[Documentation] [TitleIndex] [WordIndex

Only released in EOL distros:  

serial_communication: cereal_port

Package Summary

Simple C++ serial port class for ROS.

Notice: This package is unsupported on recent versions of ROS. If you're writing a ROS driver which interfaces with serial hardware, consider using serial.

Documentation

This package was design to make life easier when developing drivers for ROS. cereal_port includes various methods for reading data from a serial port, including threaded streaming. To start using cereal_port check out the Code API.

Example

The following example shows how to use the cereal_port library in your ROS projects. This example in particular opens a serial port sends an 'R' and waits for a reply.

   1 #include <ros/ros.h>
   2 #include <cereal_port/CerealPort.h>
   3 
   4 #define REPLY_SIZE 8
   5 #define TIMEOUT 1000
   6 
   7 // This example opens the serial port and sends a request 'R' at 1Hz and waits for a reply.
   8 int main(int argc, char** argv)
   9 {
  10     ros::init(argc, argv, "example_node");
  11     ros::NodeHandle n;
  12 
  13     cereal::CerealPort device;
  14     char reply[REPLY_SIZE];
  15 
  16     // Change the next line according to your port name and baud rate
  17     try{ device.open("/dev/ttyUSB0", 9600); }
  18     catch(cereal::Exception& e)
  19     {
  20         ROS_FATAL("Failed to open the serial port!!!");
  21         ROS_BREAK();
  22     }
  23     ROS_INFO("The serial port is opened.");
  24 
  25     ros::Rate r(1);
  26     while(ros::ok())
  27     {
  28         // Send 'R' over the serial port
  29         device.write("R");
  30 
  31         // Get the reply, the last value is the timeout in ms
  32         try{ device.read(reply, REPLY_SIZE, TIMEOUT); }
  33         catch(cereal::TimeoutException& e)
  34         {
  35             ROS_ERROR("Timeout!");
  36         }
  37         ROS_INFO("Got this reply: %s", reply);
  38 
  39         ros::spinOnce();
  40         r.sleep();
  41     }
  42 }

To compile this example.cpp file you should make sure you have the serial_communication stack installed and don't forget to add cereal_port as a dependency on your package manifest.xml:

...
  <depend package="cereal_port" />

Add the following lines to your pkg CMakeList.txt in order to get your code to compile:

rosbuild_add_executable(example_node src/example.cpp)
target_link_libraries(example_node cereal_port)

Current state

Although it is obsolete and not recommended for usage in new proejcts, it might be required by legacy code and thus package.xml and CMakeLists.txt were updated in a refreshed project to meet modern requirements.

The refreshed projeect is available at https://github.com/NetBUG/cereal_port

Tutorials

Coming soon...


2024-11-23 14:32