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

Add simple simulation of arm going to goal position. #49

Merged
merged 4 commits into from
Apr 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dependencies {
simulationRelease wpi.sim.enableRelease()

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
implementation "com.github.deepbluerobotics:lib199:0e5932a4219f3439ef2be3981a9189baf777f61e"
implementation "com.github.deepbluerobotics:lib199:0ce129844b9b918dad0207c0e1020fc26588f461"
}

test {
Expand Down
7 changes: 4 additions & 3 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
"incKey": 75
}
],
"axisCount": 2,
"axisCount": 5,
"buttonCount": 4,
"buttonKeys": [
77,
44,
46,
47
],
"povCount": 0
"povCount": 1
},
{
"axisConfig": [
Expand Down Expand Up @@ -97,7 +97,8 @@
"useGamepad": true
},
{
"guid": "Keyboard1"
"guid": "Keyboard1",
"name": "Manipulator"
}
]
}
8 changes: 8 additions & 0 deletions simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
}
},
"Other Devices": {
"AbsoluteEncoder[13]": {
"header": {
"open": true
}
},
"CANCoder (v6)[2]": {
"header": {
"open": true
Expand Down Expand Up @@ -63,6 +68,9 @@
"NetworkTables": {
"transitory": {
"SmartDashboard": {
"Arm": {
"open": true
},
"BL": {
"open": true
},
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/carlmontrobotics/subsystems/Arm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.revrobotics.SparkAbsoluteEncoder;
import com.revrobotics.SparkPIDController;

import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.controller.ArmFeedforward;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
Expand All @@ -30,9 +31,11 @@
import edu.wpi.first.units.Voltage;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import edu.wpi.first.wpilibj.simulation.SimDeviceSim;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.sysid.SysIdRoutineLog;
import edu.wpi.first.wpilibj2.command.Command;
Expand Down Expand Up @@ -76,6 +79,9 @@ public class Arm extends SubsystemBase {

private ShuffleboardTab sysIdTab = Shuffleboard.getTab("arm SysID");
private boolean setPIDOff;

private SimDouble rotationsSim;

public Arm() {
// weird math stuff
armMotorMaster.setInverted(MOTOR_INVERTED_MASTER);
Expand Down Expand Up @@ -145,6 +151,9 @@ public Arm() {
armMotorFollower.setSmartCurrentLimit(80);

SmartDashboard.putBoolean("arm is at pos", false);
if (RobotBase.isSimulation()) {
rotationsSim = new SimDeviceSim("AbsoluteEncoder", ARM_MOTOR_PORT_MASTER).getDouble("rotations");
}
}

public void setBooleanDrive(boolean climb) {
Expand Down Expand Up @@ -430,4 +439,10 @@ public void setDefaultCommand(TeleopArm teleopArm, Object object) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setDefaultCommand'");
}

@Override
public void simulationPeriodic() {
// Fake goaling to the goal instantaneously
rotationsSim.set((goalState.position + armMasterEncoder.getZeroOffset()) / armMasterEncoder.getPositionConversionFactor());
}
}
Loading