Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elevator subsystem skeleton creation #14

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
17 changes: 17 additions & 0 deletions src/main/java/competition/electrical_contract/Contract2025.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ public boolean areCanCodersReady() {
return true;
}

@Override
public boolean isElevatorReady() {
return false; //return true when ready
}

@Override
public CANMotorControllerInfo getElevatorMaster() {
return new CANMotorControllerInfo( //change CANBUS ID's later
"Master Elevator Motor", MotorControllerType.TalonFx, new CANBusId("99"), 99, new CANMotorControllerOutputConfig());
}

@Override
public CANMotorControllerInfo getElevatorFollower() {
junyu101 marked this conversation as resolved.
Show resolved Hide resolved
return new CANMotorControllerInfo( //same as above
"Follower Elevator Motor", MotorControllerType.TalonFx, new CANBusId("98"), 98, new CANMotorControllerOutputConfig());
}

protected String getDriveControllerName(SwerveInstance swerveInstance) {
return "DriveSubsystem/" + swerveInstance.label() + "/Drive";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public abstract class ElectricalContract implements XSwerveDriveElectricalContra

public abstract XYPair getSwerveModuleOffsetsInInches(SwerveInstance swerveInstance);

public abstract boolean isElevatorReady();

public abstract CANMotorControllerInfo getElevatorMaster();

public abstract CANMotorControllerInfo getElevatorFollower();
junyu101 marked this conversation as resolved.
Show resolved Hide resolved

public abstract boolean isAlgaeCollectionReady();

public abstract CANMotorControllerInfo getAlgaeCollectionMotor();
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/competition/subsystems/elevator/ElevatorSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package competition.subsystems.elevator;

import competition.electrical_contract.ElectricalContract;
import xbot.common.advantage.DataFrameRefreshable;
import xbot.common.command.BaseSetpointSubsystem;
import xbot.common.controls.actuators.XCANMotorController;
import xbot.common.properties.DoubleProperty;
import xbot.common.properties.PropertyFactory;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class ElevatorSubsystem extends BaseSetpointSubsystem<Double> implements DataFrameRefreshable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Distance rather than Double as a maintainer.


public enum ElevatorGoals{
ScoreL1,
ScoreL2,
ScoreL3,
ScoreL4,
CoralCollection,
ReturnToBase
}

final DoubleProperty elevatorPower;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ ⭐ Making the elevator go up vs down usually needs VERY different powers. And maybe we just have a gamepad control it with the joystick in the short-run?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but gamepad control should go into the HumanInput of the maintainer.

final ElectricalContract contract;

private boolean isCalibrated;

final DoubleProperty elevatorTargetHeight;
final DoubleProperty currentHeight;

//assuming we'll have a master and follower motors
public XCANMotorController masterMotor;
public XCANMotorController followerMotor;


@Inject
public ElevatorSubsystem(XCANMotorController.XCANMotorControllerFactory motorFactory, PropertyFactory pf, ElectricalContract contract){

this.elevatorPower = pf.createPersistentProperty("Elevator Power", 0.5);
this.contract = contract;

//was going to make this ephemeral but cant find it
this.elevatorTargetHeight = pf.createPersistentProperty("Elevator Target", 0.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just turn these into double and then use aKitLog.record in periodic() to save them

this.currentHeight = pf.createPersistentProperty("Current Height", 0.0);


if(contract.isElevatorReady()){
this.masterMotor = motorFactory.create(contract.getElevatorMaster(), this.getPrefix(), "Elevator Motor");
this.followerMotor = motorFactory.create(contract.getElevatorFollower(), this.getPrefix(), "Elevator Motor");
}
}

//will implement logic later
@Override
public void setPower(Double power) {
if (contract.isElevatorReady()) {
masterMotor.setPower(power);
followerMotor.setPower(power);
junyu101 marked this conversation as resolved.
Show resolved Hide resolved
}
}

public void rise(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend renaming to "raise".
Raise & Lower are a semantic pair.
Rise & Fall are a semantic pair.

setPower(elevatorPower.get());
}

public void lower(){
setPower(-elevatorPower.get());
}

public void stop(){
setPower(0.0);
}


@Override
public Double getCurrentValue() {
if (contract.isElevatorReady()){
return this.currentHeight.get();
}
return 0.0;
}

@Override
public void setTargetValue(Double targetHeight) {
this.elevatorTargetHeight.set(targetHeight);
}

@Override
public Double getTargetValue() {
return this.elevatorTargetHeight.get();
}

@Override
public boolean isCalibrated() {
return isCalibrated;
}

@Override
protected boolean areTwoTargetsEquivalent(Double target1, Double target2) {
return BaseSetpointSubsystem.areTwoDoublesEquivalent(target1, target2, 1);
}

@Override
public void refreshDataFrame() {
//to be implemented later
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do motor.refreshDataFrame() for any motor(s) you have.

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add a periodic() where you call motor.periodic()


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package competition.subsystems.elevator.commands;

import competition.subsystems.elevator.ElevatorSubsystem;
import xbot.common.command.BaseCommand;
import xbot.common.command.BaseSubsystem;
import xbot.common.properties.PropertyFactory;

import javax.inject.Inject;

public class ElevatorMaintainerCommand extends BaseCommand {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to extend BaseMaintainerCommand


public enum MaintainerMode{
Calibrating,
GaveUp,
Calibrated,
}

ElevatorSubsystem elevator;

@Inject
public ElevatorMaintainerCommand(ElevatorSubsystem elevator, PropertyFactory pf){
this.elevator = elevator;
}

@Override
public void initialize() {
log.info("initializing");
}

@Override
public void execute(){

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package competition.subsystems.elevator.commands;

import competition.subsystems.elevator.ElevatorSubsystem;
import xbot.common.command.BaseCommand;

import javax.inject.Inject;

public class LowerElevatorCommand extends BaseCommand {

ElevatorSubsystem elevator;

@Inject
public LowerElevatorCommand(ElevatorSubsystem elevator){
this.elevator = elevator;
addRequirements(elevator);
}

@Override
public void initialize() {
log.info("initializing");
}

@Override
public void execute(){
elevator.lower();
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package competition.subsystems.elevator.commands;

import competition.subsystems.elevator.ElevatorSubsystem;
import xbot.common.command.BaseCommand;

import javax.inject.Inject;

public class RiseElevatorCommand extends BaseCommand {

ElevatorSubsystem elevator;

@Inject
public RiseElevatorCommand(ElevatorSubsystem elevator){
this.elevator = elevator;
addRequirements(elevator);
}

@Override
public void initialize() {
log.info("initializing");
}

@Override
public void execute(){
elevator.rise();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package competition.subsystems.elevator.commands;

import competition.subsystems.elevator.ElevatorSubsystem;
import xbot.common.command.BaseCommand;

import javax.inject.Inject;

public class SetElevatorTargetHeightCommand extends BaseCommand {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to extend BaseSetpointCommand


Double height;
ElevatorSubsystem elevator;

@Inject
public SetElevatorTargetHeightCommand(ElevatorSubsystem elevator){
this.elevator = elevator;
addRequirements(elevator);
}

@Override
public void initialize() {
log.info("initializing");
elevator.setTargetValue(height);
}

@Override
public void execute() {
elevator.setTargetValue(height);
}

public void setHeight(double height) {
this.height = height;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package competition.subsystems.elevator.commands;

import competition.subsystems.elevator.ElevatorSubsystem;
import xbot.common.command.BaseCommand;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class StopElevatorCommand extends BaseCommand {

ElevatorSubsystem elevator;

@Inject
public StopElevatorCommand(ElevatorSubsystem elevator) {
this.elevator = elevator;
addRequirements(elevator);
}

@Override
public void initialize() {
log.info("initializing");
}

@Override
public void execute() {
elevator.stop();
}
}