Serial ascii protocol problem

Hello all.
I have some problems with serial ascii comunication.
What I do is set axis[0] speed, set axis[1] speed, get axis[0] encoder shadow_count and axis[1] shadow_count.
When my robot is driving sudeenly the serial connection is not responding anymore but the motor are still running.
I need to reboot odrive to get it running again. So I’m building some safety in my robot to cut off power to odrive when communication drops. Maybe I’m stressing the oderive to much. Because of this issue I was running behind my robot to stop it :slight_smile:

To prevent too much serial communication to odrive I changed the protocol a bit.
Looking at the code I see some threads are being made. But I did not see any mutexes being used.
For example set_vel_setpoint. So I presume I can acces the encoder_.shadow_count_ without any problems in below code?

} else if (cmd[0] == 'V') { // velocity control extended
        float vel_0_setpoint, vel_1_setpoint;
        int numscan = sscanf(cmd, "V %f %f", &vel_0_setpoint, &vel_1_setpoint);
        if (numscan < 2) {
            respond(response_channel, use_checksum, "invalid command format");
        } else {
            axes[0]->controller_.set_vel_setpoint(vel_0_setpoint, 0);
            axes[1]->controller_.set_vel_setpoint(vel_1_setpoint, 0);
            respond(response_channel, use_checksum, "%d %d", axes[0]->encoder_.shadow_count_,axes[1]->encoder_.shadow_count_);

Also I’m thinking of implementing a heartbeat feature. If odrive does not get a ping every X ms the odrive will shut down the motor.

Yep I think that should work fine. You can execute the timeout in this thread. If you look towards the bottom of the loop you see osDelay(1), aka this loop has a period of 1ms. You can add a loop counter to keep time for you.