Project

General

Profile

Revision 4069a378

ID4069a378d2c0201f91bdf72f1fc05a86a2d5177a
Parent b00761a0
Child 9b11c5b3

Added by Alex Zirbel about 12 years ago

Fixed the usb_serial node so it now compiles.

Moved the previously split send_serial_data and receive_serial_data into a single message. Renamed files to use usb_serial instead of usbserial. Updated CMakeLists to actually refer to usb_serial and not motors. Fixed bugs.

View differences:

scout/usb_serial/CMakeLists.txt
19 19
#uncomment if you have defined messages
20 20
rosbuild_genmsg()
21 21
#uncomment if you have defined services
22
rosbuild_gensrv()
22
#rosbuild_gensrv()
23 23

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

  
32
rosbuild_add_executable(motors_node src/motors.cpp)
32
rosbuild_add_executable(usb_serial_node src/usb_serial.cpp)
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/msg/serial_data.msg
1
Header header
2

  
3
# Change later based on the kind of data we actually have
4
int32 data
scout/usb_serial/src/usb_serial.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 usb_serial.cpp
28
 * @brief USB_Serial
29
 *
30
 * Implementation of functions for USB/Serial use.
31
 *
32
 * @author Colony Project, CMU Robotics Club
33
 * @author Lalitha Ganesan
34
 **/
35

  
36
#include <ros/ros.h>
37

  
38
#include "usb_serial.h"
39

  
40
/**
41
 * @defgroup usb_serial USB_Serial
42
 * @brief Functions for using the USB/Serial Ports
43
 *
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
 * @brief Sends USB/Serial data.
56
 *
57
 * Sets the state vars based on subscription to the serial_data_out topic.
58
 */
59
void send_serial_data(const usb_serial::serial_data::ConstPtr& msg)
60
{
61
    data = msg->data;
62
    //num_data_bits = msg->num_data_bits;
63
    //num_stop_bits = msg->num_stop_bits;
64
    //parity_type = msg->parity_type;
65
    //baud_rate = msg->baud_rate;
66

  
67
    // Write the data to hardware here
68
}
69

  
70
/**
71
 * @brief USB_Serial driver. This is a ROS node that controls USB/Serial 
72
 *        port data.
73
 *
74
 * This is the main function for the usb_serial node. It is run when the node
75
 * starts and initializes USB/Serial ports. It then subscribes to the
76
 * serial_data_out topic, and publishes to the serial_data_in message.
77
 */
78
int main(int argc, char **argv)
79
{
80
    /* Initialize in ROS the usb_serial driver node */
81
    ros::init(argc, argv, "usb_serial_driver");
82

  
83
    ros::NodeHandle n;
84

  
85
    /* Subscribe to the topic of outgoing serial data (which will be written
86
     * to the hardware) and if we receive any, send it via serial_data_out. */
87
    ros::Subscriber sub = n.subscribe("serial_data_out",
88
                                      QUEUE_SIZE, send_serial_data);
89

  
90
    /* Publish ingoing serial data messages back to the library. As part of
91
     * its main() function, this node reads hardware data and if a new
92
     * serial message is found, this publisher sends it inbound over ROS */
93
    ros::Publisher pub = n.advertise<usb_serial::serial_data>("serial_data_in",                                                               QUEUE_SIZE);
94

  
95
    // Initialize hardware for USB/Serial ports
96

  
97
    ROS_INFO("Ready to set USB/Serial. [Unimplemented]");
98

  
99
    // Get and publish serial data here.
100

  
101
    ros::spin();
102

  
103
    return 0;
104
}
105

  
106
/** @} */
107

  
scout/usb_serial/src/usb_serial.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 usb_serial.h
28
 * @brief Contains USB/Serial declarations and functions
29
 * 
30
 * Contains functions and definitions for the use of
31
 * USB/Serial.
32
 *
33
 * @author Lalitha Ganesan
34
 * @author Alex Zirbel
35
 **/
36

  
37
#ifndef _USB_SERIAL_H_
38
#define _USB_SERIAL_H_
39

  
40
#define QUEUE_SIZE 10
41

  
42
#include "usb_serial/serial_data.h"
43

  
44
/** @brief Initialize the motors module and driver **/
45
int main(int argc, char **argv);
46

  
47
/** @brief Responds to topic to send serial data **/
48
void send_serial_data(const usb_serial::serial_data::ConstPtr& msg);
49

  
50
#endif
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
 * @file usbserial.cpp
28
 * @brief USBSerial
29
 *
30
 * Implementation of functions for USB/Serial use.
31
 *
32
 * @author Colony Project, CMU Robotics Club
33
 * @author Lalitha Ganesan
34
 **/
35

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

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

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

  
53

  
54
/*!
55
 * \brief USBSerial driver. This is a ROS node that controls USB/Serial 
56
  * port data.
57
 *
58
 * This is the main function for the usbserial node. It is run when the node
59
 * starts and initializes USB/Serial ports. It then subscribes to the
60
 * send_serial_data topic, and publishes to the receive_serial_data message.
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 usbserial driver node */
67
  ros::init(argc, argv, "usbserial_driver");
68
  
69
  /* Subscribe to the send_serial_data topic */
70
  ros::Subscriber sub0 = n.subscribe("send_serial_data", send_serial_data);
71

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

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

  
81
  return 0;
82
}
83

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

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

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

  
36
#ifndef _USBSERIAL_H_
37
#define _USBSERIAL_H_
38

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

  
42

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

  
51
#endif

Also available in: Unified diff