[ROS learning] ROS introduction and basic operation

[ROS learning] (2) ROS introduction and basic operation

1. Introduction

Robot design includes

  • hardware design
  • Embedded software design
  • Upper software design
  • Mechanical structure design
  • machining

Robot Operating System (ROS)

  • Open source meta operating system for robots
  • It integrates a large number of tools, libraries and protocols, provides functions similar to those provided by OS, and simplifies the control of robot
  • It provides tools and libraries for distributed code acquisition, construction, writing and running, which is similar to the framework of robot
  • ROS system is a collection of communication mechanism (Plumbing), tool software package (Tools), robot high-level skills (Capabilities, such as map scanning, navigation, etc.) and robot Ecosystem

ROS design objectives

  • code reuse
  • Distributed: ROS is a process suitable for distributed processing
  • Loose coupling: the coupling between interfaces is low, so you only need to pay attention to their respective fields
  • Streamlining: for reusability
  • Language independence: Multilingual adaptation
  • Easy to test: with built-in test framework
  • Large scale applications: suitable for large-scale runtime systems and large-scale development processes
  • Rich component chemical tool package
  • Free and open source

2. Basic operation

2-1. Create a workspace

mkdir ./ros_work_space/src
# Initialize workspace
# Return to ros_work_space/src compiles the workspace

2-2. Create hello ros c + + program

create package

# Create a function package named helloros in the src directory of the created workspace (roscpp rospy std_msgs is the dependency of the function package)
catkin_create_pkg helloros roscpp rospy std_msgs 

Create a c + + file in the src directory of the feature package

touch helloros_c.cpp

Edit the c + + file as the source program

#include "ros/ros.h"

int main(int argc, char *argv[])
    //Perform ros node initialization
    //Create ros node handle (not required)
    ros::NodeHandle n;
    //Console output hello world
    ROS_INFO("hello world!");

    return 0;

Edit the CMakeLists.txt file under the function pack

# Find the comment symbol on line 136 and change it to
add_executable(Function package name src/helloros_c.cpp)
# Find the function in line 149, remove the annotation symbol and modify it to
target_link_libraries(Function package name

Return to the workspace directory and compile the workspace


After successful compilation, start the ros core


Execute the program in the function pack

# Add environment variable
source ./devel/setup.bash
# The example of executing the function package under the helloros package says that the above function package name is set to roshello
rosrun helloros roshello

If there is no error, you can see the output (which is the result of the execution of the ROS_INFO() function in the cpp program)

2-3. Create hello ros python program

Create a scripts folder under the function pack created in 2 (a folder stored as a python file)

cd helloros
mkdir scripts

Enter the scripts folder to create helloros_ p. python program of python

cd scripts 
touch helloros_p.py

Edit the helloros_p.py program

#! /usr/bin/env python
## Specify Python interpreter
# 1 Guide Package
import rospy
# 2 write function main entry
if __name__ == "__main__":
	# 3 output log
	rospy.loginfo("hello ROS!")

Because the python file is a script file, you need to add executable permissions

chmod +x helloros_p.py
# You can use the ll command to view permissions

Modify the CMakeLists.txt file under the helloros function pack

# Line 162 removes the explanation and modifies the file name

Return to ROS_ work_ Compile workspace under space directory


Open a new terminal and run roscore


Load setup.bash in the previously opened terminal and execute the program helloros_p.py

source ./devel/setup.bash
rosrun helloros helloros_p.py

If there is no error, you can see the output hello ROS!


Tags: data structure linked list Singly Linked List

Posted on Wed, 24 Nov 2021 10:04:57 -0500 by ravegti