Closed NiHoffmann closed 7 months ago
I think the issue is in getTimeToWait function, if I understand it correctly, for differential drive we'd need to compute how long it would take the center of the axis to move a given distance, so instead of computing absoluteDistance we should use distance instead.
Then for -0.9 and 1 RPM for distance of 1 m we'd get 5876.49 seconds instead of 9.5. Another thing, when resulting speed is 0 then (theoretically) an infinity should be returned, not 0. Technically it makes sense to throw an exception (e.g. invalid robot speed) also in case when RPM left is the negative of RPM right, an exception should be thrown (e.g.infinite run time requested) because in this case the robot will spin in place forever.
I think it is sin that causes this:
rpm L/R, distance: -0.9 1 100
time to wait: 9.560226873429032
rpm L/R, distance: -0.9 1 1000
time to wait: 10.153591611176166
rpm L/R, distance: -0.9 1 10000
time to wait: 3.6503858402500824
rpm L/R, distance: -0.9 1 100000
time to wait: 15.636709165184454
rpm L/R, distance: -0.9 1 1000000
time to wait: 17.21935670254879
rpm L/R, distance: -0.9 1 10000000
time to wait: 10.256383147792251
rpm L/R, distance: -0.9 1 100000000
time to wait: 2.41391530172498
rpm L/R, distance: -0.9 1 1000000000
time to wait: 17.396190869979414
rpm L/R, distance: -0.9 1 10000000000
time to wait oscillates, instead of steadily growing
when using distance instead of absoluteDistance:
rpm L/R, distance: -0.9 1 100
time to wait: 5876.490206469974
rpm L/R, distance: -0.9 1 1000
time to wait: 58764.90206469974
rpm L/R, distance: -0.9 1 10000
time to wait: 587649.0206469974
rpm L/R, distance: -0.9 1 100000
time to wait: 5876490.206469974
rpm L/R, distance: -0.9 1 1000000
time to wait: 58764902.06469974
rpm L/R, distance: -0.9 1 10000000
time to wait: 587649020.6469973
rpm L/R, distance: -0.9 1 100000000
time to wait: 5876490206.469974
rpm L/R, distance: -0.9 1 1000000000
time to wait: 58764902064.69974
rpm L/R, distance: -0.9 1 10000000000
time to wait: 587649020646.9973
TL/DR: distance needs to be used instead od absoluteDistance, inf should be returned for the case of the robot spinning in place, or an exception needs to be raised
Fixed: Tested with different speed values.
mbot2 does not drive correct distance for the following cases:
for both of these examples drive time will be below one second, note that for 2000cm the robot drive longer than for 3000cm and about the same time for 200cm and 3000cm
Cases that work: note that if both motor speed are defined in the same direction the robot appears to be driving the correct distance e.g.
if booth speeds or distance is set to 0 or both rpms cancle out (spinning in place) the robot wont move which is expected behaviour
when driving a curve and not just straight forward the robot appears to be driving the correct distance but this might have to be checked thoroughly again.