Closed cqliliping closed 6 years ago
hi. below is my algorithm. first i find which motor has the most steps and that is called high step, then I divide each of the other motor steps into high step to figure out which loops of the while statement to pulse the motor on. the motor with highest step pulses the motor every loop - the other motors will only pulse on certain loops based on the divide. it will not divide evenly there is always left over so I take the remainder and then run a calculation to spread these leftovers evenly across the span of high step and then I skip these loops, and then I do it again to catch any more leftovers and create a 3rd level of skips. its confusing but you will have to study the code below. PE stands for Pulse Every (loop) and SE stands for Skip Every (loop). I will try to add more comments next time i make a rev change. thank you.
//FIND HIGHEST STEP
int HighStep = J1step;
if (J2step > HighStep)
{
HighStep = J2step;
}
if (J3step > HighStep)
{
HighStep = J3step;
}
if (J4step > HighStep)
{
HighStep = J4step;
}
if (J5step > HighStep)
{
HighStep = J5step;
}
if (J6step > HighStep)
{
HighStep = J6step;
}
int J1_PE = 0;
int J2_PE = 0;
int J3_PE = 0;
int J4_PE = 0;
int J5_PE = 0;
int J6_PE = 0;
int J1_SE_1 = 0;
int J2_SE_1 = 0;
int J3_SE_1 = 0;
int J4_SE_1 = 0;
int J5_SE_1 = 0;
int J6_SE_1 = 0;
int J1_SE_2 = 0;
int J2_SE_2 = 0;
int J3_SE_2 = 0;
int J4_SE_2 = 0;
int J5_SE_2 = 0;
int J6_SE_2 = 0;
int J1_LO_1 = 0;
int J2_LO_1 = 0;
int J3_LO_1 = 0;
int J4_LO_1 = 0;
int J5_LO_1 = 0;
int J6_LO_1 = 0;
int J1_LO_2 = 0;
int J2_LO_2 = 0;
int J3_LO_2 = 0;
int J4_LO_2 = 0;
int J5_LO_2 = 0;
int J6_LO_2 = 0;
//reset
int J1cur = 0;
int J2cur = 0;
int J3cur = 0;
int J4cur = 0;
int J5cur = 0;
int J6cur = 0;
int J1_PEcur = 0;
int J2_PEcur = 0;
int J3_PEcur = 0;
int J4_PEcur = 0;
int J5_PEcur = 0;
int J6_PEcur = 0;
int J1_SE_1cur = 0;
int J2_SE_1cur = 0;
int J3_SE_1cur = 0;
int J4_SE_1cur = 0;
int J5_SE_1cur = 0;
int J6_SE_1cur = 0;
int J1_SE_2cur = 0;
int J2_SE_2cur = 0;
int J3_SE_2cur = 0;
int J4_SE_2cur = 0;
int J5_SE_2cur = 0;
int J6_SE_2cur = 0;
int highStepCur = 0;
///// DRIVE MOTORS /////
while (J1cur < J1step || J2cur < J2step || J3cur < J3step || J4cur
< J4step || J5cur < J5step || J6cur < J6step) {
/////// J1 ////////////////////////////////
///find pulse every
J1_PE = (HighStep / J1step);
///find left over 1
J1_LO_1 = (HighStep - (J1step * J1_PE));
///find skip 1
if (J1_LO_1 > 0)
{
J1_SE_1 = (HighStep / J1_LO_1);
}
else
{
J1_SE_1 = 0;
}
///find left over 2
if (J1_SE_1 > 0)
{
J1_LO_2 = HighStep - ((J1step * J1_PE) + ((J1step * J1_PE) /
J1_SE_1)); } else { J1_LO_2 = 0; } ///find skip 2 if (J1_LO_2 > 0) { J1_SE_2 = (HighStep / J1_LO_2); } else { J1_SE_2 = 0; } //////////////////////// if (J1cur < J1step) { if (J1_SE_2 == 0) { J1_SE_2cur = (J1_SE_2 + 1); } if (J1_SE_2cur != J1_SE_2) { J1_SE_2cur = ++J1_SE_2cur; if (J1_SE_1 == 0) { J1_SE_1cur = (J1_SE_1 + 1); } if (J1_SE_1cur != J1_SE_1) { J1_SE_1cur = ++J1_SE_1cur; J1_PEcur = ++J1_PEcur; if (J1_PEcur == J1_PE) { J1cur = ++J1cur; J1_PEcur = 0; digitalWrite(J1stepPin, LOW); } } else { J1_SE_1cur = 0; } } else { J1_SE_2cur = 0; } } /////////////////////////////////////////
/////// J2 ////////////////////////////////
///find pulse every
J2_PE = (HighStep / J2step);
///find left over 1
J2_LO_1 = (HighStep - (J2step * J2_PE));
///find skip 1
if (J2_LO_1 > 0)
{
J2_SE_1 = (HighStep / J2_LO_1);
}
else
{
J2_SE_1 = 0;
}
///find left over 2
if (J2_SE_1 > 0)
{
J2_LO_2 = HighStep - ((J2step * J2_PE) + ((J2step * J2_PE) /
J2_SE_1)); } else { J2_LO_2 = 0; } ///find skip 2 if (J2_LO_2 > 0) { J2_SE_2 = (HighStep / J2_LO_2); } else { J2_SE_2 = 0; } //////////////////////// if (J2cur < J2step) { if (J2_SE_2 == 0) { J2_SE_2cur = (J2_SE_2 + 1); } if (J2_SE_2cur != J2_SE_2) { J2_SE_2cur = ++J2_SE_2cur; if (J2_SE_1 == 0) { J2_SE_1cur = (J2_SE_1 + 1); } if (J2_SE_1cur != J2_SE_1) { J2_SE_1cur = ++J2_SE_1cur; J2_PEcur = ++J2_PEcur; if (J2_PEcur == J2_PE) { J2cur = ++J2cur; J2_PEcur = 0; digitalWrite(J2stepPin, LOW); } } else { J2_SE_1cur = 0; } } else { J2_SE_2cur = 0; } } /////////////////////////////////////////
/////// J3 ////////////////////////////////
///find pulse every
J3_PE = (HighStep / J3step);
///find left over 1
J3_LO_1 = (HighStep - (J3step * J3_PE));
///find skip 1
if (J3_LO_1 > 0)
{
J3_SE_1 = (HighStep / J3_LO_1);
}
else
{
J3_SE_1 = 0;
}
///find left over 2
if (J3_SE_1 > 0)
{
J3_LO_2 = HighStep - ((J3step * J3_PE) + ((J3step * J3_PE) /
J3_SE_1)); } else { J3_LO_2 = 0; } ///find skip 2 if (J3_LO_2 > 0) { J3_SE_2 = (HighStep / J3_LO_2); } else { J3_SE_2 = 0; } //////////////////////// if (J3cur < J3step) { if (J3_SE_2 == 0) { J3_SE_2cur = (J3_SE_2 + 1); } if (J3_SE_2cur != J3_SE_2) { J3_SE_2cur = ++J3_SE_2cur; if (J3_SE_1 == 0) { J3_SE_1cur = (J3_SE_1 + 1); } if (J3_SE_1cur != J3_SE_1) { J3_SE_1cur = ++J3_SE_1cur; J3_PEcur = ++J3_PEcur; if (J3_PEcur == J3_PE) { J3cur = ++J3cur; J3_PEcur = 0; digitalWrite(J3stepPin, LOW); } } else { J3_SE_1cur = 0; } } else { J3_SE_2cur = 0; } } /////////////////////////////////////////
/////// J4 ////////////////////////////////
///find pulse every
J4_PE = (HighStep / J4step);
///find left over 1
J4_LO_1 = (HighStep - (J4step * J4_PE));
///find skip 1
if (J4_LO_1 > 0)
{
J4_SE_1 = (HighStep / J4_LO_1);
}
else
{
J4_SE_1 = 0;
}
///find left over 2
if (J4_SE_1 > 0)
{
J4_LO_2 = HighStep - ((J4step * J4_PE) + ((J4step * J4_PE) /
J4_SE_1)); } else { J4_LO_2 = 0; } ///find skip 2 if (J4_LO_2 > 0) { J4_SE_2 = (HighStep / J4_LO_2); } else { J4_SE_2 = 0; } //////////////////////// if (J4cur < J4step) { if (J4_SE_2 == 0) { J4_SE_2cur = (J4_SE_2 + 1); } if (J4_SE_2cur != J4_SE_2) { J4_SE_2cur = ++J4_SE_2cur; if (J4_SE_1 == 0) { J4_SE_1cur = (J4_SE_1 + 1); } if (J4_SE_1cur != J4_SE_1) { J4_SE_1cur = ++J4_SE_1cur; J4_PEcur = ++J4_PEcur; if (J4_PEcur == J4_PE) { J4cur = ++J4cur; J4_PEcur = 0; digitalWrite(J4stepPin, LOW); } } else { J4_SE_1cur = 0; } } else { J4_SE_2cur = 0; } } /////////////////////////////////////////
/////// J5 ////////////////////////////////
///find pulse every
J5_PE = (HighStep / J5step);
///find left over 1
J5_LO_1 = (HighStep - (J5step * J5_PE));
///find skip 1
if (J5_LO_1 > 0)
{
J5_SE_1 = (HighStep / J5_LO_1);
}
else
{
J5_SE_1 = 0;
}
///find left over 2
if (J5_SE_1 > 0)
{
J5_LO_2 = HighStep - ((J5step * J5_PE) + ((J5step * J5_PE) /
J5_SE_1)); } else { J5_LO_2 = 0; } ///find skip 2 if (J5_LO_2 > 0) { J5_SE_2 = (HighStep / J5_LO_2); } else { J5_SE_2 = 0; } //////////////////////// if (J5cur < J5step) { if (J5_SE_2 == 0) { J5_SE_2cur = (J5_SE_2 + 1); } if (J5_SE_2cur != J5_SE_2) { J5_SE_2cur = ++J5_SE_2cur; if (J5_SE_1 == 0) { J5_SE_1cur = (J5_SE_1 + 1); } if (J5_SE_1cur != J5_SE_1) { J5_SE_1cur = ++J5_SE_1cur; J5_PEcur = ++J5_PEcur; if (J5_PEcur == J5_PE) { J5cur = ++J5cur; J5_PEcur = 0; digitalWrite(J5stepPin, LOW); } } else { J5_SE_1cur = 0; } } else { J5_SE_2cur = 0; } } /////////////////////////////////////////
/////// J6 ////////////////////////////////
///find pulse every
J6_PE = (HighStep / J6step);
///find left over 1
J6_LO_1 = (HighStep - (J6step * J6_PE));
///find skip 1
if (J6_LO_1 > 0)
{
J6_SE_1 = (HighStep / J6_LO_1);
}
else
{
J6_SE_1 = 0;
}
///find left over 2
if (J6_SE_1 > 0)
{
J6_LO_2 = HighStep - ((J6step * J6_PE) + ((J6step * J6_PE) /
J6_SE_1)); } else { J6_LO_2 = 0; } ///find skip 2 if (J6_LO_2 > 0) { J6_SE_2 = (HighStep / J6_LO_2); } else { J6_SE_2 = 0; } //////////////////////// if (J6cur < J6step) { if (J6_SE_2 == 0) { J6_SE_2cur = (J6_SE_2 + 1); } if (J6_SE_2cur != J6_SE_2) { J6_SE_2cur = ++J6_SE_2cur; if (J6_SE_1 == 0) { J6_SE_1cur = (J6_SE_1 + 1); } if (J6_SE_1cur != J6_SE_1) { J6_SE_1cur = ++J6_SE_1cur; J6_PEcur = ++J6_PEcur; if (J6_PEcur == J6_PE) { J6cur = ++J6cur; J6_PEcur = 0; digitalWrite(J6stepPin, LOW); } } else { J6_SE_1cur = 0; } } else { J6_SE_2cur = 0; } } /////////////////////////////////////////
// inc cur step
highStepCur = ++highStepCur;
////DELAY 1/////
if (highStepCur <= ACCStep)
{
delayMicroseconds(ACCSpeed);
ACCSpeed = ACCSpeed + ACCinc;
}
else if (highStepCur >= DCCStep)
{
delayMicroseconds(DCCSpeed);
DCCSpeed = DCCSpeed + DCCinc;
}
else
{
delayMicroseconds(REGSpeed);
}
///////////////////////////////
/////RESET STEPS AND DELAY ////
digitalWrite(J1stepPin, HIGH);
digitalWrite(J2stepPin, HIGH);
digitalWrite(J3stepPin, HIGH);
digitalWrite(J4stepPin, HIGH);
digitalWrite(J5stepPin, HIGH);
digitalWrite(J6stepPin, HIGH);
delayMicroseconds(25);
}
////////MOVE COMPLETE///////////
inData = ""; // Clear recieved buffer
Serial.print("Move Done");
On Tue, Jan 9, 2018 at 12:41 AM, cqliliping notifications@github.com wrote:
Hi.Chris_Annin. I'm reading arduino code,but it is too difficult to me to comprehend somewhere in short time.especially in code line 831 ////CALC SPEEDS///// ,/////DRIVE MOTORS/////. I want to know how it works,then I can make every stepper works on the same speed with different pulse. I'm from China and interesting in this project,and learning it.I just hope everyone can understand it rapidly and practice. Best regards liliping
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Chris-Annin/AR2/issues/7, or mute the thread https://github.com/notifications/unsubscribe-auth/ATpgLbL7RMqW_RZd42atKyh3gEWucphLks5tIyZPgaJpZM4RXfCv .
hi,Chris-Annin. 'PE stands for Pulse Every (loop) and SE stands for Skip Every (loop)' help me a to understand more with it,Maybe need to make a record when I study the code. Thanks for your reply! liliping
Hi.Chris_Annin. I'm reading arduino code,but it is too difficult to me to comprehend somewhere in short time.especially in code line 831 ////CALC SPEEDS///// ,/////DRIVE MOTORS/////. I want to know how it works,then I can make every stepper works on the same speed with different pulse. I'm from China and interesting in this project,and learning it.I just hope everyone can understand it rapidly and practice. Best regards liliping