Getting Started with ROS Basics - Hands-on Tutorials
preamble
This tutorial is hands-on and less about books.Documents available for referenceIn the detailed record of ROS practice and theory, just too detailed and complicated, read the brain pain, so I made this note.
This article was first edited on October 4, 2024
CSDN Home Page:/rvdgdsva
Blogland Home Page:/hassle
I. Install [virtualbox] [Ubuntu] [ROS].
enjoy the benefits of the hard work of one's predecessors.
Installation of virtualbox tutorial
Installing Ubuntu Tutorial
Installation of ROS Tutorial
Testing ROS Tutorials
II. Document creation
2.1 Workspace creation and initialization
Reference here(Optional)
Press (ctrl + alt + T) in the main ubuntu interface to open the command line, and then enter the following commands in sequence
mkdir -p test (this is a customized space name, call it whatever you want) /src
cd test (this is a custom space name, call it whatever you like)
catkin_make
The following file tree was generated
....
└─ test(folder, meaning workspace, created when the first line of code is run)
├── build(folder, meaning compilation space, created when the third line of code is run)
│ ├── ...
├── devel(folder, meaning development space, created when the third line of code runs) │ ├── devel(folder, meaning development space, created when the third line of code runs)
│ ├──
│ ├──
│ ├── ...
└── src(folder, created when the first line of code is run) │ └── src(folder, created when the first line of code is run)
└── (Don't move this)
2.2 Importing packages
Generate a ROS package based on three libraries: roscpp is a library implemented using C++, rospy is a library implemented using python, and std_msgs is a standard message library
cd src
catkin_create_pkg testpkg (this is the ROS package name, call it what you like) roscpp rospy std_msgs
At this point, the src file tree changes
....
└── test
build
│ ├── ...
├── devel
│ ├──
│ ├──
│ ├── ...
└── src
└── (Don't move this! The file with the same name is the one below, don't get it wrong)
└── testpkg
├── (cpp and py code need to be modified here) (2.4 involves here)
├── include
│ └── testpkg
├──
└── src (cpp code here) (2.3 covers here)
2.3 Writing Cpp and Py programs
Cpp Detailed Tutorial(The tutorial is condensed into the following sentence, after reading the tutorial, if you feel confused, just follow the words below)
In a nutshell: you need to store the written cpp file in the src (source file space) ------> testpkg (ROS package name, whatever you want to call it) ------> src folder (used for storing cpp files)
Py detailed tutorial(ibid.)
In a nutshell: you need to store your written py files in the src (source filespace) ------> testpkg (ROS package name, whatever you want to call it) ------> scripts folder (used for py files, you need to manually create this folder).
2.4 Rewriting of documents
2.4.1Cpp program:
Inside the custom named package (which is required to execute cpp and py code), modify lines 136 and 149-151 to read
The exact number of rows may vary depending on the version
Note that the mapping name (the mapping name is just a random name, don't write test) can be the same as the name of the cpp source file
add_executable(mapping name
src/source filename.cpp
)
target_link_libraries(mapping name
${catkin_libraries}
)
2.4.2 python program:
Inside the custom named package (which is required to execute cpp and py code), change lines 162-165 to read
The exact number of lines may vary depending on the version
Note that here the Py program isNo mapping name required(used form a nominal expression)
catkin_install_python(PROGRAMS scripts/source filename.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
2.5 Compile and run the program
2.5.1Cpp program:
In the custom space name (created in 2.1) press (ctrl + alt + T) to open the command line and type in order
catkin_make
roscore
In the custom space name (created in 2.1) press (ctrl + alt + T) to open theanothercommand line, type
source . /devel/
rosrun package name (created in 2.2) mapping name (created in 2.4)
2.5.2Python program:
In the custom space name (created in 2.1) press (ctrl + alt + T) to open the command line and type in order
chmod +x source filename.py
catkin_make
roscore
In the custom space name (created in 2.1) press (ctrl + alt + T) to open theanothercommand line, type
source . /devel/
rosrun testpkg (ROS package name, call it what you like, created in 2.2) source filename.py (created in 2.4)