# Function triggering events with time and phase offset PAYABLE WORK POSSIBLE

Hi everyones!
I’m trying to make a sort of ‘follow mode’ of a point rotating . One point follows the point rotating and an other point follows the point following the rotating point. I would like that thoses points n+1 follows point with phase and time offset.In others worls i want that a point follow point who is just next to him. Not all points follow the first point rotating.
Here a explanation https://youtu.be/WbysR8RA4Ko
Here, one possible use of my project https://youtu.be/a6RVfLpc1QA
My program is on the end of this message

The goal is that a point 2 that rotates from position 0 to 6400 “gives” its position to another point 3
He gives him his position with a time lag.
I managed to do it, but only with points 2 and 3.
Then you have to generalize to point 2 to 12, but my function shifts all the points at the same time, without waiting 200 ms for example. I would like, when point 3 passes in front of 4 by 200 points, point 4 waits 200 ms before moving forward 200 points in turn. And so on until the last point 12.

I really think you can find the answer quite easily so I am sending you my program.
I have pre-recorded different settings.
At the bottom of the screen :
K phi=0 means 0 phase shift. K phi=1 ==> 200 shift points
D ratio =75 means 75 ms of phase shift.

Realign the points up with ç
Increase phase shift with left arrow
Increase time offset with right arrow
Put point 2 at speed 2 with A
Divide the frequency by 2 with n
Multiply the frequency by 2 with N
If the function stops, it is restarted with the o key

To no longer have the pre-recordings, you must choose an empty file, which is under the empty file comment.

Tell if it is a ‘have to pay job’
Thanksss

Here the fonction

