ROS-rosserial Overview

NodeHandles and Initialization


 

rosserial official website link Overview

1. node handle

rosserial_arduino allows you to easily connect the Arduino or other serial devices to the ROS runtime graph.

All nodes are initialized and the communication node processed by a handle (NodeHandle).

In setup()creation before the function NodeHandleis very simple:

praise :: Node Handle NH;

2. Initialize

You might at Arduino setup()first call execution of the function is invoked initNode(), it will initialize ROS nodes.

* Please note that in a rosserial device can have only one node, it can only be called once initNode ().

The following example shows how to initialize the processing node and loop()complete example of the serial data within the function:

#include <ros.h>

ros::NodeHandle nh;

void setup()
{
  nh.initNode();
}

void loop()
{
  nh.spinOnce();
}

3. Custom hardware object

rosserial_client library does not actually directly NodeHandle object. Instead, it provides:

ros::NodeHandle_<HardwareType, MAX_PUBLISHERS=25, MAX_SUBSCRIBERS=25,
                 IN_BUFFER_SIZE=512, OUT_BUFFER_SIZE=512> nh;

Messages


 

1. The message generator

As with all ROS client library, rosserial receiving msg files and generates Arduino C / C ++ source code for them.

This model is:

package_name / msg / Foo.msg→package_name :: Foo

Similarly, srv files generated C / C ++ source code. This model is:

package_name / srv / Bar.srv→package_name :: Bar

Generated source files located in the directory package_name ros_lib library folder.

Thus, the code contained in the std_msgs / Stringmessage relates to:

#include <std_msgs/String.h>

And create an instance of the message:

std_msgs::String str;
Note that all the fields are initialized to the default value of the message 0 (initialization strings and variable length arrays null pointer default value). 
Note also that the array is undefined message vector objects. 
Thus, the array must be predefined, and then passed as a pointer to the message. To determine the end of the array, each array has an auto-generated integer with the same name and suffix array name _length. ( See rosserial / the Overview / Limitations )

 sensor_msgs / JointState example:

 1 //creating the message
 2 sensor_msgs::JointState jstate;
 3 
 4 //creating the arrays for the message
 5 char *name[] = {"motor_1", "motor_2"};
 6 float vel[]={0,0};
 7 float pos[]={0,0};
 8 float eff[]={0,0};
 9 
10 //assigning the arrays to the message
11 jstate.name=name;
12 jstate.position=pos;
13 jstate.velocity=vel;
14 jstate.effort=eff;
15 
16 //setting the length
17 jstate.name_length=2;
18 jstate.position_length=2;
19 jstate.velocity_length=2;
20 jstate.effort_length=2;

2. The message header (Message Header) generated

When running make in rosserial_arduino package, the header file is automatically created for many common message. If there are other messages need to create a header file, please click on this link to view .


 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/baron-an/p/12009204.html