動作確認済み

Dependents:   NewMD2 NewMD3

Revision:
2:3d70888e91c6
Parent:
1:b85088467ae0
Child:
4:aa4eca6acb60
--- a/GMD_impl.hpp	Sat Jul 02 06:16:41 2016 +0000
+++ b/GMD_impl.hpp	Sun Jul 03 01:25:10 2016 +0000
@@ -21,8 +21,8 @@
     _pwm[1]->period_ticks(_frequency_to_tick_coeff / f_kHz);
 }
 
-float sign(float v) {
-    if (v < 0.0f) {
+float sign(float n) {
+    if (n < 0.0f) {
         return -1.0f;
     }
     return 1.0f;
@@ -31,11 +31,12 @@
 template <size_t MIN, size_t MAX>
 float GMD<MIN, MAX>::set(float p) {
     p = std::max(-1.0f, std::min(p, 1.0f));
-    p = p * (MAX - MIN) + MIN;
+
+    p = (abs(p) * (MAX - MIN) + MIN) * sign(p);
     p *= 0.01f;
     
     if (p < 0.0f) {
-        _pwm[0]->write(p);
+        _pwm[0]->write(-p);
         _pwm[1]->write(0.0f);
     } else {
         _pwm[0]->write(0.0f);