Dependencies: SimpleMapSerialization serial_communication
communication.cpp@5:b1573848235e, 2016-04-04 (annotated)
- Committer:
- inst
- Date:
- Mon Apr 04 09:24:51 2016 +0000
- Revision:
- 5:b1573848235e
- Parent:
- 4:24d383b68566
- Child:
- 6:3b9c479c28d4
- Child:
- 7:6c4b22a43eb3
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 | 2:074942a78af1 | 11 | |
inst | 2:074942a78af1 | 12 | communication::communication() {} |
inst | 0:8b0edcbd3b87 | 13 | |
inst | 0:8b0edcbd3b87 | 14 | node_system::moving_object::CONTROL_MODE communication::get_mode() const { |
inst | 0:8b0edcbd3b87 | 15 | return node_system::moving_object::MANUAL_MODE; |
inst | 0:8b0edcbd3b87 | 16 | } |
inst | 0:8b0edcbd3b87 | 17 | |
inst | 0:8b0edcbd3b87 | 18 | communication::vector2f communication::get_velocity() const { |
inst | 0:8b0edcbd3b87 | 19 | uint32_t iv[] = { |
inst | 2:074942a78af1 | 20 | serial_communication::instance()->get("stkLX"), |
inst | 2:074942a78af1 | 21 | serial_communication::instance()->get("stkLY") |
inst | 0:8b0edcbd3b87 | 22 | }; |
inst | 0:8b0edcbd3b87 | 23 | |
inst | 2:074942a78af1 | 24 | if ((iv[0] == velocity_offset_) && (iv[1] == velocity_offset_)) { |
inst | 0:8b0edcbd3b87 | 25 | return vector2f(); |
inst | 0:8b0edcbd3b87 | 26 | } |
inst | 0:8b0edcbd3b87 | 27 | |
inst | 0:8b0edcbd3b87 | 28 | vector2f v; |
inst | 0:8b0edcbd3b87 | 29 | |
inst | 4:24d383b68566 | 30 | // 受信データは [0, 65535] の範囲であるので [-1, 1] に変換する |
inst | 0:8b0edcbd3b87 | 31 | for (uint32_t i = 0; i < 2; ++i) { |
inst | 0:8b0edcbd3b87 | 32 | v[i] = iv[i]; |
inst | 2:074942a78af1 | 33 | v[i] -= velocity_offset_; |
inst | 2:074942a78af1 | 34 | v[i] /= velocity_offset_; |
inst | 0:8b0edcbd3b87 | 35 | } |
inst | 0:8b0edcbd3b87 | 36 | |
inst | 0:8b0edcbd3b87 | 37 | if (v.length() > 1.0f) { |
inst | 2:074942a78af1 | 38 | return v.unit(); |
inst | 0:8b0edcbd3b87 | 39 | } |
inst | 0:8b0edcbd3b87 | 40 | |
inst | 5:b1573848235e | 41 | /* |
inst | 4:24d383b68566 | 42 | if (v.length() < analog_stick_lower_limit_) { |
inst | 4:24d383b68566 | 43 | return vector2f(); // しきい値以下なら移動操作無しとみなす |
inst | 4:24d383b68566 | 44 | } |
inst | 5:b1573848235e | 45 | */ |
inst | 4:24d383b68566 | 46 | |
inst | 2:074942a78af1 | 47 | return v; |
inst | 2:074942a78af1 | 48 | |
inst | 0:8b0edcbd3b87 | 49 | /* |
inst | 0:8b0edcbd3b87 | 50 | vector2f velocity = v.unit(); |
inst | 0:8b0edcbd3b87 | 51 | return velocity; |
inst | 0:8b0edcbd3b87 | 52 | */ |
inst | 0:8b0edcbd3b87 | 53 | } |
inst | 0:8b0edcbd3b87 | 54 | float communication::get_angular_velocity_rad_per_sec() const { |
inst | 0:8b0edcbd3b87 | 55 | return 0.0f; |
inst | 0:8b0edcbd3b87 | 56 | } |
inst | 0:8b0edcbd3b87 | 57 | communication::vector2f communication::get_target_position_mm() const { |
inst | 0:8b0edcbd3b87 | 58 | return vector2f(); |
inst | 0:8b0edcbd3b87 | 59 | } |
inst | 0:8b0edcbd3b87 | 60 | float communication::get_target_heading_rad() const { |
inst | 0:8b0edcbd3b87 | 61 | return 0.0f; |
inst | 0:8b0edcbd3b87 | 62 | } |