update c mac steppers to take args and remove windows.h
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// Leib Ramp Stepper program with millis function adapted for MacOS
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -52,57 +51,52 @@ const float minSpeed = 1.0;
|
||||
const float maxPermissSpeed = 20.0;
|
||||
const float maxAccel = 10.0;
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[1])
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
prevStepTime = 0;
|
||||
long positionToMoveTo;
|
||||
while(true)
|
||||
sscanf(argv[1], "%ld", &positionToMoveTo);
|
||||
printf(" Time (s), Speed (steps/s), Accel (steps/s^2), Posit'n (steps), Step time (ticks)\n");
|
||||
|
||||
goToPosition(positionToMoveTo);
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* Start of pre-computation code - only executed once per profile */
|
||||
// STEP 1
|
||||
// Define number of steps in acceleration phase using Equation (3)
|
||||
accelSteps = (long)(( maxPermissSpeed * maxPermissSpeed - minSpeed * minSpeed) / ( 2.0 * (float)maxAccel)); // Equation 4 but need to consider initial speed
|
||||
stepsToGo = computeStepsToGo();
|
||||
maxSpeed = maxPermissSpeed;
|
||||
if (2 * accelSteps > stepsToGo)
|
||||
{
|
||||
printf("Enter position to move to in profile (or 999 to terminate)\n");
|
||||
scanf("%ld", &positionToMoveTo);
|
||||
if (positionToMoveTo==999) break;
|
||||
printf(" Time (s), Speed (steps/s), Accel (steps/s^2), Posit'n (steps), Step time (ticks)\n");
|
||||
// STEP 2
|
||||
// Define maximum speed in profile and number of steps in acceleration phase
|
||||
// Use Equations (4) and (5)
|
||||
maxSpeed = sqrt(minSpeed * minSpeed + stepsToGo * maxAccel); // Modified version of eq. 5
|
||||
accelSteps = (long)(stepsToGo / 2);
|
||||
}
|
||||
|
||||
goToPosition(positionToMoveTo);
|
||||
// STEPS 3 and 5
|
||||
// Calculate initial value of and p1 and R Set p = p1
|
||||
p1 = (float)ticksPerSec / sqrt( minSpeed * minSpeed + 2 * maxAccel); // Eq 17 incorporating initial velocity
|
||||
p = p1;
|
||||
R = (float) maxAccel / ((float)ticksPerSec * (float)ticksPerSec); // Eq 19
|
||||
ps = ((float)ticksPerSec) / maxSpeed; // STEP 4 Eq 7 in paper
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* Start of pre-computation code - only executed once per profile */
|
||||
// STEP 1
|
||||
// Define number of steps in acceleration phase using Equation (3)
|
||||
accelSteps = (long)(( maxPermissSpeed * maxPermissSpeed - minSpeed * minSpeed) / ( 2.0 * (float)maxAccel)); // Equation 4 but need to consider initial speed
|
||||
stepsToGo = computeStepsToGo();
|
||||
maxSpeed = maxPermissSpeed;
|
||||
if (2 * accelSteps > stepsToGo)
|
||||
/* End of pre-computation code */
|
||||
/* -------------------------------------------------------------- */
|
||||
millisAtStart = millis(); /* Needed only to tabulate speed vs. time */
|
||||
|
||||
/* Timed loop for stepping, and associated coding */
|
||||
while(stepsToGo > 0)
|
||||
{
|
||||
currentMillis = millis();
|
||||
if (currentMillis - prevStepTime >= p)
|
||||
{
|
||||
// STEP 2
|
||||
// Define maximum speed in profile and number of steps in acceleration phase
|
||||
// Use Equations (4) and (5)
|
||||
maxSpeed = sqrt(minSpeed * minSpeed + stepsToGo * maxAccel); // Modified version of eq. 5
|
||||
accelSteps = (long)(stepsToGo / 2);
|
||||
}
|
||||
|
||||
// STEPS 3 and 5
|
||||
// Calculate initial value of and p1 and R Set p = p1
|
||||
p1 = (float)ticksPerSec / sqrt( minSpeed * minSpeed + 2 * maxAccel); // Eq 17 incorporating initial velocity
|
||||
p = p1;
|
||||
R = (float) maxAccel / ((float)ticksPerSec * (float)ticksPerSec); // Eq 19
|
||||
ps = ((float)ticksPerSec) / maxSpeed; // STEP 4 Eq 7 in paper
|
||||
|
||||
/* End of pre-computation code */
|
||||
/* -------------------------------------------------------------- */
|
||||
millisAtStart = millis(); /* Needed only to tabulate speed vs. time */
|
||||
|
||||
/* Timed loop for stepping, and associated coding */
|
||||
while(stepsToGo > 0)
|
||||
{
|
||||
currentMillis = millis();
|
||||
if (currentMillis - prevStepTime >= p)
|
||||
{
|
||||
moveOneStep();
|
||||
prevStepTime = currentMillis;
|
||||
computeNewSpeed();
|
||||
}
|
||||
moveOneStep();
|
||||
prevStepTime = currentMillis;
|
||||
computeNewSpeed();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -48,50 +47,45 @@ const float minSpeed = 1.0; // in steps/s
|
||||
const float maxPermissSpeed = 20.0; // in steps/s
|
||||
const float maxAccel = 10.0; // in steps/s^2
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
prevStepTime = 0;
|
||||
long positionToMoveTo;
|
||||
while(true)
|
||||
sscanf(argv[1], "%ld", &positionToMoveTo);
|
||||
printf(" Time (s), Speed (steps/s), Accel (steps/s^2), Posit'n (steps), Step time (ticks)\n");
|
||||
|
||||
goToPosition(positionToMoveTo);
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* Start of pre-computation code - only executed once per profile */
|
||||
|
||||
float maxInterval = ((float)ticksPerSec) / minSpeed;
|
||||
ps = ((float)ticksPerSec) / maxPermissSpeed;
|
||||
deltaP = (maxInterval - ps) / accelSteps;
|
||||
stepsToGo = computeStepsToGo();
|
||||
maxSpeed = maxPermissSpeed;
|
||||
if (2 * accelSteps > stepsToGo)
|
||||
{
|
||||
printf("Enter position to move to in profile (or 999 to terminate)\n");
|
||||
scanf("%ld", &positionToMoveTo);
|
||||
if (positionToMoveTo==999) break;
|
||||
printf(" Time (s), Speed (steps/s), Accel (steps/s^2), Posit'n (steps), Step time (ticks)\n");
|
||||
accelSteps = (long)(stepsToGo / 2);
|
||||
}
|
||||
|
||||
goToPosition(positionToMoveTo);
|
||||
p = maxInterval;
|
||||
|
||||
ps = ((float)ticksPerSec) / maxSpeed;
|
||||
/* End of pre-computation code */
|
||||
/* -------------------------------------------------------------- */
|
||||
millisAtStart = millis(); /* Needed only to tabulate speed vs. time */
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* Start of pre-computation code - only executed once per profile */
|
||||
|
||||
float maxInterval = ((float)ticksPerSec) / minSpeed;
|
||||
ps = ((float)ticksPerSec) / maxPermissSpeed;
|
||||
deltaP = (maxInterval - ps) / accelSteps;
|
||||
stepsToGo = computeStepsToGo();
|
||||
maxSpeed = maxPermissSpeed;
|
||||
if (2 * accelSteps > stepsToGo)
|
||||
/* Timed loop for stepping */
|
||||
while(stepsToGo > 0)
|
||||
{
|
||||
currentMillis = millis();
|
||||
if (currentMillis - prevStepTime >= p)
|
||||
{
|
||||
accelSteps = (long)(stepsToGo / 2);
|
||||
}
|
||||
|
||||
p = maxInterval;
|
||||
|
||||
ps = ((float)ticksPerSec) / maxSpeed;
|
||||
/* End of pre-computation code */
|
||||
/* -------------------------------------------------------------- */
|
||||
millisAtStart = millis(); /* Needed only to tabulate speed vs. time */
|
||||
|
||||
/* Timed loop for stepping */
|
||||
while(stepsToGo > 0)
|
||||
{
|
||||
currentMillis = millis();
|
||||
if (currentMillis - prevStepTime >= p)
|
||||
{
|
||||
moveOneStep();
|
||||
prevStepTime = currentMillis;
|
||||
computeNewSpeed();
|
||||
}
|
||||
moveOneStep();
|
||||
prevStepTime = currentMillis;
|
||||
computeNewSpeed();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
Reference in New Issue
Block a user