This is a tutorial for tutorials. I wanted to share my experience navigating the tutorials and try and highlight the issues that couldn't be answered for me. This way you won't have to spend so long digging for the answers on a random forum!
I was looking to get into ROS for a while, and wanted to apply the technology onto a robot built with my own hands. But with not much money to spend, I tried to see if I can build a robot with parts I had around my house. This tutorial will hopefully make you more comfortable with ROS, Ubuntu, Python, and general robot design.
This entire tutorial is done on Windows 10. Vscode and WSL are also being used.
Step1 : Installing Ubuntu 20.04 and ROS Noetic
We're gonna get started with installing Ubuntu and ROS Noetic so we can image the Raspberry Pi for Robotics Programming.
Connect your microSd card to your computer. If you don't have it already, make sure you download Raspberry Pi Imager. When you open RPI imager, select the OS ( Ubuntu 20.04), and the disk drive to image to (make sure it's your sd card). Go ahead and install. Once the install is finished, plug it into the Raspberry Pi. Connect a network adapter, power, and an external display to the pi as well, so we can see what the Pi does.
Now if you see green and red lights flashing from the PI, that means it's trying to boot. You should see the messages on your external monitor, showing the Pi installing the OS, and configuring the internet. It's gonna flash quickly, but you should be able to make out the IP address of your Pi.
If not, in either command prompt or powershell, go ahead and run arp -a | findstr b8-27-eb. arp -a alone finds all the internet addresses in the network. This command specifically will find your raspberry pi address.
Once you find it, go ahead and ssh into any terminal. ssh ubuntu@youripaddress. If you get a prompt for ECDSA signature, click yes. Everytime you setup a new ssh connection, you're computer needs to keep track of the address so the network connection is secure.
When prompted a password, enter ubuntu as the password. Then you'll be prompted to enter a new password. Once you do that, you'll be logged out, go ahead and log back in. It should show ubuntu@ubuntu in the terminal, you are now in your ubuntu bash shell.
Now Let's go ahead and setup wifi for the raspberry pi. Type cd /etc/netplan into the terminal and then type sudo nano 50-cloud-init.yaml. We are going to add the wifi settings in this file.
Copy this info into the file and save with Ctrl + S.
network: ethernets: eth0: dhcp4: true optional: true version: 2 wifis: wlan0: optional: true access-points: "network-name": password: [network-password] addresses: [[stock-network name],1.[address number of choice]/24] gateway4: [stock-network name].1.1 nameservers: addresses: [ [stock-network name], 8.8.8.8]
Now we will be able to use the raspberry pi wirelessly.
Step2: Building the robot.
Build the robot as you choose. I had this starter chassis that I used in addition to the camjam edukit. The canjam has the necessary motor controller and battery pack used. The key thing to think about when building the chassis is easy access to wiring and electronics. In early stages of the robot, I remeber having issues with wires falling out of ports for the motor controller.
Additional help with building the chassis:
Kyle goes in depth with ubuntu configuration and the cost of a starter robot in these steps:
https://kyrofa.com/posts/your-first-robot-a-beginner-s-guide-to-ros-and-ubuntu-core-1-5
Once you've finished this step, we can move onto downloading ros.
Please ssh into the raspberry pi using a terminal of your choice.
Example : ssh 192.168.1.[address number of choice]/24
Step3: Stepping into ROS Noetic
Make sure you first do
$ sudo apt-get update
$ sudo apt-get upgrade
In my case, since I have a windows laptop. I download noetic onto my pi via ssh into the pi, and in additional downloading ros onto my desktop via WSL.
This is an important configuration once we get into camera vision for the robot.
http://wiki.ros.org/noetic/Installation/Ubuntu
Follow this and install ros base onto your raspberry pi using the ubuntu bash terminal.
I also installed ros noetic desktop onto my laptop. The desktop version comes with rviz, and additional visualization packages for using the camera.
Once you have finished installing ros on both devices, go ahead and go through tutorials 1 until 16. Do the python related tutorials, since we will be coding in python.
http://wiki.ros.org/ROS/Tutorials
Note: The ROS tutorials will also go over the general Linux navigation commands like cd, ls, and special commands for navigating ros workspaces we make.
Why ROS? What ros allows us to do is control multiple functionalities of our robot through a single means, and have the functionalities communicate with each other. With ros we can use an xbox controller that works well with the python code we'll be writing for driving the robot.
Before writing any code, you'll need to do the following commands.
$ sudo apt install gcc python3-dev python3-pip python3-setuptools
$ pip3 install RPi.GPIO
Step4: Let's do some coding for the robot to drive in general.
This is an easy way of testing if the robot works.
Go ahead and follow these tutorials for coding in python.
When you want to run you're code ( for example run.py), just run
$ sudo python3 run.py
Now let's move onto implementing this code and using ROS with our robot.
Step5: Bringing the controller into play
From reading the tutorials, the first step when starting with a new project in ros is making a new workspace, and initialize it.
We use catkin for compiling the robot code for ROS to understand.
Any workspace needs the _ws in the name.
We use CMAKE to compile the code.
$ mkdir -p ~/edubot_ws/src
$ cd ~/edubot_ws/src
$ catkin_init_workspace
In our workspace, we need to establish the dependencies for the package we will make. Rospy is python specific dependency for ros. std_msgs is how we communicate with our nodes when we run ros core. We want to additional include the gpio dependecy since that is how we get the motors for the robot to run.
# This is an example, do not try to run this
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
$ cd ~/edubot_ws/src
$ catkin_create_pkg edukit_bot rospy std_msgs -s python-rpi.gpio
Now we need to write the node that we use for moving the robot.
Go ahead an follow kyle's steps for doing this.
https://kyrofa.com/posts/your-first-robot-introduction-to-the-robot-operating-system-2-5
Now with the controller, the package we need would have been able to be installed by doing
$ sudo apt install ros-noetic-joy
At the time of building the robot, I had to build the package from source, in that case
$ cd ~/edubot_ws/src
$ git clone [url of package]
$ cd ~/edubot_ws
$ catkin_make -DCMAKE_BUILD_TYPE=Release
$ source ~/edubot_ws/devel/setup.bash
Go ahead an follow the rest of kyle's tutorials, as that is what I followed to configure the controller for ROS robot.
https://kyrofa.com/posts/your-first-robot-the-controller-3-5
https://kyrofa.com/posts/your-first-robot-the-driver-4-5
https://kyrofa.com/posts/your-first-robot-sharing-with-others-5-5
Assuming that kyle's tutorial has helped you familiarize yourself with rosmaster, and the method of subscribing to nodes and sending messages to the nodes, we can now move onto implementing the camera.
NOTE : I was sometimes having issues with running GPIO code.
$ sudo chmod a+rw /dev/gpiomem
Allows you to continue running program with gpio.
Step6: Setting up the camera for vision
You'll want to start up roscore now on your desktop and on the raspberry pi.
Ros launch the node for moving the robot with the controller.
Follow steps 1 to 20 about setting up the usb camera in ros.
http://roboticsweekends.blogspot.com/2017/12/how-to-use-usb-camera-with-ros-on.html
Make sure you are exporting you're desktop's ip address as the master uri, so that we can view the image from the robot's camera.
To view this, I download xming, but you can use putty to do the forwarding for the video UI.
Make sure you do the commands on desktop.
sudo apt-get install x11-apps
export DISPLAY=:0.0
Display to export can be found when you hover over xming icon in command center.
If you've done these steps and followed the tutorial, you should now be able see the video from you're laptop when you run this command.
rosrun image_view image_view image:=/usb_cam/image_raw
Feel free to go ahead with this project, maybe make use of camera and do some object detection with OpenCV?
Hopefully this project has helped you get started in robotics with ROS. I will continue to update this page with any fixes needed and updates to the project. Thank you for checking this out!
Comments