library for movement of Servo 9g
Dependents: CAN_Simple_Publisher CAN_Pub_actuator
MS9g_move_sin.h
00001 /*This is simple library for sinusoidal movement of servo 9g. For now it work with 1 Hz frequency only. Lib include 3 classes: 00002 *Servo_9g 00003 -for receiver: it define the Pin to which servo connected 00004 -for transmiter: empty class 00005 *Servo_9g_Move 00006 -for one-plate interface: it maintain calculating of sine and movement of servo simultaneously 00007 *Servo_9g_CAN 00008 -for receiver: you need define Pin for servo and two pins for CAN-bus, and you may define the friquency of CAN-bus 00009 -for transmiter: you need define two pins for CAN-bus, and you may define the friquency of CAN-bus 00010 Rus Uryadinsky prod*/ 00011 #include "mbed.h" 00012 #define val 0.05 // percents in step / 100 00013 #define pi 3.141592653589793115997963468544185161590576171875 00014 #define speed_inc 0.20 00015 00016 class Servo_9g{ 00017 public: 00018 Servo_9g(); 00019 Servo_9g(PinName Pin); 00020 ~Servo_9g(); 00021 00022 protected: 00023 PwmOut *Servo; 00024 }; 00025 00026 00027 class Servo_9g_Move: public Servo_9g{ 00028 public: 00029 Servo_9g_Move(); 00030 Servo_9g_Move(PinName Pin); 00031 ~Servo_9g_Move(); 00032 00033 //set the sin and move the servo 00034 void StartMoveSin(); 00035 00036 protected: 00037 double f; 00038 Ticker timer; 00039 void Move(float f); //make move for your alg 00040 void NextSin(); //get next value of the sine 00041 00042 private: //functions 00043 void CalCnMove(); 00044 00045 private: //variables 00046 double i; //f- func, i- count 00047 }; 00048 00049 00050 class Servo_9g_CAN:public Servo_9g_Move{ 00051 public: 00052 00053 //constructors for transmiter 00054 Servo_9g_CAN(PinName rd, PinName td); 00055 Servo_9g_CAN(PinName rd, PinName td, int hz); 00056 00057 //constructors for receiver 00058 Servo_9g_CAN(PinName servo_pwm, PinName rd, PinName td); 00059 Servo_9g_CAN(PinName servo_pwm, PinName rd, PinName td, int hz); 00060 ~Servo_9g_CAN(); 00061 00062 //for transmitting sine signal 1 Hz 00063 void SendSin(); 00064 00065 //send position to the Sub 00066 void sendPosition(char id, float pos); 00067 00068 //for receiving of signal and movement of servo 00069 //1- complite, 0- error 00070 bool ReceiveServo(); 00071 00072 private: //functions 00073 void SendNextSin(); 00074 00075 private: //variables 00076 CAN can; 00077 CANMessage msg; 00078 00079 };
Generated on Wed Aug 10 2022 09:29:03 by
1.7.2