Complete ROS Noetic Mobile Robot Guide (Raspberry Pi)
This is a 10/10 end-to-end beginner-to-working-robot guide documenting the real journey of building a 4WD mobile robot using a Raspberry Pi, Ubuntu 20.04, and ROS Noetic.
By the end of this guide, you will:
- Install Ubuntu on Raspberry Pi
- Install and configure ROS Noetic
- Create a ROS workspace
- Test motors safely
- Drive the robot forward, backward, left, and right
- Control the robot using keyboard teleoperation
DAY 1 — Setting Up Raspberry Pi with Ubuntu
1. Flash Ubuntu 20.04
- Download Ubuntu 20.04 LTS (64-bit) for Raspberry Pi
- Use Raspberry Pi Imager
- Select OS → Ubuntu 20.04
- Enable SSH before flashing
2. First Boot & Basic Setup
sudo apt update
sudo apt upgrade -y
Enable SSH (Critical)
sudo systemctl enable ssh
sudo systemctl start ssh
sudo systemctl status ssh
DAY 2 — Installing ROS Noetic
1. Add ROS Repository
sudo apt install curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list'
2. Install ROS Noetic
sudo apt update
sudo apt install ros-noetic-desktop-full
3. Initialize rosdep
sudo rosdep init
rosdep update
4. Environment Setup
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
5. Install Build Tools
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
DAY 3 — Motor Driver Wiring & Test
Motor Driver (L298N) Logic
- ENA → GPIO 18
- IN1 → GPIO 17
- IN2 → GPIO 27
- ENB → GPIO 13
- IN3 → GPIO 22
- IN4 → GPIO 23
Standalone Motor Test Script
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
pins = [18,17,27,13,22,23]
for p in pins:
GPIO.setup(p, GPIO.OUT)
GPIO.output(18, True)
GPIO.output(13, True)
GPIO.output(17, True)
GPIO.output(27, False)
GPIO.output(22, True)
GPIO.output(23, False)
time.sleep(3)
GPIO.cleanup()
This confirms wiring and motor direction before ROS.
DAY 4 — ROS Motor Driver Node
1. Create Catkin Workspace
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash
2. Motor Driver ROS Node
#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
import RPi.GPIO as GPIO
ENA, IN1, IN2 = 18, 17, 27
ENB, IN3, IN4 = 13, 22, 23
GPIO.setmode(GPIO.BCM)
for pin in [ENA,IN1,IN2,ENB,IN3,IN4]:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(ENA, True)
GPIO.output(ENB, True)
def move(cmd):
lin = cmd.linear.x
ang = cmd.angular.z
```
if lin > 0:
GPIO.output(IN1,1); GPIO.output(IN2,0)
GPIO.output(IN3,1); GPIO.output(IN4,0)
elif lin < 0:
GPIO.output(IN1,0); GPIO.output(IN2,1)
GPIO.output(IN3,0); GPIO.output(IN4,1)
elif ang > 0:
GPIO.output(IN1,1); GPIO.output(IN2,0)
GPIO.output(IN3,0); GPIO.output(IN4,1)
elif ang < 0:
GPIO.output(IN1,0); GPIO.output(IN2,1)
GPIO.output(IN3,1); GPIO.output(IN4,0)
else:
GPIO.output(IN1,0); GPIO.output(IN2,0)
GPIO.output(IN3,0); GPIO.output(IN4,0)
```
rospy.init_node('motor_driver')
rospy.Subscriber('/cmd_vel', Twist, move)
rospy.spin()
Keyboard Control
Install Teleop Package
sudo apt install ros-noetic-teleop-twist-keyboard
Run Order
roscore
rosrun my_4wd_robot motor_driver_node.py
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Use keyboard:
- i → Forward
- , → Backward
- j → Left
- l → Right
- k → Stop
Final Result
- Robot moves smoothly
- Safe motor control
- ROS-compliant architecture
- Keyboard teleoperation working
This is the foundation for joystick, autonomy, and navigation.
Comments
Post a Comment