Skip to content

Commit 42a991b

Browse files
Climber code
1 parent 814d377 commit 42a991b

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

simgui.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
0.0,
7272
0.8500000238418579
7373
],
74-
"height": 338
74+
"height": 621
7575
}
7676
]
7777
}

src/main/java/org/carlmontrobotics/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public static final class Armc {
139139
public static final double AMP_ANGLE_RAD = 1.28;
140140
//-0.427725
141141
public static final double GROUND_INTAKE_POS = Units.degreesToRadians(-24.5068373);
142+
public static final double HANG_ANGL_RAD = GROUND_INTAKE_POS + Units.degreesToRadians(30);
142143

143144
public static final double SUBWOOFER_ANGLE_RAD = Units.degreesToRadians(0);//touching the base of the speaker
144145
public static final double SAFE_ZONE_ANGLE_RAD = Units.degreesToRadians(36);//touching the white line

src/main/java/org/carlmontrobotics/RobotContainer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ private void setBindingsManipulatorENDEFF() {
191191
//new WaitCommand(.5),
192192
//new MoveToPos(arm, GROUND_INTAKE_POS)
193193
//MoveToPos(arm, GROUND_INTAKE_POS));
194+
195+
new JoystickButton(manipulatorController, RAISE_CLIMBER).onTrue(new MoveToPos(arm, Armc.UPPER_ANGLE_LIMIT_RAD));
196+
new JoystickButton(manipulatorController, LOWER_CLIMBER).onTrue(new MoveToPos(arm, Armc.HANG_ANGLE_RAD));
194197

195198
//NEW BINDINGS(easier for manipulator)
196199
//Xbox left joy Y axis -> raw Intake/Outtake control

src/main/java/org/carlmontrobotics/commands/moveClimber.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
package org.carlmontrobotics.commands;
66

7-
import static org.carlmontrobotics.Constants.Armc.GROUND_INTAKE_POS;
8-
import static org.carlmontrobotics.Constants.Armc.HANG_ANGLE_RAD;
9-
import static org.carlmontrobotics.Constants.Armc.LOWER_ANGLE_LIMIT_RAD;
10-
import static org.carlmontrobotics.Constants.Armc.MAX_FF_ACCEL_RAD_P_S;
11-
import static org.carlmontrobotics.Constants.Armc.TRAP_CONSTRAINTS;
12-
import static org.carlmontrobotics.Constants.Armc.UPPER_ANGLE_LIMIT_RAD;
7+
import static edu.wpi.first.units.Units.Volt;
8+
import static org.carlmontrobotics.Constants.Armc.*;
139

1410
import org.carlmontrobotics.subsystems.Arm;
1511

1612
import com.revrobotics.CANSparkBase;
1713

14+
import edu.wpi.first.math.MathUtil;
1815
import edu.wpi.first.math.trajectory.TrapezoidProfile;
1916
import edu.wpi.first.math.util.Units;
2017
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
@@ -23,7 +20,7 @@
2320
public class moveClimber extends Command {
2421
/** Creates a new moveClimber. */
2522
private final Arm arm;
26-
private double goal;
23+
private double goal = HANG_ANGL_RAD;
2724

2825
public moveClimber(Arm arm) {
2926
// Use addRequirements() here to declare subsystem dependencies.
@@ -33,33 +30,35 @@ public moveClimber(Arm arm) {
3330
// Called when the command is initially scheduled.
3431
@Override
3532
public void initialize() {
36-
arm.callDrive = false;
37-
if (!arm.armClimbing) {
38-
goal = HANG_ANGLE_RAD;
39-
} else {
40-
goal = GROUND_INTAKE_POS;
41-
}
42-
arm.armClimbing = !arm.armClimbing;
33+
arm.callDrive = false;//turn normal arm periodic off
34+
arm.setArmTarget(goal);
4335
}
4436

4537

4638
// Called every time the scheduler runs while the command is scheduled.
4739
@Override
4840
public void execute() {
49-
arm.drivearm(Math.signum(goal - arm.getArmPos()));
41+
double err = goal - arm.getArmPos();
42+
arm.drivearm(//equivalent to a clamped P controller with KS
43+
Math.signum(err) * //direction control
44+
MathUtil.clamp(
45+
Math.abs(err)*2,//.5rad err -> 1 speed
46+
.2,
47+
.1
48+
)
49+
);
5050
}
5151

5252
// Called once the command ends or is interrupted.
5353
@Override
5454
public void end(boolean interrupted) {
55-
arm.setArmTarget(goal);
55+
arm.driveMotor(Volt.of(0));
5656
arm.callDrive = true;
5757
}
5858

5959
// Returns true when the command should end.
6060
@Override
6161
public boolean isFinished() {
62-
6362
return Math.abs(arm.getArmPos() - goal) < .1;
6463
}
6564
}

0 commit comments

Comments
 (0)