n Processing, I made a simulation where I run an engine over several revolutions at a certain speed and in both directions.
I can track the position of the simulated motor using a stepper motor.
By giving the position information of the simulated motor (on a scale from 0 to 4095) to the stepper motor (which therefore makes a revolution in 4096 steps), the stepper motor follows the simulated movement very well. 8); D.
Everything is fine when the simulated engine does not exceed 1 revolution in one direction or the other.
But, when the simulated motor exceeds a revolution, when it starts a first revolution, Processing always sends positions between 0 and 4095.
Processing therefore sends at the start of the first lap, position 0 to my stepper motor on Arduino and therefore (instead of continuing forward) it goes back to go to position 0.
So to solve this problem, when the information of the simulated engine goes from 4095 to directly 0 or 1 or 23, Processing would have to send a virtual position equal to position 4096 + 0, 4096 + 1 or 4096 + 23.
Similarly, if at the start the simulated motor turns in the other direction, Processing sends the positions 0, 4096, 4085 for example and the stepper motor goes forward (from 0 to 4096) then back (from 4096 to 4085 ).
When I should send virtual positions 0, -1, -11.
Likewise if the second back turn is the same as the first, instead of Processing sending 0, 4096, 4085, Processing should send virtual positions
0- 4096, -1- 4096, -11 - 4097. So, -4096, -4097, -5008.
Hoping to have been clear, I thank you with my greatest gratitude.
here what I tried but I don’t have all the data of position. It can to go straight to 4090 to 10 for exemple
float pos0 = map ((net.phase[0]), 0, TWO_PI, 0, 4095);
int positionMax=4095;
int Pos0= int (pos0);
print ("Pos0 "); println (Pos0);
// if motor goes forword
if (( Pos0 - positionMax > -1) || ( positionMax- Pos0 < 1)) {
int VirtualPosition = Pos0+positionMax+0;
}
String pos = (10.0)+"*"+(10.0) +"*"+(10.0)+"*"+(10.0)+"*"+(VirtualPosition) +"*";
println (pos);
arduinoport.write(pos);