Skip to content

Commit

Permalink
Use references to the existing configs object
Browse files Browse the repository at this point in the history
  • Loading branch information
bhall-ctre committed Dec 8, 2023
1 parent 0383351 commit 9e9ba7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 3 additions & 6 deletions cpp/MotionMagic/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@ void Robot::RobotInit() {
configs::TalonFXConfiguration cfg{};

/* Configure current limits */
configs::MotionMagicConfigs mm{};
configs::MotionMagicConfigs &mm = cfg.MotionMagic;
mm.MotionMagicCruiseVelocity = 5; // 5 rotations per second cruise
mm.MotionMagicAcceleration = 10; // Take approximately 0.5 seconds to reach max vel
// Take approximately 0.2 seconds to reach max accel
mm.MotionMagicJerk = 50;
cfg.MotionMagic = mm;

configs::Slot0Configs slot0{};
configs::Slot0Configs &slot0 = cfg.Slot0;
slot0.kP = 60;
slot0.kI = 0;
slot0.kD = 0.1;
slot0.kV = 0.12;
slot0.kS = 0.25; // Approximately 0.25V to get the mechanism moving
cfg.Slot0 = slot0;

configs::FeedbackConfigs fdb{};
configs::FeedbackConfigs &fdb = cfg.Feedback;
fdb.SensorToMechanismRatio = 12.8;
cfg.Feedback = fdb;

ctre::phoenix::StatusCode status = ctre::phoenix::StatusCode::StatusCodeNotInitialized;
for(int i = 0; i < 5; ++i) {
Expand Down
9 changes: 3 additions & 6 deletions java/MotionMagic/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,21 @@ public void robotInit() {
TalonFXConfiguration cfg = new TalonFXConfiguration();

/* Configure current limits */
MotionMagicConfigs mm = new MotionMagicConfigs();
MotionMagicConfigs mm = cfg.MotionMagic;
mm.MotionMagicCruiseVelocity = 5; // 5 rotations per second cruise
mm.MotionMagicAcceleration = 10; // Take approximately 0.5 seconds to reach max vel
// Take approximately 0.2 seconds to reach max accel
mm.MotionMagicJerk = 50;
cfg.MotionMagic = mm;

Slot0Configs slot0 = new Slot0Configs();
Slot0Configs slot0 = cfg.Slot0;
slot0.kP = 60;
slot0.kI = 0;
slot0.kD = 0.1;
slot0.kV = 0.12;
slot0.kS = 0.25; // Approximately 0.25V to get the mechanism moving
cfg.Slot0 = slot0;

FeedbackConfigs fdb = new FeedbackConfigs();
FeedbackConfigs fdb = cfg.Feedback;
fdb.SensorToMechanismRatio = 12.8;
cfg.Feedback = fdb;

StatusCode status = StatusCode.StatusCodeNotInitialized;
for(int i = 0; i < 5; ++i) {
Expand Down

0 comments on commit 9e9ba7a

Please sign in to comment.