Programming and configuring the DIY robot
We are now ready to program our robot. The first thing to do to enable our robot to successfully navigate the environment autonomously is to allow access to its motors. We will develop a cpp node in the package motor_ctrl. In this node, we will use the pigpio library, which allows the control of the Raspberry Pi without the necessity of superuser privileges. From this code, based on the geometry_msgs::Twist cmd_vel message, eventually generated from the ROS 2 navigation task, the PWM and digital pins of the board can be controlled. After the interface with the motors, we can move on to the configuration of the other software used to enable the autonomous navigation of the mobile base: the odometry calculation and the ROS 2 navigation stack.
Interfacing the robot’s motors
Let’s discuss the motor_ctrl.cpp source:
- We must include the interface library in the
pigpiolibrary. We will start thepigpiodaemon separately...