From f8c0311d85a9ec477be9b707b3c4cfb73f03f821 Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Thu, 19 Mar 2020 16:35:11 +0900 Subject: [PATCH] Fix race condition skipping reference velocity update (#85) --- tfrog-motordriver/communication.c | 6 ++++-- tfrog-motordriver/controlVelocity.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tfrog-motordriver/communication.c b/tfrog-motordriver/communication.c index d40a7ce..ca87e88 100644 --- a/tfrog-motordriver/communication.c +++ b/tfrog-motordriver/communication.c @@ -1524,10 +1524,12 @@ int command_analyze(unsigned char* data, int len) case PARAM_w_ref: i.integer *= 16; case PARAM_w_ref_highprec: - if (motor[imotor].ref.vel != i.integer) - motor[imotor].ref.vel_changed = 1; + { + const char changed = (motor[imotor].ref.vel != i.integer); motor[imotor].ref.vel = i.integer; + motor[imotor].ref.vel_changed = changed; break; + } case PARAM_p_toq_offset: motor[imotor].ref.torque_offset = i.integer; break; diff --git a/tfrog-motordriver/controlVelocity.c b/tfrog-motordriver/controlVelocity.c index 993e98a..bd0a9ca 100644 --- a/tfrog-motordriver/controlVelocity.c +++ b/tfrog-motordriver/controlVelocity.c @@ -109,7 +109,7 @@ void ISR_VelocityControl() motor[i].ref.vel_diff = 0; } - motor[i].error = motor[i].ref.vel_buf - motor[i].vel; + motor[i].error = motor[i].ref.vel - motor[i].vel; motor[i].error_integ += motor[i].error; if (motor[i].error_integ > motor_param[i].integ_max) {