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/TargetManager.cpp@34:85994e0501fb, 2017-03-30 (annotated)
- Committer:
- Maxime Dupuis
- Date:
- Thu Mar 30 14:38:38 2017 -0400
- Revision:
- 34:85994e0501fb
- Parent:
- 32:50b777bab5a4
- Child:
- 35:7ee45f6d6484
Remove support for TargetInfo sequence
It will only execute a single command at a time when
it is received.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Maxime Dupuis |
28:8fc53a870691 | 1 | #include "TargetManager.hpp" |
Maxime Dupuis |
28:8fc53a870691 | 2 | |
Maxime Dupuis |
30:412a779cf607 | 3 | TargetManager::TargetManager(std::vector<TargetInterface*>& targets, |
Maxime Dupuis |
30:412a779cf607 | 4 | NerfusTickerInterface& nerfus_ticker) : |
Maxime Dupuis |
30:412a779cf607 | 5 | targets(targets), |
Maxime Dupuis |
30:412a779cf607 | 6 | nerfus_ticker(nerfus_ticker) |
Maxime Dupuis |
30:412a779cf607 | 7 | { |
Maxime Dupuis |
32:50b777bab5a4 | 8 | for(int i=0; i<targets.size(); i++) |
Maxime Dupuis |
32:50b777bab5a4 | 9 | { |
Maxime Dupuis |
32:50b777bab5a4 | 10 | is_active_target.push_back(false); |
Maxime Dupuis |
32:50b777bab5a4 | 11 | } |
Maxime Dupuis |
32:50b777bab5a4 | 12 | } |
Maxime Dupuis |
30:412a779cf607 | 13 | |
Maxime Dupuis |
34:85994e0501fb | 14 | void TargetManager::execute(const TargetInfo& target_info) |
Maxime Dupuis |
32:50b777bab5a4 | 15 | { |
Maxime Dupuis |
34:85994e0501fb | 16 | TargetInterface& target = *(targets[target_info.id]); |
Maxime Dupuis |
32:50b777bab5a4 | 17 | |
Maxime Dupuis |
34:85994e0501fb | 18 | if(target_info.type == TARGET_TYPE_ALLY) |
Maxime Dupuis |
34:85994e0501fb | 19 | { |
Maxime Dupuis |
34:85994e0501fb | 20 | target.ally_command(); |
Maxime Dupuis |
34:85994e0501fb | 21 | } |
Maxime Dupuis |
34:85994e0501fb | 22 | else |
Maxime Dupuis |
34:85994e0501fb | 23 | { |
Maxime Dupuis |
34:85994e0501fb | 24 | target.enemy_command(); |
Maxime Dupuis |
34:85994e0501fb | 25 | } |
Maxime Dupuis |
32:50b777bab5a4 | 26 | |
Maxime Dupuis |
34:85994e0501fb | 27 | is_active_target[target_info.id] = true; |
Maxime Dupuis |
32:50b777bab5a4 | 28 | |
Maxime Dupuis |
34:85994e0501fb | 29 | nerfus_ticker.start(target_info.timeout_ms); |
Maxime Dupuis |
30:412a779cf607 | 30 | } |
Maxime Dupuis |
30:412a779cf607 | 31 | |
Maxime Dupuis |
28:8fc53a870691 | 32 | void TargetManager::target_hit(int target_number) |
Maxime Dupuis |
28:8fc53a870691 | 33 | { |
Maxime Dupuis |
32:50b777bab5a4 | 34 | if(is_active_target[target_number]) |
Maxime Dupuis |
32:50b777bab5a4 | 35 | { |
Maxime Dupuis |
32:50b777bab5a4 | 36 | targets[target_number]->hit(nerfus_ticker.get_time_ms()); |
Maxime Dupuis |
32:50b777bab5a4 | 37 | nerfus_ticker.stop(); |
Maxime Dupuis |
32:50b777bab5a4 | 38 | is_active_target[target_number] = false; |
Maxime Dupuis |
32:50b777bab5a4 | 39 | } |
Maxime Dupuis |
28:8fc53a870691 | 40 | } |
Maxime Dupuis |
28:8fc53a870691 | 41 | |
Maxime Dupuis |
28:8fc53a870691 | 42 | void TargetManager::target_missed(int target_number) |
Maxime Dupuis |
28:8fc53a870691 | 43 | { |
Maxime Dupuis |
32:50b777bab5a4 | 44 | if(is_active_target[target_number]) |
Maxime Dupuis |
32:50b777bab5a4 | 45 | { |
Maxime Dupuis |
32:50b777bab5a4 | 46 | targets[target_number]->timeout(nerfus_ticker.get_time_ms()); |
Maxime Dupuis |
32:50b777bab5a4 | 47 | nerfus_ticker.stop(); |
Maxime Dupuis |
32:50b777bab5a4 | 48 | is_active_target[target_number] = false; |
Maxime Dupuis |
32:50b777bab5a4 | 49 | } |
Maxime Dupuis |
28:8fc53a870691 | 50 | } |
Maxime Dupuis |
28:8fc53a870691 | 51 |