Bladeren bron

added homing method

Etienne Landon 7 jaren geleden
bovenliggende
commit
71e3f0bff5
2 gewijzigde bestanden met toevoegingen van 33 en 12 verwijderingen
  1. 7 7
      osc.h
  2. 26 5
      stepper.h

+ 7 - 7
osc.h

@@ -43,11 +43,11 @@ void printTest(OSCMessage &msg) {
 
 
 
-//void init_Stepper_OSC(OSCMessage &msg) {
-//  float maximum = init_Stepper();
-//  sendOSC("/stepper/maxPos",maximum );
-//}
-//
+void homing_Stepper_OSC(OSCMessage &msg) {
+  homing_Stepper();
+  sendOSC("/stepper/homing",3, "done" );
+}
+
 
 void setCurrentPosition_Stepper_OSC (OSCMessage &msg) {
   int index = msg.getInt(0);
@@ -101,9 +101,9 @@ void status_Stepper_OSC(int stepper_index) {
   OSCMessage OSCmsg("/stepper/status");
   OSCmsg.add(stepper_index);  
   OSCmsg.add(steppers[stepper_index].currentPosition());
-  OSCmsg.add(steppers[stepper_index].targetPosition());
+  //OSCmsg.add(steppers[stepper_index].targetPosition());
   OSCmsg.add(steppers[stepper_index].speed());
-  OSCmsg.add(steppers[stepper_index].maxSpeed());
+  //OSCmsg.add(steppers[stepper_index].maxSpeed());
   SLIPSerial.beginPacket(); 
   //Udp.beginPacket(outIp, outPort);
   OSCmsg.send(SLIPSerial); // send the bytes to the SLIP stream

+ 26 - 5
stepper.h

@@ -24,13 +24,16 @@ long int STEPS_PER_TURN = 200 ; // stepper motor
 int MICROSTEPPING = 8 ; //stepper driver
 int REDUCTION_RATIO = 70 ;  // mechanical reduction ration to real camera rotation
 
-// microswitch pins
-int switchLow = A5;
+// homing switch pins
+const int homing_Pins = { 2, 3 } ; 
+bool homing[NUM_OF_STEPPERS] ; 
 
 int driveMode ; // global stepper driving mode : default position with acceleration, 1 position with constant speed, 2 constant speed
 long int speedLimit[2] = { 50 , 10000000 } ;// sets an absolute minimum/maximum speed limit
 long int accLimit[2] = { 100, 200000} ;
 
+
+
 //////////// UTILITIES  ///////////////
 
 
@@ -87,10 +90,28 @@ long int acceleration_Stepper(int stepperIndex, long int acc ){
 
 
 
-//////////////// CALIBRATION ////////////////////////
+//////////////// HOMING ////////////////////////
+
+float homing_steppers(){
+  //run at constant speed until hitting switch
+  while( homing[0] + homing[1]  != 2 ){
+    for (int i; i++; i<NUM_OF_STEPPERS) {    
+      if (!homing[i]) { 
+       steppers[i].runSpeed() ;
+       homing[i] = digitalRead(homing_Pins[i]) ;
+      }
+    }
+  }
+
+  //this is the new 0 step for both axes
+  for (int i; i++; i<NUM_OF_STEPPERS) {  
+    steppers[i].setCurrentPosition(0);
+  }
+}
+
+
+
 
-float init_steppers(){
-//  //run at constant speed until hitting switchLow
 //  stepper.setSpeed(-1*speedLimit[1]); 
 //  while(digitalRead(switchLow)) {
 //    stepper.runSpeed();