Trossen Robotics Community > Robotics > Software and Programming > How to deal with unexpected stops.
View Full Version : How to deal with unexpected stops.
Here is the situation I am running into.
I got a PI velocity loop that works pretty well.
But occasionally due to a sensor glitch or something, it stops. Especially when going slow.
This way, if there is no new data, it will simply send the old data.
The problem arises when it decides it is going way to fast and tells the motor to stop, and it does. At this point it gets no new sensor data so it doesn't know to start going again and it keeps on sending the old data that told it to stop.
That's basically what a watchdog timer does, however it resets the entire controller.
A counter is incremented independently of the program flow, and when it overflows, the controller is reset.
I think the more common logic would be to use 2 interrupts. One interrupt is triggered by the encoder's A channel going high, and increments a counter variable. A second interrupt would be triggered by a timer, maybe at something like 60hz, everytime this interrupt triggers it would compare the counter variable (actual speed) against the setpoint (desired speed) and adjust the PWM values as necessary.
}You could of course have more complex code in the clock interrupt, in your case, it would be a PI controller.
This has the added bonus, that both of these are interrupt routines, so you haven't really created the main body of your program -- its all background stuff.