Creating our base controller

Now, we are going to do something similar, that is, prepare a code to be used with a real robot with two wheels and encoders.

Create a new file in chapter5_tutorials/src with the name base_controller.cpp and put in the following code:

#include <ros/ros.h> #include <sensor_msgs/JointState.h> #include <tf/transform_broadcaster.h> #include <nav_msgs/Odometry.h> #include <iostream> using namespace std; double width_robot = 0.1; double vl = 0.0; double vr = 0.0; ros::Time last_time; double right_enc = 0.0; double left_enc = 0.0; double right_enc_old = 0.0; double left_enc_old = 0.0; double distance_left = 0.0; double distance_right = 0.0; double ticks_per_meter = 100; double x = 0.0; double y = 0.0; double th = 0.0; ...

Get ROS Programming: Building Powerful Robots now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.