The motors stop and they never reach the target position. and steppers.run() keeps returning true..
Any idea why? what could cause this sort ofproblem?
Based on the above, where do you expect it to move to? Because the destination you specify (positions) is actually the memory address of the first element of the positions array, and NOT the value of the first element of the array.
RayLivingston:
Based on the above, where do you expect it to move to? Because the destination you specify (positions) is actually the memory address of the first element of the positions array, and NOT the value of the first element of the array.
The 'steppers' object must be a MultiStepper which takes a pointer to an array of longs.
The motors stop and they never reach the target position.
I think I can explain why they are stopping one short and possibly why 'run()' is still returning 'true'.
From the way destinationTheta and destinationRho print out you can tell they are 'float' or 'double' variables. It is likely that when destinationTheta was initialized to 8000, the closest valid 'float' number was like 7999.9990, which prints as 8000.00 when rounded but stores in the integer 'positions' as 7999 when truncated. It is also likely that when destinationRho was initialized to 4800, the closest valid 'float' number was like 4799.9990, which prints as 8000.00 when rounded but stores in the integer 'positions' as 4799 when truncated.
As for run() continuing to return 'true': the 'run()' method returns 'true' if the 'distanceToGo()' (targetPosition - currentPosition) on any of the steppers return a non-zero number. It is NOT based on 'currentPosition()' alone. Apparently, according to this comment in MultiStepper.cpp, they can get out of step. Try changing '#if 0' to '#if 1' to enable the work-around.
// Caution: it has een reported that if any motor is used with acceleration outside of
// MultiStepper, this code is necessary, you get
// strange results where it moves in the wrong direction for a while then
// slams back the correct way.
#if 0
else
{
// Need to call this to clear _stepInterval, _speed and _n, otherwise future calls will fail.
_steppers[i]->setCurrentPosition(_steppers[i]->currentPosition());
}
#endif
The ‘run()’ function has to be called many times. Calling it once won’t get you to the destination. If you are moving more than one servo you have to call the ‘run()’ function for each servo until all have reached their destination. The function returns ‘true’ if it has not reached the destination so it should work if you change: