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

Climber default coast #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions config/Subsystems.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,26 @@ lift:
homingPower: -0.2
pivot:
pivotMotor: { type: VICTOR_SPX, config: { id: 5, inverted: false } }
pivotEncoder: {
channel: 0, fullRange: 360.0, minValue: -180, continuous: true,
averageBits: 4, oversampleBits: 4,
offset: 104
}
pivotEncoder: { aChannel: 6, bChannel: 7, reverse: false,
distancePerPulse: 0.087890625 } # 360 degrees / 4096 CPR
pivotLockSolenoid: { channel: 1 }
pivotLockSensor: { channel: 16, type: PNP }

pivotController:
# kpP: 0.04 # 0.04
# kiP: 0.0 # 0.04
# kpV: 0.001
# kfV: 0.002
# kMinOutput: 0.0537
# kfA: 0.0005
# kHoldPower: 0.0
# minPosition: -90.0
# maxPosition: 90.0
# maxOutput: 0.4
# minOutput: -0.4
# maxAcceleration: 180.0
# travelVelocity: 90.0
# endVelocity: 0.0
target: { within: 3.0 }
minSetpoint: -90.0
maxSetpoint: 90.0
maxAcceleration: 1.2
movePower: 0.4
endRamp: 20.0
kpP: 0.04 # 0.04
kiP: 0.0 # 0.04
kpV: 0.001
kfV: 0.002
kMinOutput: 0.0537
kfA: 0.0005
kHoldPower: 0.0
minPosition: -90.0
maxPosition: 90.0
maxOutput: 0.4
minOutput: -0.4
maxAcceleration: 180.0
travelVelocity: 90.0
endVelocity: 0.0
# logData: true
pivotHoldPower: 0.15
anglePresets:
Expand Down
58 changes: 39 additions & 19 deletions rio/src/main/java/org/teamtators/levitator/subsystems/Climber.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.teamtators.levitator.subsystems;

import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.BaseMotorController;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.Solenoid;
Expand Down Expand Up @@ -28,9 +30,9 @@

public class Climber extends Subsystem implements Configurable<Climber.Config> {
private final TatorRobot robot;
private SpeedControllerGroup climberMotor;
private SpeedControllerGroup climberMotors;
private WPI_TalonSRX masterMotor;
// private MotorPowerUpdater climberMotorUpdater;
// private MotorPowerUpdater climberMotorUpdater;
private DigitalSensor topLimit;
private DigitalSensor bottomLimit;
private Solenoid releaser;
Expand All @@ -42,14 +44,14 @@ public Climber(TatorRobot robot) {
this.robot = robot;
}

public void setHomed(boolean homed) {
this.homed = homed;
}

public boolean isHomed() {
return homed;
}

public void setHomed(boolean homed) {
this.homed = homed;
}

public void setPower(double power, boolean force) {
double pow = power;
if (!force) {
Expand All @@ -62,7 +64,15 @@ public void setPower(double power, boolean force) {
pow = 0;
}
}
climberMotor.set(pow);
climberMotors.set(pow);
}

public void setNeutralMode(NeutralMode neutralMode) {
for (SpeedController climberMotor : climberMotors.getSpeedControllers()) {
if (climberMotor instanceof BaseMotorController) {
((BaseMotorController) climberMotor).setNeutralMode(neutralMode);
}
}
}

public double getPosition() {
Expand Down Expand Up @@ -101,22 +111,32 @@ public void onEnterRobotState(RobotState state) {
robot.getScheduler().startCommand(homeCommand);
}
}
switch (state) {
case DISABLED:
setNeutralMode(NeutralMode.Coast);
break;
default:
setNeutralMode(NeutralMode.Brake);
break;
}
}

