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

Creating a broadcaster

Let's test this with a simple code. Create a new file in chapter5_tutorials/src with the name tf_broadcaster.cpp, and put the following code inside it:

#include <ros/ros.h> 
#include <tf/transform_broadcaster.h> 
 
int main(int argc, char** argv){ 
  ros::init(argc, argv, "robot_tf_publisher"); 
  ros::NodeHandle n; 
 
  ros::Rate r(100); 
 
  tf::TransformBroadcaster broadcaster; 
 
  while(n.ok()){ 
    broadcaster.sendTransform( 
      tf::StampedTransform( 
        tf::Transform(tf::Quaternion(0, 0, 0, 1), tf::Vector3(0.1,          0.0, 0.2)), 
        ros::Time::now(),"base_link", "base_laser")); 
    r.sleep(); 
  } 
} 

Remember to add the following line in your CMakelist.txt file to create the new executable:

add_executable(tf_broadcaster src/tf_broadcaster.cpp) target_link_libraries(tf_broadcaster ...
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