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:
- 0:be6047ad0802
- Child:
- 1:1ec6af6d0c6d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MS9g_move_sin.cpp Tue May 01 13:08:26 2018 +0000
@@ -0,0 +1,45 @@
+#include "MS9g_move_sin.h"
+
+Servo_9g::Servo_9g(){
+}
+
+Servo_9g::Servo_9g (PinName Pin):
+Servo(Pin)
+{
+ Servo.period_ms(20);
+}
+
+~Servo_9g(){
+
+}
+
+void Servo_9g_Move::start_move_sin(){
+ timer.attach(this, &Servo_9g::calc_n_move, val); //sine period, sec
+}
+
+void Servo_9g_Move::calc_n_move(){
+ Servo_9g::move (Servo_9g::next_sin());
+}
+
+void Servo_9g_Move::move (float f){
+ Servo = f * val; // duty-cycle, perсents 0..1; посчитанное значение вставится в следующее прерывание
+}
+
+float Servo_9g_Move::next_sin(){
+ i += 0.1;
+ if (i > 2) i = 0;
+ f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
+ return (float)f;
+}
+
+Servo_9g_CAN::Servo_9g_CAN(PinName servo_pwm, PinName rd, PinName td):Servo_9g_Move(servo_pwm):
+can(rd, td)
+{
+
+}
+
+Servo_9g_CAN::Servo_9g_CAN(PinName servo_pwm, PinName rd, PinName td, int hz):Servo_9g_Move(servo_pwm):
+can(rd, td, hz)
+{
+
+}
\ No newline at end of file