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 NerfUS

Committer:
Maxime Dupuis
Date:
Wed Mar 08 14:05:05 2017 -0500
Revision:
20:05e2c4941285
Parent:
19:377887760869
Child:
22:d9df16225df3
Fix type in parameter name

It is not the timeout in ms but the time taken to hit the target in ms
(=timeout when missed)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Maxime Dupuis 18:353fb432c03c 1 #include "Target.hpp"
Maxime Dupuis 18:353fb432c03c 2
Maxime Dupuis 18:353fb432c03c 3
Maxime Dupuis 19:377887760869 4 Target::Target(ServomotorInterface& servomotor, LedControllerInterface& led_controller, XbeeTransmitterInterface& xbee_transmitter):
Maxime Dupuis 18:353fb432c03c 5 servomotor(servomotor),
Maxime Dupuis 19:377887760869 6 led_controller(led_controller),
Maxime Dupuis 19:377887760869 7 xbee_transmitter(xbee_transmitter)
Maxime Dupuis 18:353fb432c03c 8 {
Maxime Dupuis 18:353fb432c03c 9 }
Maxime Dupuis 18:353fb432c03c 10
Maxime Dupuis 18:353fb432c03c 11 void Target::execute_command(Mode mode, int timeout_ms)
Maxime Dupuis 18:353fb432c03c 12 {
Maxime Dupuis 18:353fb432c03c 13 if(mode == Ally)
Maxime Dupuis 18:353fb432c03c 14 {
Maxime Dupuis 18:353fb432c03c 15 ally_command();
Maxime Dupuis 18:353fb432c03c 16 }
Maxime Dupuis 18:353fb432c03c 17 else
Maxime Dupuis 18:353fb432c03c 18 {
Maxime Dupuis 18:353fb432c03c 19 enemy_command();
Maxime Dupuis 18:353fb432c03c 20 }
Maxime Dupuis 18:353fb432c03c 21 }
Maxime Dupuis 18:353fb432c03c 22
Maxime Dupuis 18:353fb432c03c 23
Maxime Dupuis 18:353fb432c03c 24 void Target::ally_command()
Maxime Dupuis 18:353fb432c03c 25 {
Maxime Dupuis 18:353fb432c03c 26 servomotor.set_position_up();
Maxime Dupuis 18:353fb432c03c 27 }
Maxime Dupuis 18:353fb432c03c 28
Maxime Dupuis 18:353fb432c03c 29 void Target::enemy_command()
Maxime Dupuis 18:353fb432c03c 30 {
Maxime Dupuis 18:353fb432c03c 31 led_controller.turn_on();
Maxime Dupuis 18:353fb432c03c 32 servomotor.set_position_up();
Maxime Dupuis 18:353fb432c03c 33 }
Maxime Dupuis 18:353fb432c03c 34
Maxime Dupuis 20:05e2c4941285 35 std::vector<uint8_t> Target::generate_message(uint8_t target_number, Result result, uint16_t time_taken_ms) const
Maxime Dupuis 19:377887760869 36 {
Maxime Dupuis 19:377887760869 37 const uint8_t target_number_and_result = (target_number << 3) + result;
Maxime Dupuis 20:05e2c4941285 38 const uint8_t time_taken_msb = time_taken_ms >> 8;
Maxime Dupuis 20:05e2c4941285 39 const uint8_t time_taken_lsb = (time_taken_ms << 8) >> 8;
Maxime Dupuis 19:377887760869 40
Maxime Dupuis 19:377887760869 41 std::vector<uint8_t> message;
Maxime Dupuis 19:377887760869 42
Maxime Dupuis 19:377887760869 43 message.push_back(target_number_and_result);
Maxime Dupuis 20:05e2c4941285 44 message.push_back(time_taken_msb);
Maxime Dupuis 20:05e2c4941285 45 message.push_back(time_taken_lsb);
Maxime Dupuis 19:377887760869 46
Maxime Dupuis 19:377887760869 47 return message;
Maxime Dupuis 19:377887760869 48 }