Instead of imperatively configuring parameters of the SPARK by calling methods directly on it and its auxiliary objects (sensors, closed loop controller, etc.), configuration parameters are set in a more declarative way through configuration objects and applying that configuration to the SPARK.
A more complete guide on the new configuration system will soon be available.
For simplicity, only an example for SPARK MAX is provided. The following will still be valid for a SPARK Flex object.
Before
CANSparkMax max =newCANSparkMax(1,MotorType.kBrushless);RelativeEncoder enc =max.getEncoder();SparkPIDController pid =max.getPIDController();max.restoreFactoryDefaults();max.setInverted(true);max.setIdleMode(IdleMode.kBrake);enc.setPositionConversionFactor(1000);enc.setVelocityConversionFactor(1000);pid.setFeedbackDevice(enc);pid.setP(1.0);pid.setI(0.0);pid.setD(0.0);max.burnFlash();
After
SparkMax max =newSparkMax(1,MotorType.kBrushless);SparkMaxConfig config =newSparkMaxConfig();config.inverted(true).idleMode(IdleMode.kBrake);config.encoder.positionConversionFactor(1000).velocityConversionFactor(1000);config.closedLoop.feedbackSensor(FeedbackSensor.kPrimaryEncoder).pid(1.0,0.0,0.0);max.configure(config,ResetMode.kResetSafeParameters,PersistMode.kPersistParameters);
Previously, setting status periods required the user to know which periodic status frame a signal belonged to. Now, status signals' periods can be individually configured, and REVLib will handle figuring out which status frame to adjust.
These values can be configured through the new configuration system.
For simplicity, only an example for SPARK MAX is provided. The following will still be valid for a SPARK Flex object.
Before
CANSparkMax max =newCANSparkMax(1,MotorType.kBrushless);max.restoreFactoryDefaults();// Adjust periodic status frame 2, which includes encoder position datamax.setPeriodicFramePeriod(PeriodicFrame.kStatus2,5);max.burnFlash();double position =max.getEncoder().getPosition();
After
SparkMax max =newSparkMax(1,MotorType.kBrushless);SparkMaxConfig config =newSparkMaxConfig();config.signals.primaryEncoderPositionPeriodMs(5);max.configure(config,ResetMode.kResetSafeParameters,PersistMode.kPersistParameters);double position =max.getEncoder().getPosition();
Before
usingnamespace rev;CANSparkMax m_max{1,MotorType.kBrushless};m_max.RestoreFactoryDefaults();// Adjust periodic status frame 2, which includes encoder position datam_max.SetPeriodicFramePeriod(CANSparkMax::PeriodicFrame::kStatus2,5);m_max.BurnFlash();double position =m_max.GetEncoder().GetPosition();
After
usingnamespace rev::spark;SparkMax m_max{1, SparkMax::MotorType::kBrushless};SparkMaxConfig config{};config.signals.PrimaryEncoderPositionPeriodMs(5);m_max.Configure(config, SparkMax::ResetMode::kResetSafeParameters, SparkMax::PersistMode::kPersistParameters);double position =m_max.GetEncoder().GetPosition();