Hello!
Setup: Teensy and ODrive (able to replicate issue on a test bench with just this)
We are running a control function, and at the end of the control function we save a bunch of the calculated variables (error, etc) as well as a few ODrive parameters (vbus_voltage, ibus, encoder_pos) and log them to an SD card. However, we have found in the logs that a lot of the time the ODrive parameters will switch at random throughout the run. For example, the voltage reading would stay consistently at the expected voltage, but then the reading would switch to the encoder position reading.
This is likely due to the timing of reading in values from the Serial connection. Below is the way we are currently using the ASCII protocol (same way as the Arduino library). We have considered just putting delays in-between the ODrive parameter calls, but don’t want the slowdown in the control function that it would cause.
Do you have any ideas as to ways we can ensure the data is successfully transmitted before requesting the next bit of data?
ODrive parameter requesting:
float ODrive::get_voltage()
{
OdriveSerial << "r vbus_voltage\n";
return ODrive::read_float();
}
This is the section of code that the variables get switched up in
out[RPM] = eg_rpm;
out[RPM_COUNT] = *m_eg_tooth_count;
out[DT] = dt;
out[ACT_VEL] = motor_velocity;
out[ENC_POS] = odrive.get_encoder_pos(constant.actuator_motor_number);
out[HALL_IN] = inbound_signal;
out[HALL_OUT] = outbound_signal;
out[T_START] = timestamp;
out[ODRV_VOLT] = odrive.get_voltage();
out[ODRV_CUR] = odrive.get_current();
out[ROLLING_FRAME] = gb_rolling;
out[EXP_DECAY] = gb_exp_decay;
out[REF_RPM] = ref_rpm;
out[T_STOP] = millis();
Any help would be appreciated, and thank you for your time!