scoutos / scout / libscout / src / test_behaviors / ParkScout.cpp @ 7b94db2c
History | View | Annotate | Download (2.75 KB)
1 |
/**
|
---|---|
2 |
* Copyright (c) 2011 Colony Project
|
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person
|
5 |
* obtaining a copy of this software and associated documentation
|
6 |
* files (the "Software"), to deal in the Software without
|
7 |
* restriction, including without limitation the rights to use,
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
* copies of the Software, and to permit persons to whom the
|
10 |
* Software is furnished to do so, subject to the following
|
11 |
* conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be
|
14 |
* included in all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23 |
* OTHER DEALINGS IN THE SOFTWARE.
|
24 |
*/
|
25 |
|
26 |
#include "ParkScout.h" |
27 |
#define LEFT_EMITTER_ID 110 |
28 |
#define RIGHT_EMITTER_ID 111 |
29 |
|
30 |
|
31 |
#define LEFT 0 |
32 |
#define RIGHT 1 |
33 |
|
34 |
using namespace std; |
35 |
|
36 |
ParkScout::ParkScout(string scoutname, Sensors* sensors)
|
37 |
: Behavior(scoutname, "Park Scout", sensors) {
|
38 |
name = scoutname; |
39 |
scout_pos = new pos;
|
40 |
} |
41 |
|
42 |
void ParkScout::run() {
|
43 |
|
44 |
/* update_readings();
|
45 |
start_side = get_side(readings);
|
46 |
|
47 |
while ((start_side == LEFT && checkBOM(3, RIGHT_EMITTER_ID)) ||
|
48 |
(start_side == RIGHT && checkBOM(6, RIGHT_EMITTER_ID))) {
|
49 |
motors->set_sides(100, 100, MOTOR_PERCENT);
|
50 |
bomR = bom->query();
|
51 |
update_readings();
|
52 |
}
|
53 |
|
54 |
motors->set_sides(0, 0, MOTOR_PERCENT);
|
55 |
|
56 |
|
57 |
while(ok) {
|
58 |
reverse_park();
|
59 |
} */
|
60 |
|
61 |
|
62 |
} |
63 |
/*
|
64 |
void reverse_park() {
|
65 |
if(checkBOM(5, LEFT_EMITTER_ID) ||
|
66 |
checkBOM(4, RIGHT_EMITTER_ID)) { //move forward
|
67 |
motors->set_sides(10, 10, MOTOR_PERCENT);
|
68 |
}
|
69 |
else if(checkBOM(4, LEFT_EMITTER_ID) &&
|
70 |
checkBOM(5, RIGHT_EMITTER_ID)) {
|
71 |
motors->set_sides(-20, -20, MOTOR_PERCENT);
|
72 |
}
|
73 |
else {
|
74 |
if (start_side == RIGHT) { //reverseright
|
75 |
motors->set_sides(100, 20, MOTOR_PERCENT);
|
76 |
}
|
77 |
else { //reverseleft
|
78 |
motors->set_sides(20, 100, MOTOR_PERCENT);
|
79 |
|
80 |
}
|
81 |
}
|
82 |
|
83 |
}
|
84 |
|
85 |
int get_side() {
|
86 |
|
87 |
return RIGHT;
|
88 |
}
|
89 |
|
90 |
bool checkBOM(int bNum, int ID) {
|
91 |
if(readings[bNum] == true) {
|
92 |
ROS_INFO("Emitter ID: %d", senders[bNum]);
|
93 |
return senders[bNum] == ID;
|
94 |
}
|
95 |
return false;
|
96 |
|
97 |
}
|
98 |
|
99 |
void update_readings() {
|
100 |
BomReadings bomR = bom->query();
|
101 |
readings = bomR.readings;
|
102 |
senders = bomR.senders;
|
103 |
|
104 |
}*/
|