Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / scout / libscout / src / test_behaviors / ApproachEmitter.cpp @ 8ae3771a

History | View | Annotate | Download (2.04 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 "ApproachEmitter.h"
27
#define BOM_W1 5
28
#define BOM_W2 10
29
#define BOM_W3 15
30
#define BOM_W4 20
31
#define BOM_W5 30
32

    
33
using namespace std;
34

    
35
ApproachEmitter::ApproachEmitter(string scoutname, Sensors* sensors) 
36
    : Behavior(scoutname, "Approach Emitter", sensors) {
37
    name = scoutname;
38
    scout_pos = new pos;
39
}
40

    
41
void ApproachEmitter::run() {
42
    BomReadings bomR;
43
    int r_weighted, l_weighted;
44
    int speed = 20;
45
    vector<uint32_t> r;
46
    vector<uint32_t> s;
47
    while (ok()) {
48
        bomR = bom->query();
49
        r = bomR.readings;
50
        s = bomR.senders;
51
        if (accumulate(r.begin(), r.end(), 0)) {
52
           l_weighted = r[0] *BOM_W1 + r[1]*BOM_W2 + r[2]*BOM_W3 + r[3]*BOM_W4 + r[4]*BOM_W5;
53
           r_weighted = r[9] *BOM_W1 + r[8]*BOM_W2 + r[7]*BOM_W3 + r[6]*BOM_W4 - r[5]*BOM_W5;
54
           motors->set_sides(min(r_weighted+speed, 100),
55
                             min(l_weighted+speed, 102),  MOTOR_PERCENT);
56
        }
57
    }
58
}