root / scout / libscout / src / HeadlightControl.cpp @ d2acabf3
History | View | Annotate | Download (3.58 KB)
1 | a8480867 | Alex Zirbel | /**
|
---|---|---|---|
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 | cc558a8d | Alex Zirbel | using namespace std; |
41 | |||
42 | a8480867 | Alex Zirbel | /** ROS publisher and client declaration */
|
43 | |||
44 | /**
|
||
45 | * @brief Initialize the headlights module of libscout.
|
||
46 | *
|
||
47 | * Initialize the libscout node as a publisher of set_headlights.
|
||
48 | */
|
||
49 | cc558a8d | Alex Zirbel | HeadlightControl::HeadlightControl(const ros::NodeHandle& libscout_node,
|
50 | string scoutname)
|
||
51 | a8480867 | Alex Zirbel | : node(libscout_node) |
52 | { |
||
53 | set_headlights_pub = node.advertise<headlights::set_headlights> |
||
54 | cfdb3afa | Alex | (scoutname + "/set_headlights", QUEUE_SIZE, true); |
55 | a8480867 | Alex Zirbel | } |
56 | |||
57 | /**
|
||
58 | * @brief Set headlight colors as a single RGB value
|
||
59 | *
|
||
60 | * Sets the colors of the headlights as a web color value. Can selectively
|
||
61 | * select which motors to set, and which to remain at previous color.
|
||
62 | * @param color The color the headlights should be set to expressed as 0xRRGGBB
|
||
63 | * @param which A bitmask of which headlights should be set
|
||
64 | */
|
||
65 | void HeadlightControl::set(int color, int which) |
||
66 | { |
||
67 | int red, green, blue;
|
||
68 | |||
69 | red = (color & RED) >> REDSHIFT; |
||
70 | green = (color & GREEN) >> GREENSHIFT; |
||
71 | blue = (color & BLUE) >> BLUESHIFT; |
||
72 | |||
73 | set_rgb(red, green, blue, which); |
||
74 | } |
||
75 | |||
76 | /**
|
||
77 | * @brief Set headlight colors as separate RGB values
|
||
78 | *
|
||
79 | * Sets the colors of the headlights as a web color value. Can selectively
|
||
80 | * select which motors to set, and which to remain at previous color.
|
||
81 | * @param red The red value the headlights should be set to
|
||
82 | * @param green The green value the headlights should be set to
|
||
83 | * @param blue The blue value the headlights should be set to
|
||
84 | * @param which A bitmask of which headlights should be set
|
||
85 | */
|
||
86 | void HeadlightControl::set_rgb(int red, int green, int blue, int which) |
||
87 | { |
||
88 | headlights::set_headlights msg; |
||
89 | |||
90 | if(which & HL_LEFT)
|
||
91 | { |
||
92 | msg.left_red = red; |
||
93 | msg.left_green = green; |
||
94 | msg.left_blue = blue; |
||
95 | } |
||
96 | else
|
||
97 | { |
||
98 | msg.left_red = NO_SET; |
||
99 | msg.left_green = NO_SET; |
||
100 | msg.left_blue = NO_SET; |
||
101 | } |
||
102 | if(which & HL_RIGHT)
|
||
103 | { |
||
104 | msg.right_red = red; |
||
105 | msg.right_green = green; |
||
106 | msg.right_blue = blue; |
||
107 | } |
||
108 | else
|
||
109 | { |
||
110 | msg.right_red = NO_SET; |
||
111 | msg.right_green = NO_SET; |
||
112 | msg.right_blue = NO_SET; |
||
113 | } |
||
114 | |||
115 | /* Publishes message to set_motors topic */
|
||
116 | set_headlights_pub.publish(msg); |
||
117 | ros::spinOnce(); |
||
118 | } |