I recently built a robot with a raspberry pi 3B which is quite large (two meters long and 60 kilograms) and walks on six legs. It is language controlled by pocketsphinx and streaming live high resolution video, which means cpu is always at about 35%. Everything was working great until today. Without any specific reason, suddenly the raspberry pi crashed and shut down, but while motors where running. The motors have pushbuttons which are pressed when the legs reach the maximum amplitude, and they stop the motors. Unfortunately, at the time of the crash three motors where still running, and the pi didn't shut them down and didn't detect it when the pushbuttons where pressed. So the motors just run further happily also when they reached the maximum amplitude until I pulled the power supply one second later. The result: Several mechanical parts where bend and one motor relay doesn't work any more (before I changed it.) My question: what are good methods to prevent something like this? I have thought about using a microcontroller which gets a signal from the pi every 0.05 seconds and disconnects power with a large relay from all peripherals in case of certain circumstances which predict a failure (signal from pi does not come or accumulator voltage is not ok). Everything that happened now is reparable, but if this happens with a larger, maybe industrial machine it might cause great trouble. I have had these failures a few times, but the other times it happened when my speakers where running, so I lost contol of them, which is annoying, but not fatal. I also will transfer speecn recognition to a remote server as sooon as possible. But the RPi should really be capable of this.
Thanks in advance.