Introduction to ROS (1)

Course1 Introduction to ROS

Overview:

  • ROS structure and principles
  • ROS hosts, nodes, topics and messages
  • Simple console command
  • Catkin workspace and creation system
  • ROS Launch
  • Gazebo Simulator

1. ROS structure and principles

ROS concept : ROS = Robot Operating System, including:
1. Channel: ROS provides a publish-subscribe communication framework to easily and quickly build a distributed computing system
2. Tools: ROS provides a large number of tool combinations for To configure, start, self-check, debug, visualize, log in, test, and terminate the distributed computing system;
3. Capability: with functions such as control, planning, prediction, positioning and manipulation;
4. Ecosystem: the support and development of ROS relies on a strong community. With a particular focus on compatibility and support documentation, ros.org provides a "one-stop" solution for users to search and learn from thousands of ROS packages from developers around the world.

ROS history :
The ROS system originated from the collaboration between the STAIR project of Stanford University's Artificial Intelligence Laboratory and the Personal Robots Program of the robotics company Willow Garage in 2007, and has been promoted by Willow Garage since 2008. It is used by many schools and companies today. Defacto standard for robot transformation

ROS principles :
1. Point-to-point design: The point-to-point design of ROS and mechanisms such as service and node managers can disperse the real-time computing pressure brought by functions such as computer vision and speech recognition, and can adapt to the challenges encountered by multiple robots.
2. Distributed design: Programs can run on multi-core computers and can communicate over a network.
3. Multilingual: ROS now supports many different languages, such as C++, Python, Octave, and LISP, and also includes multiple interface implementations for other languages. Language-independent message processing, allowing multiple languages ​​to be freely mixed and matched.
4. Lightweight: Encourage all drivers and algorithms to gradually develop into separate libraries with no dependencies on ROS. The system built by ROS has the characteristics of modularization. The code in each module can be compiled separately, and the CMake tool used for compilation makes it easy to realize the concept of streamlining. ROS basically encapsulates complex code in libraries, but creates some small applications for ROS to display library functions, allowing simple code to be ported and reused beyond prototypes.
5. Free and open source: Most of the source code of ROS is publicly released.

ROS working environment
Defines the context of the current workspace. The default workspace is imported as follows:

source /opt/ros/kinetic/setup.zsh 

Override the Catkin workspace:

cd ~/catkin_ws
source devel/setup.zsh

You can check your local workspace with the following command:

echo $ROS_PACKAGE_PATH

2. ROS hosts, nodes, topics and messages

The ROS host Master
is used to manage the communication between nodes. The ROS Master provides the registration list and the lookup of other calculation charts through RPC (Remote Procedure Call Protocol). Without a controller, nodes cannot find other nodes, exchange messages, or invoke services.

Start the Master command:

roscore 

ROS nodes Nodes
nodes are processes that independently compile and perform computing tasks. The way ROS exploits scalability is through code modularity: a system is typically composed of many nodes. Here, nodes can also be referred to as "software modules". We use "nodes" to make ROS-based systems more visible when they are running: when many nodes are running at the same time, it is convenient to draw a graph of end-to-end communication, in which processes are the nodes in the graph , and the end-to-end connection relationship is the arc connection.

Run the node:

rosrun package_name node_name

View the list of active nodes:
rosnode list

Retrieve information about a node:

rosnode info node_name

ROS topic Topic
messages are delivered in a publish/subscribe manner. A node can publish messages in a given topic. A node follows and subscribes to a specific type of data on a topic. There may be multiple nodes publishing or subscribing to the same topic at the same time. In general, publishers and subscribers are unaware of each other's existence.

View active themes:

rostopic list

To subscribe and print the content of a topic:

rostopic echo /topic

Display topic related information:

rostopic info /topic

