NerfUS mobile node that manages a target for the Nerf gun firing range
Dependencies: LedController mbed-rtos mbed NerfUSXbee Servomotor TargetManager
Fork of NerfUS by
source/Target.cpp@22:d9df16225df3, 2017-03-11 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Sat Mar 11 12:59:26 2017 -0500
- Revision:
- 22:d9df16225df3
- Parent:
- 20:05e2c4941285
- Child:
- 23:fb47bceb61da
Fix ally command and enemy command
Both commands turn on their respective LED's and raise the servomotor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Maxime Dupuis |
18:353fb432c03c | 1 | #include "Target.hpp" |
Maxime Dupuis |
18:353fb432c03c | 2 | |
Maxime Dupuis |
18:353fb432c03c | 3 | |
Maxime Dupuis |
22:d9df16225df3 | 4 | Target::Target(ServomotorInterface& servomotor, |
Maxime Dupuis |
22:d9df16225df3 | 5 | LedControllerInterface& ally_leds, |
Maxime Dupuis |
22:d9df16225df3 | 6 | LedControllerInterface& enemy_leds, |
Maxime Dupuis |
22:d9df16225df3 | 7 | XbeeTransmitterInterface& xbee_transmitter): |
Maxime Dupuis |
18:353fb432c03c | 8 | servomotor(servomotor), |
Maxime Dupuis |
22:d9df16225df3 | 9 | ally_leds(ally_leds), |
Maxime Dupuis |
22:d9df16225df3 | 10 | enemy_leds(enemy_leds), |
Maxime Dupuis |
19:377887760869 | 11 | xbee_transmitter(xbee_transmitter) |
Maxime Dupuis |
18:353fb432c03c | 12 | { |
Maxime Dupuis |
18:353fb432c03c | 13 | } |
Maxime Dupuis |
18:353fb432c03c | 14 | |
Maxime Dupuis |
18:353fb432c03c | 15 | void Target::execute_command(Mode mode, int timeout_ms) |
Maxime Dupuis |
18:353fb432c03c | 16 | { |
Maxime Dupuis |
18:353fb432c03c | 17 | if(mode == Ally) |
Maxime Dupuis |
18:353fb432c03c | 18 | { |
Maxime Dupuis |
18:353fb432c03c | 19 | ally_command(); |
Maxime Dupuis |
18:353fb432c03c | 20 | } |
Maxime Dupuis |
18:353fb432c03c | 21 | else |
Maxime Dupuis |
18:353fb432c03c | 22 | { |
Maxime Dupuis |
18:353fb432c03c | 23 | enemy_command(); |
Maxime Dupuis |
18:353fb432c03c | 24 | } |
Maxime Dupuis |
18:353fb432c03c | 25 | } |
Maxime Dupuis |
18:353fb432c03c | 26 | |
Maxime Dupuis |
18:353fb432c03c | 27 | |
Maxime Dupuis |
18:353fb432c03c | 28 | void Target::ally_command() |
Maxime Dupuis |
18:353fb432c03c | 29 | { |
Maxime Dupuis |
18:353fb432c03c | 30 | servomotor.set_position_up(); |
Maxime Dupuis |
22:d9df16225df3 | 31 | ally_leds.turn_on(); |
Maxime Dupuis |
18:353fb432c03c | 32 | } |
Maxime Dupuis |
18:353fb432c03c | 33 | |
Maxime Dupuis |
18:353fb432c03c | 34 | void Target::enemy_command() |
Maxime Dupuis |
18:353fb432c03c | 35 | { |
Maxime Dupuis |
18:353fb432c03c | 36 | servomotor.set_position_up(); |
Maxime Dupuis |
22:d9df16225df3 | 37 | enemy_leds.turn_on(); |
Maxime Dupuis |
18:353fb432c03c | 38 | } |
Maxime Dupuis |
18:353fb432c03c | 39 | |
Maxime Dupuis |
20:05e2c4941285 | 40 | std::vector<uint8_t> Target::generate_message(uint8_t target_number, Result result, uint16_t time_taken_ms) const |
Maxime Dupuis |
19:377887760869 | 41 | { |
Maxime Dupuis |
19:377887760869 | 42 | const uint8_t target_number_and_result = (target_number << 3) + result; |
Maxime Dupuis |
20:05e2c4941285 | 43 | const uint8_t time_taken_msb = time_taken_ms >> 8; |
Maxime Dupuis |
20:05e2c4941285 | 44 | const uint8_t time_taken_lsb = (time_taken_ms << 8) >> 8; |
Maxime Dupuis |
19:377887760869 | 45 | |
Maxime Dupuis |
19:377887760869 | 46 | std::vector<uint8_t> message; |
Maxime Dupuis |
19:377887760869 | 47 | |
Maxime Dupuis |
19:377887760869 | 48 | message.push_back(target_number_and_result); |
Maxime Dupuis |
20:05e2c4941285 | 49 | message.push_back(time_taken_msb); |
Maxime Dupuis |
20:05e2c4941285 | 50 | message.push_back(time_taken_lsb); |
Maxime Dupuis |
19:377887760869 | 51 | |
Maxime Dupuis |
19:377887760869 | 52 | return message; |
Maxime Dupuis |
19:377887760869 | 53 | } |