__

Dependencies:   X_NUCLEO_IHM04A1

Revision:
21:533d014f09e0
Parent:
20:8e5dd30b1b59
Child:
22:137d1ef8d22d
--- a/main.cpp	Fri Feb 08 19:48:07 2019 +0000
+++ b/main.cpp	Sat Apr 06 09:20:46 2019 +0000
@@ -6,11 +6,11 @@
 
 l6208_init_t init =
 {
-  2000,            //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
+  8000,            //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
   80,              //Acceleration current torque in % (from 0 to 100)
-  2000,            //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
+  8000,            //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
   80,              //Deceleration current torque in % (from 0 to 100)
-  6000,            //Running speed in step/s or (1/16)th step/s for microstep modes
+  8000,            //Running speed in step/s or (1/16)th step/s for microstep modes
   80,              //Running current torque in % (from 0 to 100)
   40,              //Holding current torque in % (from 0 to 100)
   STEP_MODE_1_16,  //Step mode via enum motorStepMode_t
@@ -19,6 +19,7 @@
   FALSE,           //Automatic HIZ STOP
   100000           //VREFA and VREFB PWM frequency (Hz)
 };
+
 Thread canrxa;
 
 // Utility
@@ -41,11 +42,15 @@
   while(1){} 
 }
 
+void motor_zero()
+{
+  motor->run(StepperMotor::FWD);
+}
+
 void button_int_handler()
 {
     printf("POSITION: %d\n\r", motor->get_position());
-    
-    motor->go_to(-160000);
+    motor_zero();
 }
 
 void end0_int_handler()
@@ -72,11 +77,6 @@
   pose = 0;
 }
 
-void motor_zero()
-{
-  motor->run(StepperMotor::BWD);
-}
-
 // CAN
 CAN can1(PA_11, PA_12);     // RX, TX
 
@@ -88,32 +88,36 @@
 void canrx()
 {
   while(1)
-  {
+  {    
     if(can1.read(messageIn, filter))
     {
       pose=messageIn.data[0] + (messageIn.data[1] << 8) + (messageIn.data[2] << 16) + (messageIn.data[3] << 24);
       printf("CAN: mess %d\n\r", pose);
-      printf("CANaacc: id %x \n\r ",messageIn.id);
-        if (pose == 0) 
-        {
-            motor->run(StepperMotor::BWD);
-        }
-        else if (pose == 50)
-        {
-            motor->soft_stop();
-            current_pose= motor->get_position();
-            motor->go_to(current_pose);
-        }
-        else if (pose == 100)
-        {
-            motor->run(StepperMotor::FWD);
-        }
-        else 
-        {
-            motor->soft_stop();
-            current_pose= motor->get_position();
-            motor->go_to(current_pose);
-        }
+      
+      /*
+      if (pose == 0) 
+      {
+        motor->run(StepperMotor::FWD);
+      }
+      else if (pose == 1)
+      {
+        motor->soft_stop();
+        current_pose= motor->get_position();
+        motor->go_to(current_pose);
+      }
+      else if (pose == 2)
+      {
+        motor->run(StepperMotor::BWD);
+      }
+      else 
+      {
+        motor->soft_stop();
+        current_pose= motor->get_position();
+        motor->go_to(current_pose);
+      }
+      */
+      
+      motor->go_to(pose);
     }
   }
 }
@@ -123,6 +127,8 @@
 
 int main()
 {
+  can1.frequency(125000);
+  
   // Motor Initialization 
   motor = new L6208(D2, D8, D7, D4, D5, D6, VREFA_PWM_PIN, VREFB_PWM_PIN);
   
@@ -139,10 +145,12 @@
   end1.fall(&motor_set_home);
   
   button.rise(&button_int_handler);
+  
   motor->set_step_mode(StepperMotor::STEP_MODE_1_16);
   printf("DONE: Motor Init\n\r");
   
   // CAN Initialization
+  
   canrxa.start(canrx);
   
   printf("DONE: CAN Init\n\r");