RobotCasserole1736 / RobotCasserole2019

Software for Robot Casserole's 2019 FIRST Deep Space competition season
MIT License
5 stars 0 forks source link

Update Arm to use SPARK MAX Beta Firmware Trapeziodal Motion Profiling #97

Closed imdunne8 closed 5 years ago

imdunne8 commented 5 years ago

SPARK MAX Beta includes methods within CANPIDController that can perform trapezoidal motion profiling directly on the controller. The beta firmware will need to be installed on the motor controller and the beta API will need to be installed in VS Code. As of right now, you may need to extract the Javadoc .jar file to see some of the documentation, however it is very incomplete for the SmartMotion methods. Note that this issue should be completed on a separate branch from #96, but should probably branch off of that issue's branch after it is completed.

First, the CANSparkMax object should be modified such that the voltage ramp rate is completely removed. The CANPIDController should then implement setSmartMotionAccelStrategy(CANPIDController.AccelStrategy.kTrapezoidal, 0), and the other SmartMotion setter methods should set appropriate values. Any calls to setReference should use kSmartMotion as control type rather than kPosition. I believe the two important new methods for our use case are setSmartMotionMaxVelocity and setSmartMotionMaxAccel. Theoretically, max velocity should be the max possible speed we can move the arm. The max acceleration will need to be set to a number that will keep the arm moving smoothly and not drawing crazy amounts of current, but which also pushes us close to the set 60A current limit. Chris has already done some work on this in the ArmPhysicalModel folder that you may want to review, but our robot differs from that somewhat. Here are some numbers you should be able to use as a baseline - keep in mind that the first two numbers don't account for acceleration/deceleration - that's what you'll need to calculate. As far as I can tell, the values you input should be in the same units as the PID controller is scaled to. Calculated loaded arm rotational speed: 160 degrees per second Calculated time to rotate arm 90 degrees: 0.56s Total time to move 90 degrees, including accel/decel (probably very conservative): 1.0s Total time to move 90 degrees, including accel/decel (realistic guess): 0.75s Total time to move 90 degrees, including accel/decel (probably very aggressive): 0.6s

Useful equations (these are the linear motion equations, but will work the same for rotational): t = (Vf - Vi) / a s = Vi t + 0.5 a * t^2

An example from REV is available here.