Project

General

Profile

Revision cad1ab0c

IDcad1ab0c981f4f0719e919c0e4e3ef7d103835aa

Added by Ben Wasserman about 7 years ago

Created ROS skeleton for Headlights node. Currently has functionality for getting headlights set via a message and setting some variables to the message contents, but doesn't write to hardware. Also does not include code in libscout to support headlights yet.
Also, I haven't tried compiling this, but I didn't see any syntax errors. I'll compile it when I have a working ROS install.

View differences:

scout/headlights/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
# Set the build type.  Options are:
5
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
6
#  Debug          : w/ debug symbols, w/o optimization
7
#  Release        : w/o debug symbols, w/ optimization
8
#  RelWithDebInfo : w/ debug symbols, w/ optimization
9
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
10
#set(ROS_BUILD_TYPE RelWithDebInfo)
11

  
12
rosbuild_init()
13

  
14
#set the default path for built executables to the "bin" directory
15
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
16
#set the default path for built libraries to the "lib" directory
17
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
18

  
19
#uncomment if you have defined messages
20
rosbuild_genmsg()
21
#uncomment if you have defined services
22
#rosbuild_gensrv()
23

  
24
#common commands for building c++ executables and libraries
25
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
26
#target_link_libraries(${PROJECT_NAME} another_library)
27
#rosbuild_add_boost_directories()
28
#rosbuild_link_boost(${PROJECT_NAME} thread)
29
#rosbuild_add_executable(example examples/example.cpp)
30
#target_link_libraries(example ${PROJECT_NAME})
31

  
32
rosbuild_add_executable(headlights_node src/headlights.cpp)
scout/headlights/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/headlights/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b headlights is the ROS node that will control the multicolor headlights on scout
6

  
7
<!-- 
8
Headlights will contain the functions necessary for controling the headlights
9
-->
10

  
11

  
12
\section codeapi Code API
13

  
14
<!--
15
Provide links to specific auto-generated API documentation within your
16
package that is of particular interest to a reader. Doxygen will
17
document pretty much every part of your code, so do your best here to
18
point the reader to the actual API.
19

  
20
If your codebase is fairly large or has different sets of APIs, you
21
should use the doxygen 'group' tag to keep these APIs together. For
22
example, the roscpp documentation has 'libros' group.
23
-->
24

  
25

  
26
*/
scout/headlights/manifest.xml
1
<package>
2
  <description brief="headlights">
3
     motors
4
     Module to drive the headlights and provide all headlights functionality.
5
  </description>
6
  <author>Ben Wasserman</author>
7
  <license>BSD</license>
8
  <review status="unreviewed" notes=""/>
9
  <url>https://www.roboticsclub.org/redmine/projects/colonyscout/wiki</url>
10
  <depend package="roscpp"/>
11
  <depend package="std_msgs"/>
12

  
13
</package>
14

  
15

  
scout/headlights/msg/set_headlights.msg
1
Header header
2
int8 left_red
3
int8 left_green
4
int8 left_blue
5
int8 right_red
6
int8 right_green
7
int8 right_blue
scout/headlights/src/headlights.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
 * @file headlights.cpp
28
 * @brief Contains code to control the headlights.
29
 *
30
 * Implementation of functions for headlights use.
31
 *
32
 * @author Colony Project, CMU Robotics Club
33
 **/
34

  
35
#include "ros/ros.h"
36
#include "headlights.h"
37
//#include "libscout/src/constants.h"
38
#include <cstdlib>
39

  
40
/**
41
 * @defgroup headlights headlights
42
 * @brief Functions for using the headlights
43
 *
44
 * @{
45
 **/
46

  
47
/* Headlight state variables
48
 * Each color intensity is stored as a value out of the max bunary value that 
49
 * can be written to the output pins that control the LEDs.
50
 */
51
/** @todo Fix types: static */
52
struct headlight
53
{
54
	char red;
55
	char green;
56
	char blue;
57
};
58
headlight left, right;
59

  
60
/**
61
 * @brief Sets headlight colors
62
 *
63
 * Sets the headlight colors based on subscription to the set_headlights topic.
64
 *
65
 * @param msg The message from the set_headlights topic, containing colors.
66
 */
67
void headlights_set(const headlights::set_headlights::ConstPtr& msg)
68
{
69
		/* Set state variables from message */
70
		if(msg.left_red > NO_SET)
71
		{
72
			left.red = msg.left_red;
73
		}
74
		if(msg.left_green > NO_SET)
75
		{
76
			left.green = msg.left_green;
77
		}
78
		if(msg.left_blue > NO_SET)
79
		{
80
			left.blue = msg.left_blue;
81
		}
82
		if(msg.right_red > NO_SET)
83
		{
84
			right.red = msg.right_red;
85
		}
86
		if(msg.right_green > NO_SET)
87
		{
88
			right.green = msg.right_green;
89
		}
90
		if(msg.right_blue > NO_SET)
91
		{
92
			right.blue = msg.right_blue;
93
		}
94
		
95
    /* Write colors to hardware */
96
    /** @todo Add code to write colors to hardware */
97
}
98

  
99
/**
100
 * @brief headlights driver. This is a ROS node that controls headlight colors.
101
 *
102
 * This is the main function for the headlights node. It is run when the node
103
 * starts and initializes the headlights. It then subscribes to the
104
 * set_headlights topic.
105
 * 
106
 * @param argc The number of command line arguments (should be 1)
107
 * @param argv The array of command line arguments
108
 **/
109
int main(int argc, char **argv)
110
{
111
    /* Initialize in ROS the headlights driver node */
112
    ros::init(argc, argv, "headlights_driver");
113

  
114
    /* Create the nodehandle for this node*/
115
    ros::NodeHandle n;
116

  
117
    /* Subscribe to the set_headlights topic */
118
    ros::Subscriber sub0 = n.subscribe("set_headlights", QUEUE_SIZE, headlights_set);
119

  
120
    /* Initialize hardware for headlights */
121
    // Hardware init functions here
122

  
123
    ROS_INFO("Ready to set headlights.");
124
    ros::spin();
125

  
126
    return 0;
127
}
128

  
129
/** @} **/
scout/headlights/src/headlights.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
 * @file headlights.h
28
 * @brief Contains motor declarations and functions.
29
 * 
30
 * Contains functions and definitions for the use of
31
 * headlights.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 **/
35

  
36
#ifndef _HEADLIGHTS_H_
37
#define _HEADLIGHTS_H_
38

  
39
#include "headlights/set_headlights.h"
40

  
41
#define FULL 0xFF
42
#define HALF 0xC0
43
#define OFF  0x00
44
#define NO_SET -1
45

  
46
/* The number of messages in the queue. If messages arrive faster than they are
47
 * handled, old ones are thrown out */
48
#define QUEUE_SIZE 4
49

  
50

  
51
/** @brief Initialize the headlights module and driver. **/
52
int main(int argc, char **argv);
53

  
54
/** @brief Responds to topic to set motor speeds and configs. **/
55
void headlights_set(const headlights::set_headlights::ConstPtr& msg);
56

  
57
#endif

Also available in: Unified diff