Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / HeadlightControl.cpp @ d1cc615c

History | View | Annotate | Download (3.49 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 HeadlightControl.cpp
28
 * @brief Contains headlights declarations and functions
29
 * 
30
 * Contains functions and definitions for the use of
31
 * headlights
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Ben Wasserman
35
 * @author Alex Zirbel
36
 */
37

    
38
#include "HeadlightControl.h"
39

    
40
/** ROS publisher and client declaration */
41

    
42
/**
43
 * @brief Initialize the headlights module of libscout.
44
 *
45
 * Initialize the libscout node as a publisher of set_headlights.
46
 */
47
HeadlightControl::HeadlightControl(const ros::NodeHandle& libscout_node)
48
    : node(libscout_node)
49
{
50
    set_headlights_pub = node.advertise<headlights::set_headlights>
51
        ("set_headlights", QUEUE_SIZE);
52
}
53

    
54
/**
55
 * @brief Set headlight colors as a single RGB value
56
 *
57
 * Sets the colors of the headlights as a web color value. Can selectively
58
 * select which motors to set, and which to remain at previous color.
59
 * @param color The color the headlights should be set to expressed as 0xRRGGBB
60
 * @param which A bitmask of which headlights should be set
61
 */
62
void HeadlightControl::set(int color, int which)
63
{
64
    int red, green, blue;
65

    
66
    red = (color & RED) >> REDSHIFT;
67
    green = (color & GREEN) >> GREENSHIFT;
68
    blue = (color & BLUE) >> BLUESHIFT;
69

    
70
    set_rgb(red, green, blue, which);
71
}
72

    
73
/**
74
 * @brief Set headlight colors as separate RGB values
75
 *
76
 * Sets the colors of the headlights as a web color value. Can selectively
77
 * select which motors to set, and which to remain at previous color.
78
 * @param red The red value the headlights should be set to
79
 * @param green The green value the headlights should be set to
80
 * @param blue The blue value the headlights should be set to
81
 * @param which A bitmask of which headlights should be set
82
 */
83
void HeadlightControl::set_rgb(int red, int green, int blue, int which)
84
{
85
    headlights::set_headlights msg;
86

    
87
    if(which & HL_LEFT)
88
    {
89
        msg.left_red = red;
90
        msg.left_green = green;
91
        msg.left_blue = blue;
92
    }
93
    else
94
    {
95
        msg.left_red = NO_SET;
96
        msg.left_green = NO_SET;
97
        msg.left_blue = NO_SET;
98
    }
99
    if(which & HL_RIGHT)
100
    {
101
        msg.right_red = red;
102
        msg.right_green = green;
103
        msg.right_blue = blue;
104
    }
105
    else
106
    {
107
        msg.right_red = NO_SET;
108
        msg.right_green = NO_SET;
109
        msg.right_blue = NO_SET;
110
    }
111

    
112
    /* Publishes message to set_motors topic */
113
    set_headlights_pub.publish(msg);
114
    ros::spinOnce();
115
}