``````if (circularMov==true ){ print ("Beginning circularMov "); println (circularMov);
if (d>=0){
timeOffset=d; // timeOffset in millis (50,.. 1000 ms),  before changing phase i+1 with the phase from i
}
if (k>=0){
phiShift=k*PI/16; // here the position to add or substrat to the next point (i+1)
mapShiftCircular= map (phiShift, 0, 64*PI/16, 0, 6400);   // one revolution is 6400 step
//  mapShiftCircular is the space to reach in order to follow the previous point
}
formerEvent=millis();   // time from the beginning of the launch of the program.

print (" timeOffset "); print (timeOffset);  print (" mapShiftCircular "); print (mapShiftCircular);

for (int j = 2; j < (3); j++) {

if ( circularMov==true  && //( // circularMov==true

((CircularOldVirtualPosition[j] <= CircularOldVirtualPosition[j+1]+mapShiftCircular) && (CircularVirtualPosition[j] >= CircularVirtualPosition[j+1]+mapShiftCircular) &&
(CircularOldVirtualPosition[j] < CircularVirtualPosition[j]))// space CW

)

{  print (" CircularOldVirtualPosition i ") ;   print (j); print (" ") ; print (CircularOldVirtualPosition[j]) ;
print (" CircularVirtualPosition[i ") ;   print (j); print (" ") ; println (CircularVirtualPosition[j]) ;
print ("point "); print (j); print ("is ready to give its position to point"); print (j+1); println (" TRIGGED with PHASE OFFSET*******************") ;
print ("Before net.phase[j+1]= "); print (j+1); print (" ");  println (net.phase[j+1]);
print ("actual time is formerEvent ") ;  print (0); print (" ") ; println (formerEvent) ; //  println();
print ("before timer  ") ;  print (j); print (" ") ; println (formerEvent[j]) ; //  println();
followNumber[j]= true;
formerEvent[j]=formerEvent; // set formerEvent[j] to actual time
interphase[j]=net.phase[j];
}

if ( formerEvent>=formerEvent[j]+timeOffset  && followNumber[j]== true//&& (CircularOldVirtualPosition[j]<= CircularVirtualPosition[j])
){

print ("point "); print (j); print (" gave its position to point"); print (j+1); println (" TRIGGED with TIME AND PHASE OFFSET*******************") ;
print ("timer elapsed between timeoffset and phase offset in Clock Wise Way   ") ;
print (j); print (" ") ; println (formerEvent- formerEvent[j]) ; //  println();

net.phase[j+1]=interphase[j]-phiShift*0;//
net.phase[j+1]= net.phase[j+1]%(TWO_PI*1);//  keep phase between 0 and TWO_PI

print ("After net.phase[j+1]= ");  print (j+1); print (" ") ;println (net.phase[j+1]);
print (" followNumber after time offsett "); print (j); print (" "); println (followNumber[j]);

followNumber[j]= false;
memoryi=j;
}
// TRICK TO NO BEEN BLOCKED DUE TO THE BUG when point pass trough 0
if ( formerEvent>=formerEvent[j]+timeOffset && (CircularOldVirtualPosition[j]> CircularVirtualPosition[j]) //  && followNumber[j]== true//&& (CircularOldVirtualPosition[j]<= CircularVirtualPosition[j])
){
print (" memoryiCircular= ");  print (memoryi);   println ("***********************TIME AFTER TIME  OFFSET CW PASSING THROUG 0") ;
print ("CW After time offsett formerEvent[j] ") ;  print (j); print (" ") ; println (formerEvent[j]) ; //  println();
print ("After time offsett net.phase[j+1]= ");  print (j+1); print (" ") ;println (net.phase[j+1]);

//  net.phase[j+1]=interphase[j]-net.phase[j]-phiShift*0;//
//NO   net.phase[j+1]=interphase[j]+net.phase[j]-phiShift*0;//
net.phase[j+1]= net.phase [j]+phiShift*0;//
//    net.phase[j+1]= interphase[j]-phiShift*0;//
net.phase[j+1]= net.phase[j+1]%(TWO_PI*1);//  keep phase between 0 and TWO_PI
followNumber[j]= false;
memoryi=j;
//    formerEvent[j]=formerEvent;
}

// end 2 3
}

for (int j = 3; j < (4); j++) {

if ( circularMov==true  && //( // circularMov==true

((CircularOldVirtualPosition[j] <= CircularOldVirtualPosition[j+1]+mapShiftCircular) && (CircularVirtualPosition[j] >= CircularVirtualPosition[j+1]+mapShiftCircular) &&
(CircularOldVirtualPosition[j] <  CircularVirtualPosition[j]))// space CW

)

{  print (" CircularOldVirtualPosition ") ;   print (j); print (" ") ; print (CircularOldVirtualPosition[j]) ;
print (" CircularVirtualPosition ") ;   print (j); print (" ") ; println (CircularVirtualPosition[j]) ;
print ("point "); print (j); print ("is ready to give its position to point"); print (j+1); println (" TRIGGED with PHASE OFFSET*******************") ;
print ("Before net.phase[j+1]= "); print (j+1); print (" ");  println (net.phase[j+1]);
print ("actual time is formerEvent ") ;  print (0); print (" ") ; println (formerEvent) ; //  println();
print ("before timer  ") ;  print (j); print (" ") ; println (formerEvent[j]) ; //  println();
followNumber[j]= true;
formerEvent[j]=formerEvent; // set formerEvent[j] to actual time
interphase[j]=net.phase[j];
}

if ( formerEvent>=formerEvent[j]+timeOffset // && followNumber[j]== true//&& (CircularOldVirtualPosition[j]<= CircularVirtualPosition[j])
){

print ("point "); print (j); print (" gave its position to point"); print (j+1); println (" TRIGGED with TIME AND PHASE OFFSET*******************") ;
print ("timer elapsed between timeoffset and phase offset in Clock Wise Way   ") ;
print (j); print (" ") ; println (formerEvent- formerEvent[j]) ; //  println();

net.phase[j+1]=interphase[j]-phiShift*0;//
net.phase[j+1]= net.phase[j+1]%(TWO_PI*1);//  keep phase between 0 and TWO_PI

print ("After net.phase[j+1]= ");  print (j+1); print (" ") ;println (net.phase[j+1]);
print (" After time offsett, the phase offseet between "); print (j); print (" and  "); print (j+1); print (" is  "); println (followNumber[j]);

followNumber[j]= false;
memoryi=j;
}
// TRICK TO NO BEEN BLOCKED DUE TO THE BUG zhen point pass trough 0
if ( formerEvent>=formerEvent[j]+timeOffset && (CircularOldVirtualPosition[j]> CircularVirtualPosition[j]) //  && followNumber[j]== true//&& (CircularOldVirtualPosition[j]<= CircularVirtualPosition[j])
){
print (" memoryiCircular= ");  print (memoryi);   println ("***********************TIME AFTER TIME  OFFSET CW PASSING THROUG 0") ;
print ("CW After time offsett formerEvent[j] ") ;  print (j); print (" ") ; println (formerEvent[j]) ; //  println();
print ("After time offsett net.phase[j+1]= ");  print (j+1); print (" ") ;println (net.phase[j+1]);

//  net.phase[j+1]=interphase[j]-net.phase[j]-phiShift*0;//
//NO   net.phase[j+1]=interphase[j]+net.phase[j]-phiShift*0;//
net.phase[j+1]= net.phase [j]+phiShift*0;//
//    net.phase[j+1]= interphase[j]-phiShift*0;//
net.phase[j+1]= net.phase[j+1]%(TWO_PI*1);//  keep phase between 0 and TWO_PI
followNumber[j]= false;
memoryi=j;
//    formerEvent[j]=formerEvent;
}
// end 3 4
}
``````

https://we.tl/t-YSrAYwOZoe

Hi,
quite difficult to test, i guess it need the linked hardware to run (?)
let’s hope naive questions trigger some solution:

if i well understand, this line
`if ( formerEvent>=formerEvent[j]+timeOffset`
it’s where it trigger the behaviour you want (when recorded event time+offset is >=now )

but you apply it only for j=2
` for (int j = 2; j < (3); j++) {`

and later for j=3
for (int j = 3; j < (4); j++) {

why do this code is not applied to j from 2 to 12 ?

I test only point 3 trigged with point 2 and point 4 trigged with point three to simplify the experimentation. Tell me if you manage to experiment by yourself. You can change the speed of the rotation of the point 2 with h or y. Thanks a lot.

hi,
yes i’m able to launch it,
so far it s not enough to figure out the problem
i’m not totally totally sure i see the problem or see what you expect as a behaviour
and i ve hard time to entering the code,
for the behaviour:
points sometimes jumps (point 2 for eg), is it what expected?
and for code, i see some strange parts like:
you do
`net.phase[j+1]=interphase[j]-phiShift*0;`

but on the section bellow “// TRICK TO NO BEEN BLOCKED”
which, i think, will do the same in case the point are apart of 0° (?)
it become:
net.phase[j+1]= net.phase [j]+phiShift*0;

next line you keep net.phase[j+1] between 0 and TWO_PI
`net.phase[j+1]= net.phase[j+1]%(TWO_PI*1);`

but in other parts of the code you do:
`net.phase[i]= -PI/2;`
which imply range for net.phase is not 0-TWO_PI

its not critics, but why i ve hard time to figure how it works

Something else, i saw french comments on the code, on est peut être voisin ? cela simplifierait l’échange Super, a French guy as me, beauty and necessity will bring themself what they need.

To simplify again, I send a version of my program where only point 3 follows point 2 with phase and time offset.

Au plaisir 