Skip to Content
ROS Programming: Building Powerful Robots
book

ROS Programming: Building Powerful Robots

by Anil Mahtani, Luis Sanchez, Enrique Fernandez, Aaron Martinez, Lentin Joseph
March 2018
Intermediate to advanced content levelIntermediate to advanced
1396 pages
42h 14m
English
Packt Publishing
Content preview from ROS Programming: Building Powerful Robots

Understanding ROS node APIs in Arduino

Following is a basic structure ROS Arduino node. We can see the function of each line of code:

#include <ros.h> 
 
ros::NodeHandle nh; 
 
void setup() 
{ 
  nh.initNode(); 
} 
 
void loop() 
{ 
  nh.spinOnce(); 
} 

Creating of NodeHandle in Arduino is done using the following line of code:

ros::NodeHandle nh; 

Note that Nodehandle should be declared before the setup() function, which will give a global scope to the NodeHandle instance called nh. The initialization of this node is done inside the setup() function.

  nh.initNode(); 

The Arduino setup() function will execute only once when the device starts, and note that we can only create one node from a serial device.

Inside the loop() function, we have to use the following ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Robots with ROS

Programming Robots with ROS

Morgan Quigley, Brian Gerkey, William D. Smart
Machine Learning Design Patterns

Machine Learning Design Patterns

Valliappa Lakshmanan, Sara Robinson, Michael Munn

Publisher Resources

ISBN: 9781788627436Supplemental Content