BUPT smart car simulation training (e) - use data visualization tools

Foreword

Previous: Beijing University of Posts and Telecommunications smart car simulation training (four) - Detailed simulation of Principle
Use this section to explain ros in drawing tools, can be very intuitive look at our data, we can easily debug our code. This set of tutorials ros who want to participate in a small group of creative partners ROS outdoor photo can also play a role entry, but really want to participate in outdoor photoelectric creative group recommended a look at my blog ros programming practices of those articles, to try ros several open-source platform will have a more profound understanding.

rqt_plot use Description

Here first with a simple example illustrates the use of this tool, and then combine the transmission line of the script before we use.
Create a new script in our buptsmartcat package:

cd ~/smartcar_ws/src/buptsmartcar/src
gedit sine_wave.py

sine_wave.py:

#!/usr/bin/env python
# coding=utf-8
import math, time
import rospy
from std_msgs.msg import Float64

rospy.init_node('sine_wave')#初始化节点
pub = rospy.Publisher('sin', Float64,queue_size = 1)#发布sin话题,消息类型是Float64
while not rospy.is_shutdown():#一直发布
  msg = Float64()#创建Float64对象
  msg.data = math.sin(4*time.time())#对象的数据
  pub.publish(msg)#发布消息
  time.sleep(0.1)

Giving execute permission to the script:

chmod 777 *

In a terminal starts ros services:

roscore

Use ros ros tools are required to start the service, we did not start before roscore with roslaunch reason is because the internal performs roscore execution roslaunch
Execute the script:

cd ~/smartcar_ws/src/buptsmartcar/src
python sine_wave.py

Open another terminal, using a data visualization functions rqt_plot:

rqt_plot /sin/data

Here Insert Picture Description
Toolbar There are many tools at how we can try to use your own.

Modify our patrol line script, visual debugging parameters

cd ~/smartcar_ws/src/buptsmartcar/src
gedit findLine.py

In these section plus position as shown below:

      msg = Float64()
      msg.data = err
      self.err_pub.publish(msg)

Here Insert Picture Description
In these section plus position as shown below:

    self.err_pub = rospy.Publisher('err',
                                       Float64, queue_size=1) 

Here Insert Picture Description
In these section plus position as shown below:

from std_msgs.msg import Float64

Here Insert Picture Description
Here we publish the topic of data is err, data / data, he is our value bias, which is the deviation of the center of the center of the current track and our pictures
Start gazebo model

roslaunch smartcar_description smartcar_display_gazebo3.launch

Transmission line script execution,记得先把地图拖进去

rosrun buptsmartcar findLine.py

Here you can not use rosrun to findLine.py folder using Python commands to execute the script, ros automatically will help you find the script location
Start monitoring data:

rqt_plot /err/data

Tips:
Here If you want to see more data can be used like this:rqt_plot /err/data /sin/data ...
Here Insert Picture Description

这里我们可以看到误差在0的上下起伏,这里我们修改PID参数中的P可以一定程度的减小这种起伏,但是如果P太小可能会导致在过急弯的时候车子因为转向太小而冲出跑道,所以当p的参数差不多的时候需要加PID中的D来消抖动。这里提一句吧,如果你发现你的PID参数不能很好的适应所有的情况,你可能会需要动态的来改变PID的参数,可以分几种情况,比如急弯时我们的P参数取一个较大的数,近乎直道时取一个较小的数等等。

Published 56 original articles · won praise 5 · Views 2370

Guess you like

Origin blog.csdn.net/qq_37668436/article/details/104919390
Recommended