Revision 26562d0c
Adding wl_test files that were not added before
scout/libscout/src/behaviors/wl_test.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 "wl_test.h" |
|
27 |
|
|
28 |
#define DATA_SIZE 10 |
|
29 |
|
|
30 |
using namespace std; |
|
31 |
|
|
32 |
bool is_receiving = false; |
|
33 |
uint8_t highest_received = 0; |
|
34 |
|
|
35 |
void data_callback(std::vector<uint8_t> data) |
|
36 |
{ |
|
37 |
cout << "Wireless callback triggered." << endl;; |
|
38 |
for (int i = 0; i < data.size(); i++) |
|
39 |
{ |
|
40 |
if (data[i] > highest_received) |
|
41 |
{ |
|
42 |
highest_received = data[i]; |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
void wl_test::run() |
|
48 |
{ |
|
49 |
motors->set_sides(20, 50, MOTOR_ABSOLUTE); |
|
50 |
wl_receiver->register_callback(data_callback); |
|
51 |
|
|
52 |
while(ok()) |
|
53 |
{ |
|
54 |
if (!is_receiving) |
|
55 |
{ |
|
56 |
// Fill up a bogus data array |
|
57 |
vector<uint8_t> data; |
|
58 |
for (int i = 0; i < DATA_SIZE; i++) |
|
59 |
{ |
|
60 |
data.push_back(highest_received + i); |
|
61 |
} |
|
62 |
|
|
63 |
wl_sender->send(data); |
|
64 |
cout << "Sent wireless packet." << endl; |
|
65 |
is_receiving = true; |
|
66 |
} |
|
67 |
|
|
68 |
spinOnce(); |
|
69 |
loop_rate->sleep(); |
|
70 |
} |
|
71 |
} |
|
72 |
|
scout/libscout/src/behaviors/wl_test.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 _WL_TEST_H_ |
|
27 |
#define _WL_TEST_H_ |
|
28 |
|
|
29 |
#include "../Behavior.h" |
|
30 |
|
|
31 |
class wl_test : Behavior |
|
32 |
{ |
|
33 |
public: |
|
34 |
wl_test(std::string scoutname) : Behavior(scoutname, "wl_test") {}; |
|
35 |
|
|
36 |
/** Actually executes the behavior. */ |
|
37 |
void run(); |
|
38 |
}; |
|
39 |
|
|
40 |
#endif |
Also available in: Unified diff