To further understand, you want the value that you set as the target to be absolute as opposed to relative to the current position, i.e,. -2000 would result in rotating counter clockwise 5000 degrees if the current motor position is 3000.
yes, that's correct.
Code: Select all
SetMotorRotationTarget(OUT_A, -1000); // define absolute target value
RotateToTarget(OUT_A, 100); // start rotation task; self-terminating when the absolute target has been reached
You may need to somehow tell your program that you are switching into an adjustment phase which it should ignore, and then switching out of the adjustment phase so that it should stop ignoring motor rotations.
The RotateToTarget task (or: function processed inside a task) has to run autonomously self-controlled until the target has been reached; during that time the MotorRunstate is "BUSY". Manual corrections are not intended in this phase, but if they happen accidentally, then the motor control task should re-correct them.
Intermediate premature termination by other tasks must be possible (regardless of any mutexes).
If once the absolute target has been reached, the control task is self-terminating and switches off the motor (MotorRunstate switched to "IDLE"), now this is finished. You can see if the task is finished by
Code: Select all
if (MotorRunstate(OUT_A)==IDLE) {...} // if it's true then the absolute target has been reached and the task is finished!
I now might do anything or nothing, e.g. now make some intermediate corrections. During manual correction the manual rotation of course is monitored by a change of the MotorRotationCount value. The program knows what the current position is anyway (either if changed or not) and will have to approach the next target regardless if any adjustment has been made or not, e.g.:
If the current position is 1000 and the next target will be 1500 then the next function call will move 500 clockwise.
If the current position is 1000, and I should move it manually to 900, and also the next target will be 1500, then the next function call will have to move 600 clockwise.
The zero point which is initialized at program start (ResetRotationCount) will not be affected
- unless I will make an additional re-initialization intermediately (e.g. if someone severely hit or twisted an arm or the turn table accidentally).