Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / scout / libscout / src / libheadlights.cpp @ 90c7a37c

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

    
38
#include "libheadlights.h"
39

    
40
/* ROS node created in libscout.cpp */
41
extern ros::NodeHandle libscout_node;
42

    
43
/** ROS publisher and client declaration */
44
ros::Publisher set_headlights_publisher;
45

    
46
/*!
47
 * \brief Initialize the headlights module of libscout.
48
 *
49
 * Initialize the libscout node as a publisher of set_headlights.
50
 */
51
void libheadlights_init()
52
{
53
  set_headlights_publisher =
54
                libscout_node.advertise<headlights::set_headlights>("libheadlights", 10);
55
}
56

    
57
/*!
58
 * \brief Set headlight colors as a single RGB value
59
 * Sets the colors of the headlights as a web color value. Can selectively
60
 * select which motors to set, and which to remain at previous color.
61
 * \param color The color the headlights should be set to expressed as 0xRRGGBB
62
 * \param which A bitmask of which headlights should be set
63
 * \return Function status
64
 */
65
int headlights_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
        return headlights_set_rgb(red, green, blue, which);
74
}
75

    
76
/*!
77
 * \brief Set headlight colors as separate RGB values
78
 * Sets the colors of the headlights as a web color value. Can selectively
79
 * select which motors to set, and which to remain at previous color.
80
 * \param red The red value the headlights should be set to
81
 * \param green The green value the headlights should be set to
82
 * \param blue The blue value the headlights should be set to
83
 * \param which A bitmask of which headlights should be set
84
 * \return Function status
85
 */
86
int headlights_set_rgb(int red, int green, int blue, int which)
87
{
88
  /** \todo Set fields of the message based on params */
89
  
90
        headlights::set_headlights msg;
91
        
92
  if(!ros::ok())
93
        {
94
    return LIB_ERROR;
95
  }
96
 
97
        if(which & HL_LEFT)
98
        {
99
                left_red = red;
100
                left_green = green;
101
                left_blue = blue;
102
        }
103
        if(which & HL_RIGHT)
104
        {
105
                right_red = red;
106
                right_green = green;
107
                right_blue = blue;
108
        }
109
        
110
  /* Publishes message to set_motors topic */
111
  set_headlights_publisher.publish(msg);
112
  ros::spinOnce();
113

    
114
  return LIB_OK;
115
}