- Arduino Uno or Nano - 1 nos
- DC motor with encoder - 2 nos (I have used SPG30E-200K DC Geared Motor with Encoder)
- L298 or L293 motor driver - 1 nos
- Include the required header files
- Declare variables for publishing encoder ticks
- Instantiate a ROS Publisher to publish the motor encoder ticks
- Instantiate a ROS subscriber that subscribes to the topic /cmd_vel
- Within the Arduino setup function :
- Set the pin modes
- Initialize the baud rate
- Initialize the node
- Initialize the subscriber for command velocity
- Initialize the subscriber for resetting encoders
- Advertise the left and right motor encoder publishers
- Within the Arduino loop function :
- Assign data values to encoder tick publisher
- Process the subcriber callback (nh.spinOnce())
- Add a small delay
- Functions for moving the bot : forward, backward, turn left, turn right, stopping
- cmd velocity call back function
- Interrupt functions for left and right encoders
- Encoder reset function
- Pin declarations : Arduino pins connected to motor, PWM pins, Encoder pins
- DC motor interfacing with ROS serial
- Configure VS Code for rosserial_arduino
- Video tutorial - Configure VS Code for rosserial_arduino
- Launch roscore in a terminal
roscore
- In another terminal type in following to launch a rosserial connection with Arduino
rosrun rosserial_arduino serial_node.py _baud:=115200
- In yet another terminal run teleop_twist_keyboard to control the motor. Since we have interfaced only one motor we can verify the following functionalities - bot_forward, bot_backward and bot_stop. The bot_left and bot_right functionalities can be verified by interfacing one more motor.
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
- Launch another terminal and echo the motor encoder tick topics
rostopic echo \left_encoder_ticks
rostopic echo \right_encoder_ticks