123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- #include <AccelStepper.h>
-
- const int NUM_OF_STEPPERS = 2 ;
- AccelStepper steppers[NUM_OF_STEPPERS] = {AccelStepper(1, 8, 7), AccelStepper(1, 10, 9)}; ;
- long int STEPS_PER_TURN = 200 ;
- int MICROSTEPPING = 8 ;
- int REDUCTION_RATIO = 70 ;
- int switchLow = A5;
- int driveMode ;
- long int speedLimit[2] = { 50 , 10000000 } ;
- long int accLimit[2] = { 100, 200000} ;
- long int camRot2steps (float camRot ) {
- return (long int) STEPS_PER_TURN * MICROSTEPPING * REDUCTION_RATIO *camRot ;
- }
- void stop_Steppers (void) {
- for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
- steppers[i].stop();
- }
-
- }
- long int moveTo_Stepper(int stepperIndex, long int stepto ) {
- steppers[stepperIndex].moveTo(stepto);
- return steppers[stepperIndex].distanceToGo();
- }
- long int move_Stepper(int stepperIndex, long int stepRelative ) {
- steppers[stepperIndex].move(stepRelative);
- return steppers[stepperIndex].distanceToGo();
- }
- long int maxSpeed_Stepper(int stepperIndex, long int maxspeed){
- steppers[stepperIndex].setMaxSpeed( constrain (maxspeed, speedLimit[0], speedLimit[1] ) );
- return steppers[stepperIndex].maxSpeed();
- }
- long int setSpeed_Stepper(int stepperIndex, long int maxspeed){
- steppers[stepperIndex].setSpeed( constrain (maxspeed, speedLimit[0], speedLimit[1] ) );
- return steppers[stepperIndex].maxSpeed();
- }
- long int acceleration_Stepper(int stepperIndex, long int acc ){
- steppers[stepperIndex].setAcceleration(acc + 1);
- return acc;
- }
- float init_steppers(){
- }
- void setup_steppers(){
- pinMode (switchLow, INPUT_PULLUP);
- for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
- steppers[i].setMaxSpeed( 20000);
- steppers[i].setSpeed(10000);
- }
-
- }
- bool update_steppers() {
- for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
- switch (driveMode) {
- case 1:
- steppers[i].runSpeedToPosition();
- break ;
- case 2:
- steppers[i].runSpeed();
- break ;
- default :
- steppers[i].run();
- }
-
-
- }
-
-
-
- }
|