Dependencies: SimpleMapSerialization serial_communication
communication.cpp@6:3b9c479c28d4, 2016-04-05 (annotated)
- Committer:
- inst
- Date:
- Tue Apr 05 09:13:13 2016 +0000
- Revision:
- 6:3b9c479c28d4
- Parent:
- 5:b1573848235e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
inst | 0:8b0edcbd3b87 | 1 | #include "communication.hpp" |
inst | 0:8b0edcbd3b87 | 2 | #include "moving_object.hpp" |
inst | 0:8b0edcbd3b87 | 3 | #include "serial_communication.hpp" |
inst | 0:8b0edcbd3b87 | 4 | |
inst | 0:8b0edcbd3b87 | 5 | #include "mbed_stl.hpp" |
inst | 0:8b0edcbd3b87 | 6 | #include "mbed.h" |
inst | 0:8b0edcbd3b87 | 7 | |
inst | 0:8b0edcbd3b87 | 8 | communication* communication::instance_ = NULL; |
inst | 2:074942a78af1 | 9 | const int communication::velocity_offset_ = 32767; |
inst | 4:24d383b68566 | 10 | const float communication::analog_stick_lower_limit_ = 0.2f; |
inst | 6:3b9c479c28d4 | 11 | //const size_t communication::direction_div_num_ = 8; |
inst | 2:074942a78af1 | 12 | |
inst | 2:074942a78af1 | 13 | communication::communication() {} |
inst | 0:8b0edcbd3b87 | 14 | |
inst | 0:8b0edcbd3b87 | 15 | node_system::moving_object::CONTROL_MODE communication::get_mode() const { |
inst | 0:8b0edcbd3b87 | 16 | return node_system::moving_object::MANUAL_MODE; |
inst | 0:8b0edcbd3b87 | 17 | } |
inst | 0:8b0edcbd3b87 | 18 | |
inst | 0:8b0edcbd3b87 | 19 | communication::vector2f communication::get_velocity() const { |
inst | 0:8b0edcbd3b87 | 20 | uint32_t iv[] = { |
inst | 2:074942a78af1 | 21 | serial_communication::instance()->get("stkLX"), |
inst | 2:074942a78af1 | 22 | serial_communication::instance()->get("stkLY") |
inst | 0:8b0edcbd3b87 | 23 | }; |
inst | 0:8b0edcbd3b87 | 24 | |
inst | 2:074942a78af1 | 25 | if ((iv[0] == velocity_offset_) && (iv[1] == velocity_offset_)) { |
inst | 0:8b0edcbd3b87 | 26 | return vector2f(); |
inst | 0:8b0edcbd3b87 | 27 | } |
inst | 0:8b0edcbd3b87 | 28 | |
inst | 0:8b0edcbd3b87 | 29 | vector2f v; |
inst | 0:8b0edcbd3b87 | 30 | |
inst | 4:24d383b68566 | 31 | // 受信データは [0, 65535] の範囲であるので [-1, 1] に変換する |
inst | 0:8b0edcbd3b87 | 32 | for (uint32_t i = 0; i < 2; ++i) { |
inst | 0:8b0edcbd3b87 | 33 | v[i] = iv[i]; |
inst | 2:074942a78af1 | 34 | v[i] -= velocity_offset_; |
inst | 2:074942a78af1 | 35 | v[i] /= velocity_offset_; |
inst | 0:8b0edcbd3b87 | 36 | } |
inst | 6:3b9c479c28d4 | 37 | /* |
inst | 6:3b9c479c28d4 | 38 | float p = 2.0f * PI / direction_div_num_; |
inst | 6:3b9c479c28d4 | 39 | float rad = atan2f(v.y(), v.x()); |
inst | 6:3b9c479c28d4 | 40 | rad += p * 0.5f; |
inst | 6:3b9c479c28d4 | 41 | rad /= p; |
inst | 6:3b9c479c28d4 | 42 | rad *= p; |
inst | 6:3b9c479c28d4 | 43 | */ |
inst | 0:8b0edcbd3b87 | 44 | if (v.length() > 1.0f) { |
inst | 6:3b9c479c28d4 | 45 | //v = v.unit(); |
inst | 2:074942a78af1 | 46 | return v.unit(); |
inst | 0:8b0edcbd3b87 | 47 | } |
inst | 0:8b0edcbd3b87 | 48 | |
inst | 6:3b9c479c28d4 | 49 | //return v.length() * vector2f(cos(rad), sin(rad)); |
inst | 6:3b9c479c28d4 | 50 | |
inst | 5:b1573848235e | 51 | /* |
inst | 4:24d383b68566 | 52 | if (v.length() < analog_stick_lower_limit_) { |
inst | 4:24d383b68566 | 53 | return vector2f(); // しきい値以下なら移動操作無しとみなす |
inst | 4:24d383b68566 | 54 | } |
inst | 5:b1573848235e | 55 | */ |
inst | 4:24d383b68566 | 56 | |
inst | 2:074942a78af1 | 57 | return v; |
inst | 0:8b0edcbd3b87 | 58 | } |
inst | 0:8b0edcbd3b87 | 59 | float communication::get_angular_velocity_rad_per_sec() const { |
inst | 0:8b0edcbd3b87 | 60 | return 0.0f; |
inst | 0:8b0edcbd3b87 | 61 | } |
inst | 0:8b0edcbd3b87 | 62 | communication::vector2f communication::get_target_position_mm() const { |
inst | 0:8b0edcbd3b87 | 63 | return vector2f(); |
inst | 0:8b0edcbd3b87 | 64 | } |
inst | 0:8b0edcbd3b87 | 65 | float communication::get_target_heading_rad() const { |
inst | 0:8b0edcbd3b87 | 66 | return 0.0f; |
inst | 0:8b0edcbd3b87 | 67 | } |