Skip to content
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
62 changes: 38 additions & 24 deletions comp/simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"visible": false
}
},
"Joysticks": {
"Keyboard 0 Settings": {
"window": {
"visible": false
"visible": true
}
},
"System Joysticks": {
Expand All @@ -18,34 +18,42 @@
{
"axisConfig": [
{
"decKey": 69,
"incKey": 82
"decKey": 65,
"incKey": 81
},
{
"decKey": 83,
"incKey": 87
},
{},
{
"decKey": 68,
"decayRate": 0.0,
"incKey": 69,
"keyRate": 0.009999999776482582
},
{},
{
"decKey": 65,
"incKey": 68
"decKey": 70,
"incKey": 82
},
{
"decKey": 71,
"incKey": 84
},
{
"decKey": 87,
"incKey": 83
"decKey": 72,
"incKey": 89
}
],
"axisCount": 6,
"buttonCount": 7,
"buttonKeys": [
90,
88,
67,
86,
66,
78,
77
49,
50,
51,
52,
53,
54,
55
],
"povConfig": [
{
Expand Down Expand Up @@ -75,18 +83,17 @@
"incKey": 76
},
{
"decKey": 73,
"incKey": 75
}
],
"axisCount": 6,
"buttonCount": 5,
"buttonKeys": [
49,
50,
51,
52,
53
-1,
-1,
-1,
-1,
-1
],
"povCount": 0
},
Expand Down Expand Up @@ -121,10 +128,17 @@
],
"robotJoysticks": [
{
"guid": "Keyboard0"
"guid": "78696e70757401000000000000000000",
"useGamepad": true
},
{
"useGamepad": true
},
{},
{},
{
"guid": "Keyboard0",
"name": "keyboard"
}
]
}
102 changes: 85 additions & 17 deletions comp/src/main/java/org/team100/frc2026/Climber.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,113 @@
package org.team100.frc2026;

import org.team100.lib.config.Friction;
import org.team100.lib.config.Identity;
import org.team100.lib.config.PIDConstants;
import org.team100.lib.config.SimpleDynamics;
import org.team100.lib.controller.r1.PIDFeedback;
import org.team100.lib.logging.LoggerFactory;
import org.team100.lib.mechanism.RotaryMechanism;
import org.team100.lib.motor.BareMotor;
import org.team100.lib.motor.MotorPhase;
import org.team100.lib.motor.sim.SimulatedBareMotor;

import org.team100.lib.profile.r1.IncrementalProfile;
import org.team100.lib.profile.r1.TrapezoidIncrementalProfile;
import org.team100.lib.reference.r1.IncrementalProfileReferenceR1;
import org.team100.lib.reference.r1.ProfileReferenceR1;
import org.team100.lib.sensor.position.absolute.sim.SimulatedRotaryPositionSensor;
import org.team100.lib.sensor.position.incremental.IncrementalBareEncoder;
import org.team100.lib.sensor.position.incremental.ctre.Talon6Encoder;
import org.team100.lib.servo.OnboardAngularPositionServo;
import org.team100.lib.util.CanId;
import com.ctre.phoenix.motorcontrol.NeutralMode;
import org.team100.lib.motor.ctre.KrakenX44Motor;
import org.team100.lib.motor.ctre.KrakenX60Motor;
import org.team100.lib.motor.NeutralMode100;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

