Revision 90c7a37c

View differences:

scout/libscout/src/constants.h
1 1
/**
2
 * Copyright (c) 2007 Colony Project
2
 * Copyright (c) 2011 Colony Project
3 3
 * 
4 4
 * Permission is hereby granted, free of charge, to any person
5 5
 * obtaining a copy of this software and associated documentation
......
31 31
 * Contains constants for use in libscout
32 32
 *
33 33
 * @author Colony Project, CMU Robotics Club
34
 * @author Ben Wasserman
34 35
 **/
35 36

  
36
/* Author: Ben Wasserman
37
*/
38

  
39

  
40 37
#ifndef _CONSTANTS_H_
41 38
#define _CONSTANTS_H_
42 39

  
scout/libscout/src/libheadlights.cpp
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
}
scout/libscout/src/libheadlights.h
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.h
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 "ros/ros.h"
39
#include "constants.h"
40
#include "headlights/set_headlights.h"
41

  
42
#ifndef _LIBheadlights_H_
43
#define _LIBheadlights_H_
44

  
45
/* Defines */
46
#define WHITE		0xFFFFFF
47
#define OFF			0x000000
48
#define RED 		0xFF0000
49
#define GREEN 	0x00FF00
50
#define BLUE		0x0000FF
51
#define YELLOW	0xFFFF00
52
#define CYAN		0x00FFFF
53
#define PINK		0xFF00FF
54

  
55
#define HL_RIGHT	0x1
56
#define HL_LEFT		0x2
57
#define HL_BOTH		0x3
58

  
59
#define REDSHIFT 		16
60
#define GREENSHIFT 	 8
61
#define BLUESHIFT		 0
62

  
63
void libheadlights_init();
64
int headlights_set(int color, int which);
65
int headlights_set_rgb(int red, int green, int blue, int which);
66

  
67
#endif
68

  
scout/libscout/src/libscout.cpp
66 66
  if(modules & LIB_MOTORS){
67 67
    libmotors_init();
68 68
  }
69
	if(modules & LIB_HEADLIGHTS){
70
    libheadlights_init();
71
  }
69 72
  /** \todo Add other lib inits **/
70 73
  return 0;
71 74
}
scout/libscout/src/libscout.h
44 44
#include "ros/ros.h"
45 45
#include "constants.h"
46 46
#include "libmotors.h"
47
#include "libheadlights.h"
47 48

  
48 49
/* Libscout functions */
49 50
int init(int modules, int argc, char **argv);

Also available in: Unified diff