library for movement of Servo 9g
Dependents: CAN_Simple_Publisher CAN_Pub_actuator
Revision 4:98c0904b5ec7, committed 2018-06-26
- Comitter:
- RuslanUrya
- Date:
- Tue Jun 26 10:16:55 2018 +0000
- Parent:
- 2:3eadad0761e9
- Commit message:
- filter on in "ReseiveServo"
Changed in this revision
| MS9g_move_sin.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MS9g_move_sin.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/MS9g_move_sin.h Thu May 03 14:46:58 2018 +0000
+++ b/MS9g_move_sin.h Tue Jun 26 10:16:55 2018 +0000
@@ -11,6 +11,7 @@
#include "mbed.h"
#define val 0.05 // percents in step / 100
#define pi 3.141592653589793115997963468544185161590576171875
+#define speed_inc 0.20
class Servo_9g{
public:
@@ -61,6 +62,9 @@
//for transmitting sine signal 1 Hz
void SendSin();
+ //send position to the Sub
+ void sendPosition(char id, float pos);
+
//for receiving of signal and movement of servo
//1- complite, 0- error
bool ReceiveServo();
@@ -71,4 +75,5 @@
private: //variables
CAN can;
CANMessage msg;
+
};