Dependencies: SimpleMapSerialization serial_communication
communication.cpp
- Committer:
- inst
- Date:
- 2016-04-03
- Revision:
- 2:074942a78af1
- Parent:
- 0:8b0edcbd3b87
- Child:
- 4:24d383b68566
File content as of revision 2:074942a78af1:
#include "communication.hpp" #include "moving_object.hpp" #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; } communication::vector2f communication::get_velocity() const { uint32_t iv[] = { serial_communication::instance()->get("stkLX"), serial_communication::instance()->get("stkLY") }; // 受信データは [0, 65535] の範囲であるので [-1, 1] に変換する if ((iv[0] == velocity_offset_) && (iv[1] == velocity_offset_)) { return vector2f(); } vector2f v; for (uint32_t i = 0; i < 2; ++i) { v[i] = iv[i]; v[i] -= velocity_offset_; v[i] /= velocity_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 v.unit(); } return v; /* 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; }