From 9e9ba7af027fabe1485411dca377f5ef1150224c Mon Sep 17 00:00:00 2001 From: Benjamin Hall Date: Fri, 8 Dec 2023 18:02:37 -0500 Subject: [PATCH] Use references to the existing configs object --- cpp/MotionMagic/src/main/cpp/Robot.cpp | 9 +++------ java/MotionMagic/src/main/java/frc/robot/Robot.java | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/cpp/MotionMagic/src/main/cpp/Robot.cpp b/cpp/MotionMagic/src/main/cpp/Robot.cpp index cbb7612e..c56b807a 100644 --- a/cpp/MotionMagic/src/main/cpp/Robot.cpp +++ b/cpp/MotionMagic/src/main/cpp/Robot.cpp @@ -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) { diff --git a/java/MotionMagic/src/main/java/frc/robot/Robot.java b/java/MotionMagic/src/main/java/frc/robot/Robot.java index 4c998e8d..8c142198 100644 --- a/java/MotionMagic/src/main/java/frc/robot/Robot.java +++ b/java/MotionMagic/src/main/java/frc/robot/Robot.java @@ -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) {