Statistics
| Branch: | Revision:

root / scout / painter / src / painter.cpp @ 1019d31f

History | View | Annotate | Download (2.95 KB)

1
/**
2
 * Copyright (c) 2013 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 painter.cpp
28
 * @brief Contains code to control the painter and query the metal detector.
29
 *
30
 * @author Colony Project, CMU Robotics Club
31
 * @author Tom Mullins
32
 *
33
 */
34

    
35
#define QUEUE_SIZE 10
36

    
37
#include <cstdlib>
38
#include <ros/ros.h>
39
#include <messages/set_paintboard.h>
40
#include <messages/query_paintboard.h>
41
#include <messages/query_metal_detector.h>
42
#include "paint-i2c.h"
43

    
44
using namespace std;
45

    
46
int painter_value;
47

    
48
/**
49
 * @brief ROS callback to turn the paint output on or off
50
 */
51
void paint_set(const ::messages::set_paintboard::ConstPtr& msg)
52
{
53
  painter_value = msg->setting;
54
  set_servo(0, painter_value);
55
}
56

    
57
/**
58
 * @brief ROS callback to query whether the paint output is on or off
59
 */
60
bool paint_query(::messages::query_paintboard::Request &req,
61
                 ::messages::query_paintboard::Response &res)
62
{
63
  res.setting = painter_value;
64
  return true;
65
}
66

    
67
/**
68
 * @brief ROS callback to query whether there is metal detected
69
 */
70
bool metal_query(::messages::query_metal_detector::Request &req,
71
                 ::messages::query_metal_detector::Response &res)
72
{
73
  res.metal = get_input(0);
74
  return true;
75
}
76

    
77
/**
78
 * @brief Painter driver for ROS, to control the painter and metal detector
79
 *
80
 * @param argc The number of command line arguments (should be 1)
81
 * @param argv The array of command line arguments
82
 */
83
int main(int argc, char **argv)
84
{
85
    ros::init(argc, argv, "painter");
86
    ros::NodeHandle node;
87

    
88
    i2c_start();
89
    set_motor(0, 0);
90
    set_servo(0, 0);
91

    
92
    ros::Subscriber painter_sub = node.subscribe("/set_paintboard", QUEUE_SIZE,
93
        paint_set);
94
    ros::ServiceServer painter_srv = node.advertiseService("/query_paintboard",
95
        paint_query);
96
    ros::ServiceServer metal_srv = node.advertiseService("/query_metal_detector",
97
        metal_query);
98

    
99
    ROS_INFO("Painter node ready.");
100
    ros::spin();
101

    
102
    i2c_stop();
103

    
104
    return 0;
105
}