Project

General

Profile

Revision 14241f84

ID14241f8443aba850e38075d982a03fe2d2f8091a

Added by Lalitha Ganesan over 12 years ago

Added Encoders and USB/Serial ROS nodes. Some of the functions in the
src/<node>.cpp files are not fully functional yet.

View differences:

scout/encoders/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(motors_node src/motors.cpp)
scout/encoders/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/encoders/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b encoders is the ros node that will provide all encoder functionality and control.
6

  
7
<!-- 
8
Encoders will contain the functions necessary for reading encoder data.
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/encoders/manifest.xml
1
<package>
2
  <description brief="encoders">
3
     encoders
4
     Module to provide all encoder control functionality.
5
  </description>
6
  <author>Lalitha</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/encoders/msg/encoder_state.msg
1
Header header
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
6
int8 units
scout/encoders/msg/encoder_state.txt
1
Header header
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
6
int8 units
scout/encoders/src/encoders.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 encoders.cpp
29
 * @brief Encoders
30
 *
31
 * Implementation of functions for encoder use.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Benjamin Wasserman
35
 **/
36

  
37
#include "ros/ros.h"
38
#include "encoders.h"
39
//#include "libscout/src/constants.h"
40
#include <cstdlib>
41

  
42
/**
43
 * @defgroup encoders Encoders
44
 * @brief Functions for using the encoders
45
 *
46
 **/
47

  
48
/* Encoder state variables */
49
/** \todo Fix types: static */
50
int encoder_fl; /**< The current state of the front left encoder. */
51
int encoder_fr; /**< The current state of the front right encoder. */
52
int encoder_bl; /**< The current state of the back left encoder. */
53
int encoder_br; /**< The current state of the back right encoder. */
54

  
55
/*!
56
 * \brief Encoders driver. This is a ROS node that controls encoders.
57
 *
58
 * This is the main function for the encoders node. It is run when the node
59
 * starts and initializes the encoders. It then publishes to the
60
 * encoder_state topic and advertises the query_encoders service.
61
 * 
62
 * \param argc The number of command line arguments (should be 1)
63
 * \param argv The array of command line arguments
64
 **/
65
int main(int argc, char **argv){
66
  /* Initialize in ROS the encoders driver node */
67
  ros::init(argc, argv, "encoders_driver");
68
  
69
  /* Advertise that this serves the query_encoders service */
70
  ros::NodeHandle n;
71
  ros::ServiceServer service = n.advertiseService("query_encoders", encoders_query);
72

  
73
  /* Subscribe to the encoder_state topic */
74
  ros::Subscriber sub0 = n.subscribe("encoder_state", 4, encoder_state);
75

  
76
  /* Initialize hardware for motors */
77
  // Hardware init functions here
78

  
79
  ROS_INFO("Ready to set encoders.");
80
  ros::spin();
81

  
82
  return 0;
83
}
84

  
85
/*!
86
 * \brief Gets encoder state
87
 *
88
 * Sets the encoder state based on subscription to the encoder_state topic.
89
 *
90
 * \param msg The message from the encoder_state topic, containing encoder
91
 * configuration settings.
92
 */
93
void encoder_state(const encoders::encoder_state::ConstPtr& msg){ 
94
  encoder_fl = msg->fl_encoder;
95
  encoder_fr = msg->fr_encoder;
96
  encoder_bl = msg->bl_encoder;
97
  encoder_br = msg->br_encoder;
98
}
99

  
100
/*!
101
 * \brief Outputs current encoder data
102
 *
103
 * Serves the service query_encoders by responding to service requests with the
104
 * encoder values.
105
 * \param req The request. Should be empty.
106
 * \param res The response. The fields will be filled with values.
107
 */
108
bool encoders_query(encoders::query_encoders::Request &req,
109
    encoders::query_encoders::Response &res){
110
  
111
  res.fl_encoder = encoder_fl;
112
  res.fr_encoder = encoder_fr;
113
  res.bl_encoder = encoder_bl;
114
  res.br_encoder = encoder_br;
115

  
116
  ROS_DEBUG("Encoder values queried");
117
  return true;
118
}
119

  
scout/encoders/src/encoders.h
1
/**
2
 *Copyright (c) 2007 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 encoders.h
29
 * @brief Contains encoder declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * encoders.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Authors: Ben Wasserman, Lalitha Ganesan
38
*/
39

  
40
#ifndef _ENCODERS_H_
41
#define _ENCODERS_H_
42

  
43
#include "encoders/query_encoders.h"
44
#include "encoders/encoder_state.h"
45

  
46

  
47
/** @brief Initialize the encoders module and driver **/
48
int main(int argc, char **argv);
49
/** @brief Responds to topic to get encoder state **/
50
void encoder_state(const encoders::encoder_state::ConstPtr& msg);
51
/** @brief Responds to service to query encoder data **/
52
bool encoders_query(encoders::query_encoders::Request &req,
53
    encoders::query_encoders::Response &res);
