Closed gabryelreyes closed 3 months ago
Issue has been tracked to
DifferentialDrive::calculateLinearSpeedLeftRight
where the result ofangularSpeed32 * wheelBase32
exceeds the maximum value ofint16_t
and wraps over to its negative domain.
Can't be, because calculated with int32_t and divided by 2. Result will be lower than 65535. https://github.com/BlueAndi/RadonUlzer/blob/d7d53e5b116f64c77faa25195fecd9158b95f7ea/lib/Service/src/DifferentialDrive.cpp#L258-L259
True, in the case of 1500 mrad/s, the result is 63750. Nonetheless the direction of the turning is wrong
I do not quite understand how we come from mrad/s
to steps/s
in the mentioned formula, as the wheelbase is in mm
https://github.com/BlueAndi/RadonUlzer/blob/d7d53e5b116f64c77faa25195fecd9158b95f7ea/lib/Service/src/DifferentialDrive.cpp#L258-L259
Yes, looks not that good. Would calculate it like this ... please check.
$v [\frac{mm}{s}] = \frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2}$
$v_L [\frac{mm}{s}] = -\frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2}$
$v_R [\frac{mm}{s}] = \frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2}$
$v [\frac{steps}{s}] = \frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$v_L [\frac{steps}{s}] = -\frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$v_R [\frac{steps}{s}] = \frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$vL [\frac{steps}{s}] = \frac{v{Linear}}{2} [\frac{steps}{s}] -\frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$vR [\frac{steps}{s}] = \frac{v{Linear}}{2} [\frac{steps}{s}] + \frac{w_r [\frac{rad}{s}] \cdot W [mm]}{2} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$vL [\frac{steps}{s}] = \frac{v{Linear}}{2} [\frac{steps}{s}] -\frac{w_r [\frac{mrad}{s}] \cdot W [mm]}{2 \cdot 1000} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$vR [\frac{steps}{s}] = \frac{v{Linear}}{2} [\frac{steps}{s}] + \frac{w_r [\frac{mrad}{s}] \cdot W [mm]}{2 \cdot 1000} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
Can't be, because calculated with int32_t and divided by 2. Result will be lower than 65535.
The results are assigned to linearSpeedLeft
and linearSpeedRight
, which both are int16_t.
Can't be, because calculated with int32_t and divided by 2. Result will be lower than 65535.
The results are assigned to
linearSpeedLeft
andlinearSpeedRight
, which both are int16_t.
And in range with provided values.
I believe the first equation is wrong when dividing the wheelbase by 2. This Source proposes an equation for $w$ in Eq. 3, from which we can derive the following:
$v [\frac{mm}{s}] = w_r [\frac{rad}{s}] \cdot W [mm]$
Carrying this change over all equations presented earlier, the final equations for linear speeds are as follows:
$vL [\frac{steps}{s}] = \frac{v{Linear}}{2} [\frac{steps}{s}] -\frac{w_r [\frac{mrad}{s}] \cdot W [mm]}{1000} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
$vR [\frac{steps}{s}] = \frac{v{Linear}}{2} [\frac{steps}{s}] + \frac{w_r [\frac{mrad}{s}] \cdot W [mm]}{1000} \cdot \frac{ENC [\frac{steps}{m}]}{1000}$
I have tested both variants and the solution I am proposing seems to achieve the goal and turning in the correct direction and the correct distance.
Regarding the size of int16 and the maximal result of the equation, an angular speed of $48186 [\frac{mrad}{s}]$ would be required to reach the maximum value for int16. We are quite far away from this value.
But your linked documentation shows a division by 2. :-? And if I calculate with real values, the divison by 2 is required to get the right result. Did you test it only empirical or by calculation?
Using the following call:
This results in a counter-clockwise rotation of aroung 270° while the expected behavior is the rotation of the Zumo clockwise around 90° in one second.
Issue has been tracked to
DifferentialDrive::calculateLinearSpeedLeftRight
where the result ofangularSpeed32 * wheelBase32
exceeds the maximum value ofint16_t
and wraps over to its negative domain.