Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / BehaviorProcess.cpp @ 676cbe0e

History | View | Annotate | Download (3.12 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 c467de4f Yuyang Guo
    if (argc < 2)
57 c239584b Priya
    {
58
        cout << "You have started this behavior in hardware mode." << endl
59
             << "To start in software mode, use: " << argv[0]
60 c467de4f Yuyang Guo
             << " <behavior#> <scoutname> " << endl;
61 c239584b Priya
    }
62
    else
63
    {
64
        // Use the provided scoutname for simulator messages
65 c467de4f Yuyang Guo
        //scoutname = argv[1];
66
        behavior_num = atoi(argv[1]);
67
        if (argc == 3) {
68
            scoutname = argv[2];
69
        }
70 c239584b Priya
71 2e8030ea Priya
        ros::init(argc, argv, scoutname + "Behavior",
72 dcf49526 Priya
            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 d140fd71 Yuyang
        // one Sensor instance per-class
79
        Sensors* sensors = new Sensors(scoutname);
80 faa11f08 Priya
        BehaviorList* list = new BehaviorList();
81
        vector<behavior_func> behavior_list = list->behavior_list;
82 c239584b Priya
        if (behavior_num < (int)behavior_list.size())
83
        {
84 faa11f08 Priya
            Behavior* b = behavior_list[behavior_num](scoutname, sensors);
85
            b->run();
86 679f4e26 Priya
            delete b;
87 c239584b Priya
        }
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 679f4e26 Priya
        delete sensors;
97 c239584b Priya
    }
98
99
    return 0;
100
}