Is there a software approach to toggle brake/coast mode with Victor SP Motor Controller. We are trying to add braking for autonomous but keep coast mode for teleop in the disabled stage. Is this possible for this motor type? If so, is there a way to do so in Java?
As the Victor SP is a PWM controller, it is not possible to do this programmatically (the only communication between the controller and the roboRIO is the signal corresponding to the desired output voltage). Consider using the Talon SRX, instead.
Well… you COULD use a servo to press the brake/coast button, but don’t actually do that. +1 for using the SRXs, they’re great.
For years, teams would remove the jumper from the brake/coast selector pins and connect a PWM wire from there to a DIO port. In 2016, the GDC ruled that to be an illegal modification of the motor controller because of a rare case that could lead to fires. I don’t remember if they cleared that up in the 2017 rules or if anyone raised the question in Q&A. Either way, it will likely still be illegal in 2018. See discussion here.
For now, the only legal way to have programmatic control of brake/coast is by using a Talon SRX* and setting it via CAN.
*I don’t remember if CAN Jaguars could control brake/coast programmatically, but it’s really not worth going through all the trouble for a worse motor controller. Even if you had Jaguars in stock, in the time it would take you to figure out how to properly set up Jaguars with CAN you could fundraise the money to buy your team a new set of Talon SRXs.
I agree it is academic, but yes, they could.
As stated above, you can’t switch between break and coast in software, but if you have the jumper set to coast you could program a quick reversal of direction to help decrease your momentum.
void stopMotion(VictorSP motor){
for(int i=0; i<3; i++){
motor.setSpeed(-0.2);
}
}
Something like that should work, although it’s not going to be very consistent as is. I’ll leave writing better code as an exercise to the reader. Also, keep in mind that this will not extend the life of gears.
With a PWM motor controller like a Spark/Talon SR/Jaguar this would not be possible since the brake/coast mode is set with a button on each controller that must be manually switched.
With a CAN motor controller like a Talon SRX it would be a simple toggle in code to switch between brake and coast that could be switched when you initialize teleop or with a button on the controllers.