@Override
public void configure(Config config) {
this.config = config;
climberMotor = config.climberMotor.create();
masterMotor = (WPI_TalonSRX) climberMotor.getSpeedControllers()[0];
climberMotors = config.climberMotor.create();
masterMotor = (WPI_TalonSRX) climberMotors.getSpeedControllers()[0];
topLimit = config.topLimit.create();
bottomLimit = config.bottomLimit.create();
releaser = config.releaser.create();
// climberMotorUpdater = new MotorPowerUpdater(climberMotor);
// climberMotorUpdater = new MotorPowerUpdater(climberMotors);

setNeutralMode(NeutralMode.Coast);

climberMotor.setName("Climber", "climberMotor");
for (int i = 0; i < climberMotor.getSpeedControllers().length; i++) {
SpeedController speedController = climberMotor.getSpeedControllers()[i];
((Sendable) speedController).setName("Climber", ("climberMotor(" + i + ")"));
climberMotors.setName("Climber", "climberMotors");
for (int i = 0; i < climberMotors.getSpeedControllers().length; i++) {
SpeedController speedController = climberMotors.getSpeedControllers()[i];
((Sendable) speedController).setName("Climber", ("climberMotors(" + i + ")"));
}
topLimit.setName("Climber", "topLimit");
bottomLimit.setName("Climber", "bottomLimit");
Expand All @@ -127,7 +147,7 @@ public void configure(Config config) {

@Override
public void deconfigure() {
SpeedControllerConfig.free(climberMotor);
SpeedControllerConfig.free(climberMotors);
topLimit.free();
bottomLimit.free();
releaser.free();
Expand All @@ -137,10 +157,10 @@ public void deconfigure() {
public ManualTestGroup createManualTests() {
ManualTestGroup group = super.createManualTests();
group.addTest(new ClimberEncoderTest());
group.addTest(new SpeedControllerTest("climberMotor", climberMotor));
for (int i = 0; i < climberMotor.getSpeedControllers().length; i++) {
SpeedController speedController = climberMotor.getSpeedControllers()[i];
group.addTest(new SpeedControllerTest("climberMotor(" + i + ")", speedController));
group.addTest(new SpeedControllerTest("climberMotors", climberMotors));
for (int i = 0; i < climberMotors.getSpeedControllers().length; i++) {
SpeedController speedController = climberMotors.getSpeedControllers()[i];
group.addTest(new SpeedControllerTest("climberMotors(" + i + ")", speedController));
}
group.addTest(new DigitalSensorTest("topLimit", topLimit));
group.addTest(new DigitalSensorTest("bottomLimit", bottomLimit));
Expand Down
13 changes: 13 additions & 0 deletions rio/src/main/java/org/teamtators/levitator/subsystems/Drive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.teamtators.levitator.subsystems;

import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.BaseMotorController;
import edu.wpi.first.wpilibj.*;
import org.teamtators.common.config.Configurable;
import org.teamtators.common.config.helpers.EncoderConfig;
Expand Down Expand Up @@ -204,6 +206,16 @@ public void setLeftPower(double power) {
leftMotor.set(power);
}

public void setNeutralMode(NeutralMode neutralMode) {
for (SpeedControllerGroup group : Arrays.asList(leftMotor, rightMotor)) {
for (SpeedController motor : group.getSpeedControllers()) {
if (motor instanceof BaseMotorController) {
((BaseMotorController) motor).setNeutralMode(neutralMode);
}
}
}
}

public double getLeftRate() {
return leftEncoder.getRate();
}
Expand Down Expand Up @@ -353,6 +365,7 @@ public void configure(Config config) {
rightEncoder.setName("Drive", "rightEncoder");
gyro.setName("Drive", "gyro");

setNeutralMode(NeutralMode.Coast);
poseEstimator.start();
}

Expand Down
16 changes: 15 additions & 1 deletion rio/src/main/java/org/teamtators/levitator/subsystems/Lift.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.teamtators.levitator.subsystems;

import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.BaseMotorController;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.teamtators.common.config.Configurable;
import org.teamtators.common.config.helpers.*;
Expand All @@ -20,6 +23,7 @@
import java.util.Map;

public class Lift extends Subsystem implements Configurable<Lift.Config> {
private static final boolean ENABLE_HOMING = false;
private Pivot pivot;

private SpeedControllerGroup liftMotor;
Expand Down Expand Up @@ -69,6 +73,14 @@ public void linkTo(Pivot pivot) {
this.setPivot(pivot);
}

public void setNeutralMode(NeutralMode neutralMode) {
for (SpeedController liftMotor : liftMotor.getSpeedControllers()) {
if (liftMotor instanceof BaseMotorController) {
((BaseMotorController) liftMotor).setNeutralMode(neutralMode);
}
}
}

/**
* @return height in inches
*/
Expand Down Expand Up @@ -347,6 +359,7 @@ public void configure(Config config) {

homed = false;
homeTimer.stop();
setNeutralMode(NeutralMode.Coast);
}

@Override
Expand Down Expand Up @@ -409,10 +422,11 @@ private void updateHeight() {
return;
}
setLiftPower(config.homingPower);
if (!isAtBottomLimit() && false && !homeTimeout) {
if (!isAtBottomLimit() && ENABLE_HOMING && !homeTimeout) {
return;
}
logger.info("Lift homed");
setNeutralMode(NeutralMode.Brake);
liftEncoder.reset();
enableLiftController();
homed = true;
Expand Down
Loading