ROS learning (4) - writing the launch file

For a complex system, there will be dozens, dozens or even hundreds of nodes running. If we start the
application by "opening the terminal and running the rosrun command" every time, it is very inefficient. We need a more convenient way to boot the system. ROS provides the "use launch file + roslaunch" command to complete the system startup. The specific implementation method is as follows:

1. Add launch file

  • Right-click the selected feature package --> Add launch folder
  • Right click on the selected launch folder ——> Add launch file
  • Write a launch file

2. Write the launch file

Here is an example launch file:

<launch>
    <node pkg="hello" type="hello_vs" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>
  • node - one of the contained nodes
  • pkg - the name of the function package where the node is located
  • type - the name of the node's binary executable
  • name —— After the node starts, it can have the node name recognized by ROS. When we write the node, we have specified the node name through ros::init(argc, argv, "node_name"). When the node starts, this startup file (*.launch) will give us a chance to rename the node.
  • output—— Set the output target of the log. After starting the node through the startup file, the default node output information will be input to a log file instead of the screen. If you want to print information on the screen, you need to add "output="screen"

     So the launch file example above implements the functions in the hello_vs.cpp file, and also starts the turtle node at the same time

     Function.

3. Run the launch file

  • Compile the file on the vscode interface ctrl+shift+B
  • Open a terminal and run:
roscore
  • Re-open a terminal and enter the command
source ./devel/setup.bash
roslaunch package_name launch_file_name

The running interface is as follows

Tip - ROS omits the command "source ./devel/setup.bash"

Because it is very troublesome to enter the command "source ./devel/setup.bash" every time a new terminal is opened, we can pass

sudo gedit ~/.bashrc

Open the .bashrc file and write the command in

source /home/***/your_ws/devel/setup.bash 

Where *** is your computer name. For specific operations, please refer to ROS omitting the command "source ./devel/setup.bash"

Guess you like

Origin blog.csdn.net/bulletstart/article/details/130794565
Recommended