Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / BehaviorProcess.cpp @ c9638ad1

History | View | Annotate | Download (3.12 KB)

1

    
2
/**
3
 * Copyright (c) 2011 Colony Project
4
 * 
5
 * Permission is hereby granted, free of charge, to any person
6
 * obtaining a copy of this software and associated documentation
7
 * files (the "Software"), to deal in the Software without
8
 * restriction, including without limitation the rights to use,
9
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following
12
 * conditions:
13
 * 
14
 * The above copyright notice and this permission notice shall be
15
 * included in all copies or substantial portions of the Software.
16
 * 
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
 * OTHER DEALINGS IN THE SOFTWARE.
25
 */
26

    
27
/**
28
 * @file Behavior.cpp
29
 * @brief A wrapper that executes PriyaBehavior as an executable.
30
 *
31
 * Should be auto-generated in the future.
32
 * 
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Alex Zirbel
35
 */
36

    
37
#include "BehaviorProcess.h"
38
#include "Sensors.h"
39
#include <assert.h>
40
#include <signal.h>
41

    
42
// Make the behavior's ok() function return false.
43
void sigint_handler(int sig)
44
{
45
  Behavior::keep_running = false;  
46
}
47

    
48
int main (int argc, char **argv)
49
{
50
    string scoutname = "";
51
    int behavior_num;
52
    string behavior_name = "";
53

    
54
    // Running with no arguments only supports one scout. Check in case
55
    // the user meant to specify a scout in the arguments.
56
    if (argc < 2)
57
    {
58
        cout << "You have started this behavior in hardware mode." << endl
59
             << "To start in software mode, use: " << argv[0]
60
             << " <behavior#> <scoutname> " << endl;
61
    }
62
    else
63
    {
64
        // Use the provided scoutname for simulator messages
65
        //scoutname = argv[1];
66
        behavior_num = atoi(argv[1]);
67
        if (argc == 3) {
68
            scoutname = argv[2];
69
        }
70

    
71
        ros::init(argc, argv, scoutname + "Behavior",
72
            ros::init_options::NoSigintHandler);
73

    
74
        // Initialize the signal handler after initializing rosnode.
75
        // Otherwise it will be overwritten and you will be sad.
76
        signal(SIGINT, sigint_handler);
77

    
78
        // one Sensor instance per-class
79
        Sensors* sensors = new Sensors(scoutname);
80
        BehaviorList* list = new BehaviorList();
81
        vector<behavior_func> behavior_list = list->behavior_list;
82
        if (behavior_num < (int)behavior_list.size())
83
        {
84
            Behavior* b = behavior_list[behavior_num](scoutname, sensors);
85
            b->run();
86
            delete b;
87
        }
88
        else
89
        {
90
            cout << "There is no behavior number" << behavior_num
91
              << ". There are only " << (int)behavior_list.size() << "behaviors."
92
              << endl;
93
        }
94

    
95
        delete list;
96
        delete sensors;
97
    }
98

    
99
    return 0;
100
}