ros发布节点信息python_ROS Twist和Odometry消息类型使用(Python)

本文介绍了ROS中的Twist和Odometry消息类型在Python中的使用。Twist消息常用于控制机器人运动,包含线速度和角速度;Odometry消息则提供了更精确的机器人位姿信息,包括位姿、线速度、角速度及其协方差。通过示例代码展示了如何发布Twist消息控制机器人前进、旋转,以及如何通过Odometry获取机器人运动轨迹和位姿。
摘要由CSDN通过智能技术生成

消息类型:

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'''

importrospyfrom geometry_msgs.msg importTwistfrom math importpiclassForwardAndBack():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 = 50r=rospy.Rate(rate)

linear_speed= 0.2goal_distance= 5linear_duration= goal_distance/linear_speed

angular_speed= 1.0goal_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 i

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值