@SuppressWarnings("unused")
public class Climber extends SubsystemBase {
private final BareMotor m_motor;
// these are for the degrees that the motor moves
private final double m_level1 = 90;
private final double m_level3 = 180;
private final OnboardAngularPositionServo m_servo;
private static final double m_level0 = 0.1;
private static final double m_level1 = 90;
private static final double m_level3 = 180;

public Climber(LoggerFactory parent) {
public Climber(LoggerFactory parent, CanId CanId) {
LoggerFactory log = parent.type(this);
m_motor = new SimulatedBareMotor(log, 600);

switch (Identity.instance) {

case COMP_BOT -> {
m_motor = new KrakenX60Motor(
log,
new CanId(0),
NeutralMode100.BRAKE,
MotorPhase.FORWARD,
60, 1,
new SimpleDynamics(log, 0, 0),
new Friction(log, 0, 0, 0, 0),
new PIDConstants(log, 0, 0, 0, 0, 0, 0));
IncrementalBareEncoder encoder = m_motor.encoder();

TrapezoidIncrementalProfile profile = new TrapezoidIncrementalProfile(log, 1, 2, 0.05);
Copy link
Member Author

Choose a reason for hiding this comment

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

you can pull the common elements (e.g. the profile) out of the switch statement


ProfileReferenceR1 ref = new IncrementalProfileReferenceR1(log, () -> profile, 0.05, 0.05);
double initialPosition = 0;
double gearRatio = 2;
RotaryMechanism climberMech = new RotaryMechanism(
log, m_motor, encoder, initialPosition, gearRatio,
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
PIDFeedback feedback = new PIDFeedback(log, 5, 0, 0, false, 0.05, 0.1);
m_servo = new OnboardAngularPositionServo(log, climberMech, ref, feedback);
}

default -> {
m_motor = new SimulatedBareMotor(log, 600);
IncrementalProfile profile = new TrapezoidIncrementalProfile(log, 1, 2, 0.05);
ProfileReferenceR1 ref = new IncrementalProfileReferenceR1(log, ()-> profile, 0.05, 0.05);
PIDFeedback feedback = new PIDFeedback(log, 5, 0, 0, false, 0.05, 0.1);
IncrementalBareEncoder encoder = m_motor.encoder();

SimulatedRotaryPositionSensor sensor = new SimulatedRotaryPositionSensor(log, encoder, 1);
RotaryMechanism climberMech = new RotaryMechanism(
log,
m_motor,
sensor,
1,
Double.NEGATIVE_INFINITY,
Double.POSITIVE_INFINITY);
m_servo = new OnboardAngularPositionServo(log, climberMech, ref, feedback);
}
}
}

public Command setClimb0() {
return run(this::setL0);
return runOnce(this::setL0);
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be "run".

the difference is that "runOnce" executes the lambda once on command initialize and then never does anything else. you want this lambda (which is ultimately "set position") to run on each iteration until it's finished.

}

public Command setClimb1() {
return run(this::setL1);
return runOnce(this::setL1);
}

public Command setClimb3() {
return run(this::setL3);
public Command setClimb3() {
return runOnce(this::setL3);
}

private void setL0() {
m_motor.setUnwrappedPosition(0, 0, 0, 0);

m_servo.setPositionProfiled(m_level0, 0);
}

public void setL1() {
m_motor.setUnwrappedPosition(m_level1, 0, 0, 0);
private void setL1() {
m_servo.setPositionProfiled(m_level1, 0);
}

public void setL3() {
m_motor.setUnwrappedPosition(m_level3, 0, 0, 0);
private void setL3() {
m_servo.setPositionProfiled(m_level3, 0);
}
@Override
public void periodic() {
m_servo.periodic();
}
}
90 changes: 84 additions & 6 deletions comp/src/main/java/org/team100/frc2026/ClimberExtension.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,110 @@
package org.team100.frc2026;

import org.team100.lib.config.Friction;
import org.team100.lib.config.Identity;
import org.team100.lib.config.PIDConstants;
import org.team100.lib.config.SimpleDynamics;
import org.team100.lib.controller.r1.PIDFeedback;
import org.team100.lib.logging.LoggerFactory;
import org.team100.lib.mechanism.LinearMechanism;
import org.team100.lib.mechanism.RotaryMechanism;
import org.team100.lib.motor.BareMotor;
import org.team100.lib.motor.MotorPhase;
import org.team100.lib.motor.NeutralMode100;
import org.team100.lib.motor.ctre.KrakenX60Motor;
import org.team100.lib.motor.sim.SimulatedBareMotor;
import org.team100.lib.profile.r1.IncrementalProfile;
import org.team100.lib.profile.r1.TrapezoidIncrementalProfile;
import org.team100.lib.reference.r1.IncrementalProfileReferenceR1;
import org.team100.lib.reference.r1.ProfileReferenceR1;
import org.team100.lib.sensor.position.absolute.sim.SimulatedRotaryPositionSensor;
import org.team100.lib.sensor.position.incremental.IncrementalBareEncoder;
import org.team100.lib.servo.AngularPositionServo;
import org.team100.lib.servo.LinearPositionServo;
import org.team100.lib.servo.OnboardAngularPositionServo;
import org.team100.lib.servo.OutboardAngularPositionServo;
import org.team100.lib.servo.OutboardLinearPositionServo;
import org.team100.lib.util.CanId;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class ClimberExtension extends SubsystemBase {
private final BareMotor m_motor;
private final LinearPositionServo m_servo;

private final double m_maxExtension=20;
private final double m_maxExtension = 20;
private final double m_minextension = 0.01;

public ClimberExtension(LoggerFactory parent) {
LoggerFactory log = parent.type(this);
m_motor = new SimulatedBareMotor(log, 600);
IncrementalProfile profile = new TrapezoidIncrementalProfile(log, 1, 2, 0.05);
ProfileReferenceR1 ref = new IncrementalProfileReferenceR1(log, () -> profile, 0.05, 0.05);

switch (Identity.instance) {
case COMP_BOT -> {

KrakenX60Motor m_motor = new KrakenX60Motor(log, new CanId(0), NeutralMode100.BRAKE, MotorPhase.FORWARD,
60, 1,
new SimpleDynamics(log, 0, 0), new Friction(log, 0, 0, 0, 0),
new PIDConstants(log, 0, 0, 0, 0, 0, 0));

IncrementalBareEncoder encoder = m_motor.encoder();

double initialPosition = 0;
double gearRatio = 2;
LinearMechanism climberMech = new LinearMechanism(
log, m_motor, encoder, initialPosition, gearRatio,
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
m_servo = new OutboardLinearPositionServo(
log, // LoggerFactory parent,
climberMech,// LinearMechanism mechanism,
ref, // ProfileReferenceR1 ref,
0.01, // double positionTolerance,
0.01 // double velocityTolerance)
);
}

default -> {
SimulatedBareMotor m_motor = new SimulatedBareMotor(log, 600);
PIDFeedback feedback = new PIDFeedback(log, 5, 0, 0, false, 0.05, 0.1);
IncrementalBareEncoder encoder = m_motor.encoder();

SimulatedRotaryPositionSensor sensor = new SimulatedRotaryPositionSensor(log, encoder, 1);
Double minimumPosition = 0.1;
LinearMechanism climberMech = new LinearMechanism(
log, m_motor, encoder, 1, 2,
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);

m_servo = new OutboardLinearPositionServo(
log, // LoggerFactory parent,
climberMech, // LinearMechanism mechanism,
ref, // ProfileReferenceR1 ref,
0.01, // double positionTolerance,
0.01 // double velocityTolerance
);
}
}
}

public Command setPosition() {
return run(this::setOutPosition);
}

public Command setHomePosition() {
return run(this::setInPosition);
}

private void setOutPosition() {
m_motor.setUnwrappedPosition(m_maxExtension,0,0,0);
m_servo.setPositionProfiled(m_maxExtension, 0);

}

public void setInPosition() {
m_motor.setUnwrappedPosition(0,0,0,0);
m_servo.setPositionProfiled(m_minextension, 0.01);
}

@Override
public void periodic() {
m_servo.periodic();
}
}
11 changes: 11 additions & 0 deletions comp/src/main/java/org/team100/frc2026/auton/AutonPositions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.team100.frc2026.auton;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;

public class AutonPositions {

public static final Pose2d CLIMB_LEFT = new Pose2d(1.175, 4.25, new Rotation2d(-135 * (Math.PI / 180)));
public static final Pose2d CLIMB_RIGHT = new Pose2d(1.175, 3.1, new Rotation2d(135 * (Math.PI / 180)));

}
Loading