Although the topic-based publish/subscribe model of ROS message
is a very flexible communication mode, its broadcast path planning is not suitable for the synchronous transmission mode that can simplify node design. In ROS, we call it a service, defined with a string and a pair of strictly canonical messages: one for the request and one for the response.
The message is used to define the data structure of the topic type. It is a series of structures such as integer, floating-point, Boolean, and string that are compressed and defined as *.msg files.
View topic types:

rostopic type /topic

Publish a message to topic:

rostopic pub /topic type args

3. Simple console commands

Running an instance of ROS

Start:

roscore

Run a publisher:talker:

rosrun roscpp_tutorials talker

View the list of active nodes:

rosnode list

Display information about talk nodes:

 rosnode info /talker

In the information of the talk node, we can see its topic: chatter, check the relevant information of chatter:

rostopic info /chatter

chatter topic type:

 rostopic type /chatter

Chatter topic information content:

rostopic echo /chatter

Analysis frequency:

rostopic hz /chatter

Run a subscriber: listener

rosrun roscpp_tutorials listener

Publish your own information, that is, create a publisher under the chatter topic:

rostopic pub /chatter std_msgs/String "data: 'My own message.'"

4. Catkin Workspace and Creation System

catkin creation system
catkin is a ROS creation system used to generate executables, libraries and interfaces.
(Many people now recommend catkin build instead of catkin_make)
First go into the workspace:

cd ~/catkin_ws

Then create a package:

catkin build package_name

Whenever you create a new package, you need to update your environment:

source devel/setup.zsh

The workspace created by catkin contains the following three folders:
1. src: This is where the source code is stored, where the operator codes and modifies
2. build: It is used to store cache files and some intermediate files, Do not touch
3. devel: (development) The place where the created target is stored (installed before storage), do not touch

Clear the entire build and devel space:

catkin clean

Check catkin space creation:

catkin config

Create a Cmake build type to Release:

catkin build --cmake-args-DCMAKE_BUILD_TYPE=Release

5. ROS Launch

The Launch file is provided by ROS and can run files of multiple nodes at the same time. Launch files are written in a special XML format and are *.launch files.

Run a launch file:

roslaunch file_name.launch

Run a launch file from the package:

roslaunch package_name file_name.launch

The launch file structure (talker_listener) is an example:

<launch>
    <node name="listener" pkg="roscpp_tutorials" type="listener" output="screen"/>
    <node name="talker" pkg="roscpp_tutorials" type="talker" output="screen"/>
</launch>

launch: root element
node: use the node label to indicate the node
name: the name of the node
pkg: the name of the package containing the node
type: the node type
output: indicate where the log information is located

range_world.launch(simplified)

<?xml version="1.0"?>
<launch>
    <arg name="use_sim_time" default="true"/>
    <arg name="world" default="gazebo_ros_range"/>
    <arg name="debug" default="false"/>
    <arg name="physics" default="ode"/>
    <group if="$(arg use_sim_time)">
        <param name="/use_sim_time" value="true" />
    </group>
    <include file="$(find gazebo_ros) /launch/empty_world.launch">
        <arg name="world_name" value="$(find gazebo_plugins)/
        test/test_worlds/$(arg world).world"/>
        <arg name="debug" value="$(arg debug)"/>
        <arg name="physics" value="$(arg physics)"/>
    </include>
</launch>

File Analysis
Create a reusable launch file:

<arg name="arg_name" default="default_value"/>

Use argument in the file:

$(arg arg_name)

When running the file it can be set as follows:

roslaunch launch_file.launch arg_name:=value

If the file contains other files in the project:

<include file="package_name"/>

Find system paths for other packages:

$(find package_name)

Pass arguments to the included file:

<arg name="arg_name" value="value"/>

6. Gazebo Simulator

Gazebo is a simulation environment (platform) that can perform 3D robot dynamics simulation, etc. It is powerful enough to simulate articulated robots in complex and realistic environments.
Run Gazebo:

rosrun gazebo_ros gazebo

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324752597&siteId=291194637