Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.05 KB)

1 d140fd71 Yuyang
2 c239584b Priya
/**
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 d140fd71 Yuyang
#include "Sensors.h"
39 dcf49526 Priya
#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 c239584b Priya
48
int main (int argc, char **argv)
49
{
50
    string scoutname = "";
51
    int behavior_num;
52 31be19a6 Priya
    string behavior_name = "";
53 c239584b Priya
54
    // Running with no arguments only supports one scout. Check in case
55
    // the user meant to specify a scout in the arguments.
56 da08d580 Alex Zirbel
    if (argc < 3)
57 c239584b Priya
    {
58
        cout << "You have started this behavior in hardware mode." << endl
59
             << "To start in software mode, use: " << argv[0]
60 26258aeb Alex
             << " <scoutname> <behavior#> " << endl;
61 c239584b Priya
    }
62
    else
63
    {
64
        // Use the provided scoutname for simulator messages
65
        scoutname = argv[1];
66
        behavior_num = atoi(argv[2]);
67
68 dcf49526 Priya
        ros::init(argc, argv, scoutname + "_behavior",
69
            ros::init_options::NoSigintHandler);
70
71
        // Initialize the signal handler after initializing rosnode.
72
        // Otherwise it will be overwritten and you will be sad.
73
        signal(SIGINT, sigint_handler);
74
75 d140fd71 Yuyang
        // one Sensor instance per-class
76
        Sensors* sensors = new Sensors(scoutname);
77 faa11f08 Priya
        BehaviorList* list = new BehaviorList();
78
        vector<behavior_func> behavior_list = list->behavior_list;
79 c239584b Priya
        if (behavior_num < (int)behavior_list.size())
80
        {
81 faa11f08 Priya
            Behavior* b = behavior_list[behavior_num](scoutname, sensors);
82
            b->run();
83 679f4e26 Priya
            delete b;
84 c239584b Priya
        }
85
        else
86
        {
87
            cout << "There is no behavior number" << behavior_num
88
              << ". There are only " << (int)behavior_list.size() << "behaviors."
89
              << endl;
90
        }
91
92
        delete list;
93 679f4e26 Priya
        delete sensors;
94 c239584b Priya
    }
95
96
    return 0;
97
}