Руслан Урядинский / MS9g_move_sin

Dependents:   CAN_Simple_Publisher CAN_Pub_actuator

Revision:
4:98c0904b5ec7
Parent:
2:3eadad0761e9
--- a/MS9g_move_sin.cpp	Thu May 03 14:46:58 2018 +0000
+++ b/MS9g_move_sin.cpp	Tue Jun 26 10:16:55 2018 +0000
@@ -21,7 +21,7 @@
 }
     
 void Servo_9g_Move::NextSin(){
-        i += 0.1;
+        i += speed_inc;
         if (i > 2) i = 0;
         f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
 }
@@ -71,16 +71,17 @@
 void Servo_9g_CAN::SendNextSin(){
     NextSin();
     float send = static_cast<float>(f);
-    can.write(CANMessage(1, (char*)&send, sizeof(send)));
+    can.write(CANMessage(2, (char*)&send, sizeof(send)));
 }
 
 bool Servo_9g_CAN::ReceiveServo(){
     if(can.read(msg)){
-        float rec;
-        memcpy(&rec, msg.data, sizeof(rec));
-//        Move((float)*msg.data);
-        Move(rec);
-        return true;
+        if (msg.id == 2){
+            float rec;
+            memcpy(&rec, msg.data, sizeof(rec));
+            Move(rec);
+            return true;
+        }
     }
     return false;
 }
@@ -88,4 +89,7 @@
     timer.attach(this, &Servo_9g_CAN::SendNextSin, val);
     
 }
+void Servo_9g_CAN::sendPosition(char id, float pos){
+    can.write(CANMessage(id, (char*)&pos, sizeof(pos)));
+}
 //end of class Servo_9g_CAN
\ No newline at end of file