ROS 底盘控制
2022-04-05 15:40 jym蒟蒻 阅读(416) 评论(0) 编辑 收藏 举报先在机器人端通过launch文件启动底盘控制。
@robot:~$ roslaunch base_control base_control.launch
... logging to /home/jym/.ros/log/3e52acda-914a-11ec-beaa-ac8247315e93/roslaunch-robot-8759.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://192.168.0.110:36751/
SUMMARY
========
PARAMETERS
* /base_control/ackermann_cmd_topic: ackermann_cmd
* /base_control/base_id: base_footprint
* /base_control/battery_topic: battery
* /base_control/baudrate: 115200
* /base_control/cmd_vel_topic: cmd_vel
* /base_control/imu_id: imu
* /base_control/imu_topic: imu
* /base_control/odom_id: odom
* /base_control/odom_topic: odom
* /base_control/port: /dev/move_base
* /base_control/pub_imu: False
* /base_control/pub_sonar: False
* /base_control/sub_ackermann: False
* /rosdistro: melodic
* /rosversion: 1.14.10
NODES
/
base_control (base_control/base_control.py)
auto-starting new master
process[master]: started with pid [8769]
ROS_MASTER_URI=http://192.168.0.110:11311
setting /run_id to 3e52acda-914a-11ec-beaa-ac8247315e93
process[rosout-1]: started with pid [8780]
started core service [/rosout]
process[base_control-2]: started with pid [8783]
[INFO] [1645250866.687446]: NanoCar_Pro base control ...
[INFO] [1645250866.713360]: Opening Serial
[INFO] [1645250866.716848]: Serial Open Succeed
[INFO] [1645250867.309188]: Move Base Hardware Ver 2.1.0,Firmware Ver 2.1.3
[INFO] [1645250867.378238]: SN:002b00413138511532323338
[INFO] [1645250867.385795]: Type:RC_ACKERMAN Motor:RS365 Ratio:11.0 WheelDiameter:72.0
检查话题列表,看目前ros中有哪些话题。
@robot:~$ rostopic list
/battery
/cmd_vel
/odom
/rosout
/rosout_agg
/tf
rostopic is a command-line tool for printing information about ROS Topics.
Commands:
rostopic bw display bandwidth used by topic
rostopic delay display delay of topic from timestamp in header
rostopic echo print messages to screen
rostopic find find topics by type
rostopic hz display publishing rate of topic
rostopic info print information about active topic
rostopic list list active topics
rostopic pub publish data to topic
rostopic type print topic or field type
battery话题,输出的内容有电池的电压和电流,发布者是机器人底盘。
@robot:~$ rostopic info /battery
Type: sensor_msgs/BatteryState
Publishers:
* /base_control (http://192.168.0.110:38535/)
Subscribers: None
@robot:~$ rostopic echo /battery
header:
seq: 1
stamp:
secs: 1645251153
nsecs: 739257097
frame_id: "base_footprint"
voltage: 12.0539999008
current: 0.670000016689
charge: 0.0
capacity: 0.0
design_capacity: 0.0
percentage: 0.0
power_supply_status: 0
power_supply_health: 0
power_supply_technology: 0
present: False
cell_voltage: []
location: ''
serial_number: ''
---
cmd_vel话题,订阅者是底盘
@robot:~$ rostopic info /cmd_vel
Type: geometry_msgs/Twist
Publishers: None
Subscribers:
* /base_control (http://192.168.0.110:38535/)
odom话题,里程计,发布者是机器人底盘。
@robot:~$ rostopic info /odom
Type: nav_msgs/Odometry
Publishers:
* /base_control (http://192.168.0.110:38535/)
Subscribers: None
odom话题,输出的主要信息是位置坐标,航向、线加速度、角加速度。
@robot:~$ rostopic echo /odom
header:
seq: 1
stamp:
secs: 1645251339
nsecs: 379389047
frame_id: "odom"
child_frame_id: "base_footprint"
pose:
pose:
position:
x: 0.0
y: 0.0
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
twist:
twist:
linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: -0.006
covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
---
然后在机器人端终止运行。输出下面这些提示。
^C[base_control-2] killing on exit
[rosout-1] killing on exit
[master] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done
下面看一下底盘控制节点的可执行文件base_control.py里面的BaseControl类,类里面有一些初始化。
为什么订阅器不需要定时器而发布器需要定时器。
因为订阅器是通过话题来驱动的,收到了订阅的话题之后,会直接跳转到回调函数里面,不需要定时器定期来执行。
关于timer_communication:
用于检查现在nano是否收到stm32的消息。定时器时间到了就去执行timerCommunicationCB回调函数。
def __init__(self):
#Get params,获取各种参数,获取的参数就是launch文件中param标签设置的参数。
#如果没有在 launch 文件中获取到这些参数就会使用类中提前设置的默认值。
self.baseId = rospy.get_param('~base_id','base_footprint')
self.odomId = rospy.get_param('~odom_id','odom')
self.device_port = rospy.get_param('~port','/dev/ttyUSB0')
self.baudrate = int(rospy.get_param('~baudrate','115200'))
self.odom_freq = int(rospy.get_param('~odom_freq','50'))
self.odom_topic = rospy.get_param('~odom_topic','/odom')
self.battery_topic = rospy.get_param('~battery_topic','battery')
self.battery_freq = float(rospy.get_param('~battery_freq','1'))
self.cmd_vel_topic= rospy.get_param('~cmd_vel_topic','/cmd_vel')
self.ackermann_cmd_topic = rospy.get_param('~ackermann_cmd_topic','/ackermann_cmd_topic')
#如果在启动时设置底盘节点launch文件pub_imu参数为True,底盘节点接收launch文件中param标签的参数,然后设置imu变量信息
self.pub_imu = bool(rospy.get_param('~pub_imu',False))
if(self.pub_imu == True):
self.imuId = rospy.get_param('~imu_id','imu')
self.imu_topic = rospy.get_param('~imu_topic','imu')
self.imu_freq = float(rospy.get_param('~imu_freq','50'))
if self.imu_freq > 100:
self.imu_freq = 100
self.pub_sonar = bool(rospy.get_param('~pub_sonar',False))
self.sub_ackermann = bool(rospy.get_param('~sub_ackermann',False))
#define param,BaseControl类使用到的变量的定义
self.current_time = rospy.Time.now()
self.previous_time = self.current_time
self.pose_x = 0.0
self.pose_y = 0.0
self.pose_yaw = 0.0
self.serialIDLE_flag = 0
self.trans_x = 0.0
self.trans_y = 0.0
self.rotat_z = 0.0
self.speed = 0.0
self.steering_angle = 0.0
self.sendcounter = 0
self.ImuErrFlag = False
self.EncoderFlag = False
self.BatteryFlag = False
self.OdomTimeCounter = 0
self.BatteryTimeCounter = 0
self.Circleloop = queue(capacity = 1024*4)#注意这个环形队列,存放串口中缓存的数据
self.Vx = 0
self.Vy = 0
self.Vyaw = 0
self