54

  
55
#endif
scout/encoders/srv/query_encoders.srv
1
---
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
scout/usb_serial/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(motors_node src/motors.cpp)
scout/usb_serial/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/usb_serial/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b usbserial is the ros node that will provide all IO over USB/Serial functionality and control.
6

  
7
<!-- 
8
USBserial will contain the functions neceessary for providing USB/Serial IO capability.
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/usb_serial/manifest.xml
1
<package>
2
  <description brief="usbserial">
3
     usbserial
4
     Module for USB/Serial that provide all USB/Serial control functionality.
5
  </description>
6
  <author>Lalitha</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/usb_serial/msg/receive_serial_data.msg
1
Header header
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
6
int8 units
scout/usb_serial/msg/send_serial_data.msg
1
Header header
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
6
int8 units
scout/usb_serial/src/usbserial.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 usbserial.cpp
29
 * @brief USBSerial
30
 *
31
 * Implementation of functions for USB/Serial use.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Lalitha Ganesan
35
 **/
36

  
37
#include "ros/ros.h"
38
#include "usbserial.h"
39
#include <cstdlib>
40

  
41
/**
42
 * @defgroup usbserial USBSerial
43
 * @brief Functions for using the USB/Serial Ports
44
 *
45
 **/
46

  
47
/* USB/Serial state variables */
48
int data; /**< The USB serial data received. */
49
int num_data_bits; /**< The number of bits that store data. */
50
int num_stop_bits; /**< The number of bits that indicate the end of data. */
51
int parity_type; /**< The parity type of the data being sent over. */
52
int baud_rate; /**< The baud rate of the USB/Serial (bits/sec). */
53

  
54

  
55
/*!
56
 * \brief USBSerial driver. This is a ROS node that controls USB/Serial 
57
  * port data.
58
 *
59
 * This is the main function for the usbserial node. It is run when the node
60
 * starts and initializes USB/Serial ports. It then subscribes to the
61
 * send_serial_data topic, and publishes to the receive_serial_data message.
62
 * 
63
 * \param argc The number of command line arguments (should be 1)
64
 * \param argv The array of command line arguments
65
 **/
66
int main(int argc, char **argv){
67
  /* Initialize in ROS the usbserial driver node */
68
  ros::init(argc, argv, "usbserial_driver");
69
  
70
  /* Subscribe to the send_serial_data topic */
71
  ros::Subscriber sub0 = n.subscribe("send_serial_data", send_serial_data);
72

  
73
  /* Publish to the receive_serial_data topic */
74
  ros::Publisher pub0 = n.publish("receive_serial_data", receive_serial_data);
75
  
76
  /* Initialize hardware for USB/Serial ports */
77
  // Hardware init functions here
78

  
79
  ROS_INFO("Ready to set USB/Serial.");
80
  ros::spin();
81

  
82
  return 0;
83
}
84

  
85
/*!
86
 * \brief Sends USB/Serial data.
87
 *
88
 * Sets the state vars based on subscription to the send_serial_data topic.
89
 *
90
 * \param msg The message from the send_serial_data topic, containing info about 
91
 * how data are being sent.
92
 */
93
void send_serial_data(const usbserial::send_serial_data::ConstPtr& msg){
94
  
95
  data = msg->data;
96
  num_data_bits = msg->num_data_bits;
97
  num_stop_bits = msg->num_stop_bits;
98
  parity_type = msg->parity_type;
99
  baud_rate = msg->baud_rate;
100
}
101

  
102
/*!
103
 * \brief Handles received USB/Serial data.
104
 *
105
 * Serves the service receive_serial_data by responding to service requests with the
106
 * usb/serial data.
107
 * \param req The request. Should be empty.
108
 * \param res The response. The fields will be filled with values.
109
 */
110
bool receive_serial_data(usbserial::receive_serial_data::Request &req,
111
    usbserial::receive_serial_data::Response &res){
112
  
113
  res.data = data;
114
  res.num_data_bits = num_data_bits;
115
  res.num_stop_bits = num_stop_bits;
116
  res.parity_type = parity_type;
117
  res.baud_rate = baud_rate;
118
  
119
  return true;
120
}
121

  
scout/usb_serial/src/usbserial.h
1
/**
2
 *Copyright (c) 2007 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 usbserial.h
29
 * @brief Contains USB/Serial declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * USB/Serial.
33
 *
34
 * @author Lalitha Ganesan
35
 **/
36

  
37
#ifndef _USBSERIAL_H_
38
#define _USBSERIAL_H_
39

  
40
#include "usbserial/send_serial_data.h"
41
#include "usbserial/receive_serial_data.h"
42

  
43

  
44
/** @brief Initialize the motors module and driver **/
45
int main(int argc, char **argv);
46
/** @brief Responds to topic to send serial data **/
47
void send_serial_data(const usbserial::send_serial_data::ConstPtr& msg);
48
/** @brief Responds to service to receive serial data **/
49
bool receive_serial_data(usbserial::receive_serial_data::Request &req,
50
    usbserial::receive_serial_data::Response &res);
51

  
52
#endif

Also available in: Unified diff