Enable watchdog with arduino

I can successfully control two different odrive boards with my esp32 using the arduino library, and now it’s time to make it safe. I want to enable the watchdog feature in my code to limit the capacity for chaos and bloodshed. I don’t think this feature exists yet in the arduino library, but I tried to edit ODriveArduino.cpp by adding

void ODriveArduino::EnableWatchdog(int motor_number, float watchdog_timeout, bool should_enable) {
    serial_ << "o " << motor_number << ".config.watchdog_timeout "<< watchdog_timeout << "\n";
    serial_ << "d " << motor_number << ".config.enable_watchdog "<< should_enable << "\n";
}

It’s not causing any errors, but it’s not doing anything either. I have no idea what the opening "o " and "d " might do. I just copied the formating of the other features in the file and picked new letters. I have also edited ODriveArduino.h by adding

void EnableWatchdog(int axis, float watchdog_timeout, bool should_enable);

I am trying to call the whole thing using the following in my .ino

odrive_wheels.EnableWatchdog(0,.10,true);

Any tips for making this work?

In general, once the watchdog is enabled, there are several UART commands that “feed” the watchdog, including a dedicated u command

https://docs.odriverobotics.com/v/latest/ascii-protocol.html#update-motor-watchdog

Thanks, I’m throwing new velocities at the odrive as fast as I can, so the watchdog is plenty fed. It’s enabling watchdog that I’m looking to do. I know I can save the configuration with watchdog enabled on boot, but I wanted to be able to explicitly activate the feature to be extra sure of safety.

I see now that the message I structured needs something on the firmware side to listen, so that’s why it’s not doing anything. I’m cycling onto another aspect of the project next week, but when I come back to this, if it’s still important, I’ll look at ascii_protocol.cpp and see about changing cmd_update_axis_wdg by adding something like axes[motor_number].enable_watchdog = True;

Seems harmless in the long term and would just re-activate the watchdog any time it got the u command you mentioned. Gets me the belt and suspenders safety I’m after. Assuming when I get around to this it does what I think.

Thanks for the ideas.

Oh. I figured out the issue. you’re using o and d instead of just uisng the w command.

void ODriveArduino::EnableWatchdog(int motor_number, float watchdog_timeout, bool should_enable) {
    serial_ << "w axis" << motor_number << ".config.watchdog_timeout "<< watchdog_timeout << "\n";
    serial_ << "w axis" << motor_number << ".config.enable_watchdog "<< should_enable << "\n";
}

This should work. See ASCII Protocol — ODrive Documentation 0.0 documentation

Beautiful. Works great, thanks!

1 Like