Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: CAN_Simple_Publisher CAN_Pub_actuator
Diff: MS9g_move_sin.cpp
- Revision:
- 1:1ec6af6d0c6d
- Parent:
- 0:be6047ad0802
- Child:
- 2:3eadad0761e9
--- a/MS9g_move_sin.cpp Tue May 01 13:08:26 2018 +0000
+++ b/MS9g_move_sin.cpp Wed May 02 12:19:26 2018 +0000
@@ -1,7 +1,6 @@
#include "MS9g_move_sin.h"
-
-Servo_9g::Servo_9g(){
-}
+//class Servo_9g
+Servo_9g::Servo_9g(){}
Servo_9g::Servo_9g (PinName Pin):
Servo(Pin)
@@ -9,37 +8,81 @@
Servo.period_ms(20);
}
-~Servo_9g(){
+Servo_9g::~Servo_9g(){
}
-
-void Servo_9g_Move::start_move_sin(){
- timer.attach(this, &Servo_9g::calc_n_move, val); //sine period, sec
-}
+//end of class Servo_9g
-void Servo_9g_Move::calc_n_move(){
- Servo_9g::move (Servo_9g::next_sin());
-}
+//class Servo_9g_Move
+//Servo_9g_Move::Servo_9g_Move():Servo_9g(){}
+//Servo_9g_Move::Servo_9g_Move(PinName Pin):Servo_9g(Pin){}
+Servo_9g_Move::~Servo_9g_Move(){}
-void Servo_9g_Move::move (float f){
- Servo = f * val; // duty-cycle, perсents 0..1; посчитанное значение вставится в следующее прерывание
+void Servo_9g_Move::Move (float f){
+ Servo = f * val; // duty-cycle, perсents 0..1
}
-float Servo_9g_Move::next_sin(){
+void Servo_9g_Move::NextSin(){
i += 0.1;
if (i > 2) i = 0;
f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
- return (float)f;
+}
+
+void Servo_9g_Move::CalCnMove(){
+ Move((float)f);
+ NextSin();
}
+void Servo_9g_Move::StartMoveSin(){
+ timer.attach(this, &Servo_9g_Move::CalCnMove, val); //sine period, sec
+}
+//end of class Servo_9g_Move
+
+//class Servo_9g_CAN
+Servo_9g_CAN::Servo_9g_CAN(PinName rd, PinName td):Servo_9g_Move():
+can(rd, td)
+{
+ func.id = 1;
+ func.len = 4;
+}
+Servo_9g_CAN::Servo_9g_CAN(PinName rd, PinName td, int hz):Servo_9g_Move():
+can(rd, td, hz)
+{
+ func.id = 1;
+ func.len = 4;
+}
+
Servo_9g_CAN::Servo_9g_CAN(PinName servo_pwm, PinName rd, PinName td):Servo_9g_Move(servo_pwm):
can(rd, td)
{
-
+ func.id = 1;
+ func.len = 4;
}
Servo_9g_CAN::Servo_9g_CAN(PinName servo_pwm, PinName rd, PinName td, int hz):Servo_9g_Move(servo_pwm):
can(rd, td, hz)
{
+ func.id = 1;
+ func.len = 4;
+}
+
+Servo_9g_CAN::~Servo_9g_CAN(){
-}
\ No newline at end of file
+}
+
+void Servo_9g_CAN::SendNextSin(){
+ NextSin();
+ func.data = &f; //возможно func.data = &(const char)f; или func.data = (const char*)&f;
+ can.write(func);
+}
+
+void Servo_9g_CAN::ReceiveServo(){
+ if(can.read(func)){
+ Move((float)func.data); //по идее функ- массив, значит имя-указатель
+ }
+}
+
+void Servo_9g_CAN::SendSin(){
+ timer.attach(this, &Servo_9g_CAN::SendNextSin, val);
+}
+//end of class Servo_9g_CAN
\ No newline at end of file