ROS??? Tell me more about it. #
To design and run a robot, one easy way is to use ROS.
- Why we use ROS?
- A lazy way to compile :P Otherwise you may need pointers and need to handle a bunch of annoying bugs.
- System requirement?
- Linux. I use ubuntu 20.04.6. And if you are using windows 10 or 11, you can conside windows subsystem, which is the easiest way. Unfortunately, I forgot how to setup :( Check this document.
- The downside of the subsyetem is, the subsystem doesn’t have a graphic desktop prepared for you. Warning: if you are using ROS1, currently (May 2024) ROS1 cannot run on ubuntu 22. There’re a bunch of tutorials on youtube regarding ros. If you can, use virtual machine, double system, or buy a hard drive and install Linux on that.
- Recommended tutorials?
- I recommend this series. It includes ROS setup process. Click the link to see all 11 videos.
Create a new workspace when you start a new project #
In linux terminal, at your home directory, create a folder as your workspace directory using
mkdir [your folder name]
, for instance:mkdir test_ws
Use
cd [your new folder name]
, for instance,cd test_ws
, to navigaite into your directory. Then runmkdir src
to create your source folder. (Tip: You can usels
to check what’s inside your folder or directory.) Here is an example for step 2:cd test_ws
mkdir src
lsUse
cd src
to navigate into your new blank source folder. Then initialize catkin workspace. This is the code for step 3:cd src
catkin_init_workspace(Important) Go back to the home directory of your workspace folder by
cd ..
, press enter, then runcatkin_make
, which will create all shenanigans (I mean a bunch of files) for you. Code for step 4:cd ..
catkin_make(Important) Now you need to source your file by:
source devel/setup.bash
Each time you run the program, you have to source your directory by running the line above. This is needed after you open your linux terminal, whenever do run the program, and whenever to switch to another robot project, etc. (Well, if you’re not sure, just run it. It’s not harmful).
BUT THERE IS A TRICK :) There is a way that you don’t need to source that often. Just run:
cd ..
(Note: if there is an error, use
sudo gedit .bashrcsudo install gedit
if your linux don’t have gedit).Enter your password, and then scroll down to the bottom of a bunch of test after a bunch of if statements. Add two lines of code:
source /opt/ros/noetic/setup.bash
source ~/[your folder name, for instance, test_ws]/devel/setup.bashCongrats, you edited the code file! But to keep safe, I recommend after using gedit, still run source code whenever you are not sure if you should run it or not.
test_ws
to catkin_ws
, change the line, quote (using #
) and create a new line, for instance:
source ~/catkin_ws/devel/setup.bash
#source ~/test_ws/devel/setup.bash
You’ve finished creating directories and soursing files. Now we need packages. Depending on the language you use (can be Python or C++), you may need different packages. Use
cd [your directory]/src
to your source folder (for instance, test_ws/src), and then typecatkin_create_pkg [your package folder] [all the shenanigans you need]
. If you need C++, use roscpp; if you use Python, use rospy. Here’s the example code for step 7:cd test_ws/src
catkin_create_pkg this_is_a_package roscpp rospy std_msgCongrats, you have created a new workspace with packages!
Last modified on 2024-05-21