I am currently building a platform to take my panoramic videos. I am using a clear path servo motor and attaching two limit switches to tell it to reverse the direction. Here is what I have so far. I cannot even get the motor to start. It's been quite some time since I have dabbled with arduino and coding so I apologize for the terrible code. (if it is bad)
#include <PulseClearpath.h>
#include <StepController.h>
#include <StepClearpath.h>
StepClearpath X; // initialize a StepClearpath Motor
StepController machine(&X); //initialize the controller and pass the reference to the motor we are controlling
boolean IsSDHPmodel=false;
boolean IsSDSKmodel=true;
int limitL = 11;
int limitR = 12;
int stage1 = 0;
int stage2 = 0;
int num1 = 0;
double TotalDistance=20; // distance in Steps - check step/rev in ClearPath MSP config file (1,600 steps/rev)
void setup(){
pinMode(2,OUTPUT); //DEBUG declare pin 2 as output. Abe, this shows when the arduino is in the ISR
pinMode(limitL, INPUT_PULLUP);
pinMode(limitR, INPUT_PULLUP);
Serial.begin(9600);
X.attach(8,9,6,4); //Direction/A is pin 8, Step/B is pin 9, Enable is pin 6, HLFB is pin 4 //JWS: HFLB = high level feedback info coming from motor to arduino
X.setMaxVel(500); // Set max Velocity. Parameter can be between 2 and 100,000
X.setMaxAccel(5000); // Set max Acceleration. Parameter can be between 4000 and 2,000,000
X.enable(); // Enable motor, reset the motor position to 0 //JWS: enable happens automatically per Clearpath (whenever enabled) - no actual arduino code required
Serial.print("Homing..."); // wait until the command is finished and then 1 more second
while(X.readHLFB()) {
Serial.print('z');
}
Serial.println();
Serial.println("Homing Complete");
delay(200);
machine.Start(249); // Set up the ISR to constantly check motor position. PARAMETER MUST BE SET TO 249
}
void loop (){
if (limitR == HIGH && num1 == 0 ){
stage1 = 1;
Serial.println("limit2");
num1 = 1;}
if (limitL == HIGH && num1 == 0){
stage2 = 1;
Serial.println("limitL");
num1 = 1;
}
if (stage2 = 1){
X.move(TotalDistance);
if (limitR, HIGH){
stage1 = 1;
stage2 = 0;
Serial.println("stage2");
}
}
if (stage1 = 1){
X.move(-TotalDistance);
if (limitL, HIGH){
stage1 = 0;
stage2 = 1;
Serial.println("stage1");
}
}
}