tarou yamada / communication

Dependencies:   SimpleMapSerialization serial_communication

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Thu Mar 31 04:43:01 2016 +0000
Child:
1:0970a7b78c1d
Commit message:

Changed in this revision

SimpleMapSerialization.lib Show annotated file Show diff for this revision Revisions of this file
communication.cpp Show annotated file Show diff for this revision Revisions of this file
communication.hpp Show annotated file Show diff for this revision Revisions of this file
serial_communication.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleMapSerialization.lib	Thu Mar 31 04:43:01 2016 +0000
@@ -0,0 +1,1 @@
+SimpleMapSerialization#f398994b70f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/communication.cpp	Thu Mar 31 04:43:01 2016 +0000
@@ -0,0 +1,70 @@
+#include "communication.hpp"
+#include "moving_object.hpp"
+#include "serial_communication.hpp"
+
+#include "mbed_stl.hpp"
+
+
+#include "mbed.h"
+
+communication* communication::instance_ = NULL;
+
+node_system::moving_object::CONTROL_MODE communication::get_mode() const {
+    return node_system::moving_object::MANUAL_MODE;
+}
+
+communication::vector2f communication::get_velocity() const {
+    uint32_t iv[] = {
+        serial_communication::instance()->get_data("stkLX"),
+        serial_communication::instance()->get_data("stkLY")
+    };
+    
+    // 受信データは [0, 65535] の範囲であるので [-1, 1] に変換する
+    int offset = 32767;
+    
+    if ((iv[0] == offset) && (iv[1] == offset)) {
+        return vector2f();
+    }
+    
+    vector2f v;
+    
+    for (uint32_t i = 0; i < 2; ++i) {
+        v[i] = iv[i];
+        v[i] -= offset;
+        v[i] /= offset;
+        /*
+        switch(iv[i]) {
+            case 0:
+                v[i] = 0.0f;
+                break;
+                
+            case 1:
+                v[i] = 1.0f;
+                
+                break;
+                
+            case 2:
+                v[i] = -1.0f;
+                break;
+        }
+        */
+    }
+    
+    if (v.length() > 1.0f) {
+        return ;
+    }
+    
+    /*
+    vector2f velocity = v.unit();
+    return velocity;
+    */
+}
+float communication::get_angular_velocity_rad_per_sec() const {
+    return 0.0f;
+}
+communication::vector2f communication::get_target_position_mm() const {
+    return vector2f();
+}
+float communication::get_target_heading_rad() const {
+    return 0.0f;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/communication.hpp	Thu Mar 31 04:43:01 2016 +0000
@@ -0,0 +1,36 @@
+#ifndef INCLUDED_NODE_SYSTEM_COMMUNICATION_H
+#define INCLUDED_NODE_SYSTEM_COMMUNICATION_H
+
+#include "moving_object.hpp"
+#include "mbed_stl.hpp"
+
+class communication {
+public:
+    typedef mbed_stl::linear_algebra::vector2f vector2f;
+
+    static communication* instance() {
+        if (instance_ == NULL) {
+            instance_ = new communication;
+        }
+        return  instance_;
+    }
+    static void destory() {
+        delete instance_;
+    }
+    node_system::moving_object::CONTROL_MODE get_mode() const;
+    vector2f get_velocity() const;
+    float get_angular_velocity_rad_per_sec() const;
+    vector2f get_target_position_mm() const;
+    float get_target_heading_rad() const;
+    
+private:
+    communication() {}
+    ~communication() {}
+    // singletonにつき禁止のため以下の二つの実装は無し
+    void operator=(const communication& s);
+    communication(const communication& s);
+    
+    static communication* instance_;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serial_communication.lib	Thu Mar 31 04:43:01 2016 +0000
@@ -0,0 +1,1 @@
+serial_communication#964bbeb0a1d3