ROS Melodic

Package Structure


ws_catkin
├── devel
├── build
└── src
    └── package_name
        ├── CMakeList.txt
        ├── package.xml
        ├── arduino           --- arduino_sketch.ino
        ├── config            --- config.yaml
        ├── doc               --- pdf jpg
        ├── include
        │   └── package_name  --- cppheader.h
        ├── src               --- cppsource.cpp
        ├── scripts           --- python_script.py
        ├── launch            --- launch_file.launch
        ├── action            --- action.action
        ├── msg               --- msg.msg
        ├── srv               --- srv.srv
        ├── rviz              --- rviz_config.rviz
        ├── test              --- unitest.cpp/.py
        └── gazebo
            ├── meshes        --- model.STL/.dae
            ├── models        --- model.config/.sdf/.urdf
            ├── urdf          --- model.xacro/.gazebo
            └── worlds        --- model.world
        

Workspaces and Package

Create Workspace


mkdir catkin_ws && cd catkin_ws
wstool init src
catkin_make
source devel/setup.bash
        

Add Repo to Workspace


roscd; cd ../src
wstool set repo_name \
--git http://github.com/org/repo_name.git \
--version=melodic-devel
wstool up
        

Resolve Dependencies in Workspace


sudo rosdep init  # only once
rosdep update
rosdep install --from-paths src --ignore-src \
--rosdistro=${ROS_DISTRO} -y
        

Create Package


catkin_create_pkg package_name [dependencies ...]
        

CMakeList.txt

Skeleton


cmake_minimum_required(VERSION 2.8.3)
project(package_name)
find_package(catkin REQUIRED)
catkin_package()
        

Package Dependencies


find_package(catkin REQUIRED COMPONENTS roscpp)
Tell dependent packages what headers or libraries to pull in when your package is declared as a catkin component:
catkin_package(
    INCLUDE_DIRS include
    LIBRARIES ${PROJECT_NAME}
    CATKIN_DEPENDS roscpp)
        

Messages, Services


find_package(catkin REQUIRED COMPONENTS message_generation std_msgs)
add_message_files(FILES MyMessage.msg)
add_service_files(FILES MyService.msg)
generate_messages(DEPENDENCIES std_msgs)
catkin_package(CATKIN_DEPENDS message_runtime std_msgs)
        

Build Libraries, Executables


add_library(${PROJECT_NAME} src/cpp_code.cpp)
add_executable(${PROJECT_NAME}_node src/cpp_code.cpp)
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES})
add_dependencies(${PROJECT_NAME} beginner_tutorials_generate_messages_cpp)
        

Installation


install(TARGETS ${PROJECT_NAME} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(TARGETS ${PROJECT_NAME}_node DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
install(PROGRAMS scripts/myscript DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
        

Remote Connection

To connect remotely, ensure the following:

To debug, check ping from each side to the other, run roswtf on each side.

Command Line Interfaces

Command Description
rosnode list List available ROS nodes
rostopic list List available ROS topics
rostopic echo /topic_name Print out data in topic name
rostopic hz /topic_name Calculate frequency of topic
rostopic info /topic_name Show information of topic
rosmsg show message_msgs/msg_name Show information of data in ROS message
rospack find {package_name} Find the location of the package
rospack depends {package_name} Find the packages that the package depends on
rospack help Show description of rospack
rosrun rqt_graph rqt_graph Show rqt graph
roscd {package_name} Change directory to ROS package in system
rosls {package_name} List content in the directory
find . -name".py" -exec chmod +x {} \; Find all files ending in .py and make them executable