Dependencies:   SimpleMapSerialization serial_communication

Revision:
2:074942a78af1
Parent:
0:8b0edcbd3b87
Child:
4:24d383b68566
diff -r 0970a7b78c1d -r 074942a78af1 communication.cpp
--- a/communication.cpp	Thu Mar 31 04:43:55 2016 +0000
+++ b/communication.cpp	Sun Apr 03 06:30:39 2016 +0000
@@ -3,11 +3,12 @@
 #include "serial_communication.hpp"
 
 #include "mbed_stl.hpp"
-
-
 #include "mbed.h"
 
 communication* communication::instance_ = NULL;
+const int communication::velocity_offset_ = 32767;
+
+communication::communication() {}
 
 node_system::moving_object::CONTROL_MODE communication::get_mode() const {
     return node_system::moving_object::MANUAL_MODE;
@@ -15,14 +16,12 @@
 
 communication::vector2f communication::get_velocity() const {
     uint32_t iv[] = {
-        serial_communication::instance()->get_data("stkLX"),
-        serial_communication::instance()->get_data("stkLY")
+        serial_communication::instance()->get("stkLX"),
+        serial_communication::instance()->get("stkLY")
     };
     
     // 受信データは [0, 65535] の範囲であるので [-1, 1] に変換する
-    int offset = 32767;
-    
-    if ((iv[0] == offset) && (iv[1] == offset)) {
+    if ((iv[0] == velocity_offset_) && (iv[1] == velocity_offset_)) {
         return vector2f();
     }
     
@@ -30,8 +29,8 @@
     
     for (uint32_t i = 0; i < 2; ++i) {
         v[i] = iv[i];
-        v[i] -= offset;
-        v[i] /= offset;
+        v[i] -= velocity_offset_;
+        v[i] /= velocity_offset_;
         /*
         switch(iv[i]) {
             case 0:
@@ -51,9 +50,11 @@
     }
     
     if (v.length() > 1.0f) {
-        return ;
+        return v.unit();
     }
     
+    return v;
+    
     /*
     vector2f velocity = v.unit();
     return velocity;