Revision ee42f84a
add explore starter file
scout/libscout/src/test_behaviors/explore.cpp | ||
---|---|---|
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 "explore.h" |
|
27 |
|
|
28 |
using namespace std; |
|
29 |
|
|
30 |
|
|
31 |
void explore::run() |
|
32 |
{ |
|
33 |
ROS_INFO("Starting to explore region"); |
|
34 |
sonar->set_on(); |
|
35 |
sonar->set_range(0, 23); |
|
36 |
Duration sleeptime(1); |
|
37 |
while (ok()) { |
|
38 |
int *readings = sonar->get_sonar_readings(); |
|
39 |
// Look to the left. |
|
40 |
int left_distance = readings[0]; |
|
41 |
// Look to the front. |
|
42 |
int front_distance = readings[12]; |
|
43 |
// Look to the right. |
|
44 |
int right_distance = readings[24]; |
|
45 |
// Look to the back |
|
46 |
int back_distance = readings[36]; |
|
47 |
ROS_INFO("front: %d left: %d back: %d right: %d ", front_distance, left_distance, back_distance, right_distance); |
|
48 |
sleeptime.sleep(); |
|
49 |
spinOnce(); |
|
50 |
} |
|
51 |
} |
scout/libscout/src/test_behaviors/explore.h | ||
---|---|---|
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 |
#ifndef _EXPLORE_H_ |
|
27 |
#define _EXPLORE_H_ |
|
28 |
|
|
29 |
#include "../Behavior.h" |
|
30 |
#include "../Sensors.h" |
|
31 |
|
|
32 |
|
|
33 |
class explore: public Behavior |
|
34 |
{ |
|
35 |
public: |
|
36 |
explore(std::string scoutname, Sensors* sensors): |
|
37 |
Behavior(scoutname, "explore", sensors) {}; |
|
38 |
void run(); |
|
39 |
}; |
|
40 |
#endif |
|
41 |
|
Also available in: Unified diff