Practice of autonomous navigation car (four)

2.6 Self-starting script problem

First of all, we continue the previous tutorial. We put the commands to start all ROS nodes in a self-start script to let Ubuntu run automatically after booting. There are two ways to realize the function of the self-start script in Ubuntu.

The first kind of startup Application that comes with ubuntu

First create a new mytest.sh file and fill in the following content [6], here is an example of starting a turtlebot node and a small turtle

#! /bin/bash
### BEGIN INIT INFO
# Provides:          xxxx.com
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mylaunch service
# Description:       mylaunch service test
### END INIT INFO

gnome-terminal -x bash -c "source /opt/ros/kinetic/setup.bash;roslaunch turtlebot_bringup minimal.launch" #新建终端启动节点
sleep 8 #等待8秒
gnome-terminal -x bash -c "source /opt/ros/kinetic/setup.bash;rosrun turtlesim turtlesim_node" &  
wait
exit 0

Among them, gnome-terminal -x bash -c means to create a new bash terminal and execute the statement following c, the command is separated by';;'
,! Note, if it is an ubuntu 18.04 system [6], gnome-terminal -x bash- c needs to be rewritten into gnome-terminal-bash -c

Next, modify permissions on the mytest.sh file

sudo chmod 777 mytest.sh

Here it is best to test whether the .sh file you wrote yourself can run

./mytest.sh

Search for "startup Application" in ubuntu 1604 and you will find the configuration software.
Insert picture description here
Select our newly created mytest.sh file
Insert picture description here
. Note here that we need to set the current account to automatically log in

Insert picture description here
After restarting, it will automatically enter the desktop and then the ros node. Note (I found during the test that this method must be set to automatically log in to the account. It should be after entering the desktop to run the startup script we set)

The second rc.local script start

The second is through the script file rc.local in Ubuntu 1604 (/etc/rc.local), where we need to write the startup code into a xxx.sh file in advance (of course, if there are fewer commands, you can also Uninstall all the commands directly in rc.local), then open the rc.local file and add a self-starting command in front of "exit 0" such as:

gnome-terminal --window -x bash -c "sh /home/crp/mytest.sh;exec bash"

There is another command format here:

gnome-terminal --window -x bash -c "sh /home/crp/mytest.sh;exec bash"
echo  123456| sudo -S 
gnome-terminal -t "terminal-name" -X bash -c "sh ./xxx.sh"; exec bash;

This command is to create a new terminal, and then run the xxx.sh file in the /home/crp/xxx.sh directory, and switch to the super user (password 123456), and then create a new terminal to run another xxx .sh file.

The above method may be invalid. [7] The pop-up command such as gnome-terminal --window -x bash -c is invalid.

The third installation script service starts

The third way is to install the startup script as the startup service of Ubuntu:
1> Copy the startup script "my_autorun.sh" to the /etc/init.d/ directory
2> Next modify the permissions of this script

sudo chmod 755 /etc/init.d/mytest.sh

3> Install script service

cd /etc/init.d
sudo update-rc.d mytest.sh defaults 95   #其中95是启动顺序

4> Uninstall script service (no operation required during installation)

 cd /etc/init.d
 sudo update-rc.d -f mytest.sh remove   #其中95是启动顺序

Next, we create a new file named "car_launch.sh" and add the following content:

3 summary

Through the previous three blogs, I sorted out the hardware framework of the autonomous navigation car, the algorithm framework of mapping and the algorithm framework of navigation. I put all the code on this github .

In the hardware article, since we are using a standard platform and do not involve making the car chassis by ourselves, we did not mention the steps of making the chassis. We will build a self-made ROS chassis in the future. Generally speaking, the ROS chassis needs to receive the linear speed and angle Command, the chassis communicates with the ROS node by the single-chip microcomputer, and the single-chip is responsible for the closed-loop control of the motor and the conversion of the kinematics model of the chassis. In addition, additional sensor modules such as ultrasonic and power management systems are required on the chassis.

In the process of building maps, we only used gmapping to create maps. gmapping is only applicable to 2D lidars. 3D lasers and RGB-D cameras cannot be used to create maps. Therefore, the follow-up plan to learn Google’s cartography has been established using ORB-SLAM 3D point cloud map.

In the process of motion planning, we only understood the operating parameters of move_base in a simple way. Since there are many parameters, we plan to have a deeper understanding of the operating parameters of move_base in the subsequent process.

Reference

【1】https://blog.csdn.net/huaweijian0324/article/details/81142610
【2】 https://www.ncnynl.com/category/ros-car/
【3】https://www.ncnynl.com/archives/201703/1415.html
【4】https://blog.csdn.net/Nksjc/article/details/77359952
【5】https://blog.csdn.net/x_r_su/article/details/52927564
【6】https://blog.csdn.net/baidu_34319491/article/details/106456571
【7】https://blog.csdn.net/Andrwin/article/details/100883593

Previous post: Practice of autonomous navigation car (3)

For friends who have running problems, please email or leave a message to discuss [email protected]

Guess you like

Origin blog.csdn.net/crp997576280/article/details/100023484
Recommended