消息类型:
1. Twist - 线速度角速度
通常被用于发送到/cmd_vel话题,被base controller节点监听,控制机器人运动
geometry_msgs/Twist geometry_msgs/Vector3 linear float64 x float64 y float64 z geometry_msgs/Vector3 angular float64 x float64 y float64 z
linear.x指向机器人前方,linear.y指向左方,linear.z垂直向上满足右手系,平面移动机器人常常linear.y和linear.z均为0
angular.z代表平面机器人的角速度,因为此时z轴为旋转轴
示例:
#! /usr/bin/env python ''' Author: xushangnjlh at gmail dot com Date: 2017/05/22 @package forward_and_back ''' import rospy from geometry_msgs.msg import Twist from math import pi class ForwardAndBack(): def __init__(self): rospy.init_node('forward_and_back', anonymous=False) rospy.on_shutdown(self.shutdown) # this "forward_and_back" node will publish Twist type msgs to /cmd_vel # topic, where this node act like a Publisher self.cmd_vel = rospy.Publisher('/cmd_vel', Twist, queue_size=5) # parameters rate = 50 r = rospy.Rate(rate) linear_speed = 0.2 goal_distance = 5 linear_duration = goal_distance/linear_speed angular_speed = 1.0 goal_angular = pi angular_duration = goal_angular/angular_speed # forward->rotate->back->rotate for i in range(2): # this is the msgs variant, has Twist type, no data now move_cmd = Twist() move_cmd.linear.x = linear_speed # # should keep publishing ticks = int(linear_duration*rate) for t