Parcourir la source

driving modes and communication

*added methods for driving mode :
- default is position driven with acceleration
- 1 is position driven, constant speed
- 2 is constant speed

*modified sendOSC() template, added a first parameter to ease filtering
in receiver. "0" or "1" is corresponding stepper, 3 is global
Etienne Landon il y a 7 ans
Parent
commit
9e50263466
3 fichiers modifiés avec 48 ajouts et 26 suppressions
  1. 1 1
      C_Vieille_OSCstepperCtl.ino
  2. 34 24
      osc.h
  3. 13 1
      stepper.h

+ 1 - 1
C_Vieille_OSCstepperCtl.ino

@@ -8,7 +8,7 @@ void setup() {
   setup_OSC();
   setup_steppers();
   delay(1000);
-  sendOSC("/ended ", "setup");
+  sendOSC("/ended ", 3,  "setup");
 //  init_steppers() ;
 
 }

+ 34 - 24
osc.h

@@ -18,8 +18,9 @@ bool update_stepper_status[NUM_OF_STEPPERS];
 ////  UTILITIES ///////// 
 
 
-template <typename TYPE> void sendOSC(const char * adress, TYPE parameter) {
+template <typename TYPE> void sendOSC(const char * adress, int first_param, TYPE parameter) {
   OSCMessage OSCmsg(adress);
+  OSCmsg.add(first_param);
   OSCmsg.add(parameter);
   SLIPSerial.beginPacket(); 
   //Udp.beginPacket(outIp, outPort);
@@ -31,7 +32,7 @@ template <typename TYPE> void sendOSC(const char * adress, TYPE parameter) {
 }
 
 void printTest(OSCMessage &msg) {
-  sendOSC("/still", "up and running");
+  sendOSC("/still", 3, "up and running");
 }
 
 
@@ -45,40 +46,47 @@ void printTest(OSCMessage &msg) {
 //  sendOSC("/stepper/maxPos",maximum );
 //}
 //
+
+void setCurrentPosition_Stepper_OSC (OSCMessage &msg) {
+  int index = msg.getInt(0);
+  steppers[index].setCurrentPosition(msg.getInt(1));
+  sendOSC("/stepper/setPosition/", index,  "position set");
+}
+
+void drivingMode_Stepper_OSC (OSCMessage &msg) {
+  driveMode = msg.getInt(0);
+  sendOSC("/stepper/driveMode/", 3,  "set to " + driveMode);
+}
+
 void moveTo_Stepper_OSC (OSCMessage &msg){
-  long int distance = moveTo_Stepper(msg.getInt(0), msg.getInt(1));
-  sendOSC("/stepper/distanceToGo",distance );
+  int index = msg.getInt(0);
+  long int distance = moveTo_Stepper(index, msg.getInt(1));
+  sendOSC("/stepper/distanceToGo", index, distance );
 //  while (!stepper.distanceToGo()==0)
 //    stepper.run();
 }
 
 void move_Stepper_OSC (OSCMessage &msg){
-  long int distance = move_Stepper(msg.getInt(0), msg.getInt(1));
-  sendOSC("/stepper/distanceToGo",distance );
+  int index = msg.getInt(0);
+  long int distance = move_Stepper(index, msg.getInt(1));
+  sendOSC("/stepper/distanceToGo", index, distance );
 }
-//
-//void moveToCm_Stepper_OSC (OSCMessage &msg){
-//  long int distance = moveToCm_Stepper(msg.getFloat(0));
-//  sendOSC("/stepper/distanceToGo/cm",distance );
-//}
-//
-//void moveCm_Stepper_OSC (OSCMessage &msg){
-//  long int distance = moveCm_Stepper(msg.getFloat(0));
-//  sendOSC("/stepper/distanceToGo/cm",distance );
-//}
 
 void maxSpeed_Stepper (OSCMessage &msg){
-  long int max_speed = maxSpeed_Stepper(msg.getInt(0), msg.getInt(1));
-  sendOSC("/stepper/maxSpeed",max_speed );
+  int index = msg.getInt(0);
+  long int max_speed = maxSpeed_Stepper(index, msg.getInt(1));
+  sendOSC("/stepper/maxSpeed", index, max_speed );
 }
 
 void acceleration_Stepper (OSCMessage &msg){
-  long int acceleration = acceleration_Stepper(msg.getInt(0), msg.getInt(1));
-  sendOSC("/stepper/acceleration",acceleration );
+  int index = msg.getInt(0);
+  long int acceleration = acceleration_Stepper(index, msg.getInt(1));
+  sendOSC("/stepper/acceleration", index, acceleration );
 }
 
 void currentPos_Stepper_OSC(OSCMessage &msg) {
-  sendOSC("/stepper/currentPos", steppers[msg.getInt(0)].currentPosition());
+  int index = msg.getInt(0);
+  sendOSC("/stepper/currentPos", index, steppers[index].currentPosition());
 }
 
 void status_Stepper_OSC(int stepper_index) {
@@ -108,7 +116,7 @@ void setup_OSC(){
   
   SLIPSerial.begin(115200);
 //  delay (100);
-  sendOSC("/ready", "to go");
+  sendOSC("/ready", 3, "to go");
 
   
 }
@@ -147,8 +155,10 @@ void handleOSCIn() {
 
 //      //STEPPER CONTROL
 //      OSCin.dispatch("/stepper/init", init_Stepper_OSC);
-    OSCin.dispatch("/stepper/status", getStatus_stepper_OSC);
-    OSCin.dispatch("/stepper/currentPos", currentPos_Stepper_OSC);  
+    OSCin.dispatch("/stepper/getStatus", getStatus_stepper_OSC);
+    OSCin.dispatch("/stepper/setCurrentPosition", setCurrentPosition_Stepper_OSC);
+    OSCin.dispatch("/stepper/currentPosition", currentPos_Stepper_OSC);  
+    OSCin.dispatch("/stepper/driveMode", drivingMode_Stepper_OSC);
     OSCin.dispatch("/stepper/moveTo", moveTo_Stepper_OSC);
     OSCin.dispatch("/stepper/move", move_Stepper_OSC);
 //      OSCin.dispatch("/stepper/moveTo/cm", moveToCm_Stepper_OSC);

+ 13 - 1
stepper.h

@@ -27,6 +27,7 @@ int REDUCTION_RATIO = 70 ;  // mechanical reduction ration to real camera rotati
 // microswitch pins
 int switchLow = A5;
 
+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} ;
 
@@ -141,7 +142,18 @@ void setup_steppers(){
 bool update_steppers() {
 
   for(int i ; i < NUM_OF_STEPPERS ; i++ ) {
-    steppers[i].run();    
+    switch (driveMode) {
+      case 1:
+        steppers[i].runSpeedToPosition();
+        break ;
+      case 2:
+        steppers[i].runSpeed();
+        break ;
+      default :
+        steppers[i].run();
+    }
+      
+        
   }
   
 //  bool updated = 1 ;