Statistics
| Branch: | Revision:

scoutos / scout / libscout / src / PaintBoardControl.cpp @ 34a60a3b

History | View | Annotate | Download (3.11 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
/**
27
 * @file PaintBoardControl.cpp
28
 * @brief Contains paintboard declarations and functions
29
 * 
30
 * Contains functions and definitions for the use of
31
 * paintboards
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Priyanka Deo
35
 **/
36

    
37
#include "PaintBoardControl.h"
38

    
39
using namespace std;
40

    
41
/**
42
 * @brief Initialize the paintboards module of libscout.
43
 *
44
 * Initialize the libscout node as a publisher of set_paintboards and a client of
45
 * query_paintboards.
46
 */
47
PaintBoardControl::PaintBoardControl(const ros::NodeHandle& libscout_node,
48
                           string scoutname)
49
    : node(libscout_node)
50
{
51
    set_paintboard_pub =
52
        node.advertise< ::messages::set_paintboard>(scoutname + "/set_paintboard",
53
                                           QUEUE_SIZE, true);
54
    query_paintboard_client =
55
        node.serviceClient< ::messages::query_paintboard>(scoutname + "/query_paintboard");
56
}
57

    
58
PaintBoardControl::~PaintBoardControl()
59
{
60
  set(STOP_PAINT);
61
}
62

    
63
/**
64
 * @brief Sets all the speeds according to the specificiation of which paintboard
65
 *        to set.
66
 *
67
 * @param which A bitmask of which paintboard need to be set.
68
 * @param speed The value to set the paintboard to.
69
 * @param units The units the speed is expressed in.
70
 * @return Function status
71
 */
72
void PaintBoardControl::set(int paintboard_setting)
73
{
74
    ::messages::set_paintboard msg;
75
    
76
    msg.setting = paintboard_setting;
77

    
78
    set_paintboard_pub.publish(msg);
79
    ros::spinOnce();
80
}
81

    
82
/**
83
 * @brief Query the current speeds of the paintboard
84
 *
85
 * Sends a request to the query_paintboard service which will reply with the
86
 *  current setting of the paintboard.
87
 *
88
 * @param which A bitmask that will specify which motor speed should be
89
 *  returned
90
 * @return The speed of the selected motor
91
 */
92
int PaintBoardControl::query()
93
{
94
    ::messages::query_paintboard srv;
95
    if(query_paintboard_client.call(srv))
96
    {
97
      return srv.response.setting;
98
    }
99
    else
100
    {
101
        ROS_FATAL("Failed to call service query_paintboard");
102
    }
103

    
104
    return -1;
105
}