rospy让机器人绕圈、矩形行走(碰到障碍物停止)

更新时间:2023-05-13 19:50:25 阅读: 评论:0

励志奖学金rospy让机器⼈绕圈、矩形⾏⾛(碰到障碍物停⽌)绕圆圈⾏⾛白灼秋葵
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from math import pi
def publisher():
  pub = rospy.Publisher('mobile_ba/commands/velocity', Twist)
组合销售
  rospy.init_node('Walker', anonymous=True)
  rate = rospy.Rate(10) #10hz
  r = 0.1 # 半径
  speed_lin = 0.5 #线速度
  speed_ang = speed_lin/(2*pi*r) #⾓速度
  desired_velocity = Twist()
  desired_velocity.linear.x = speed_lin
  desired_velocity.angular.z = speed_ang
  while True:
  pub.publish(desired_velocity)
  rate.sleep()
if __name__ == "__main__":
try:
  publisher()
except rospy.ROSInterruptException:
  pass
————————————————
绕矩形⾏⾛,并且碰到障碍物停⽌。
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from kobuki_msgs.msg import BumperEvent
from math import pi
import time
stop = Fal
def callback(data, pub):
global stop
if data.state == 1:
stop = True
print('Robot stop!')
def publisher():
global stop梦见和男友分手
pub = rospy.Publisher('mobile_ba/commands/velocity', Twist)
sub = rospy.Subscriber('mobile_ba/events/bumper', BumperEvent, callback=callback, callback_args=pub)
rospy.init_node('Walker', anonymous=True)
rate = rospy.Rate(10) #10hz 10/s
教堂简笔画desired_velocity = Twist()
desired_velocity.linear.x = 0
desired_velocity.angular.z = 0
while True:
desired_velocity.linear.x = 0.3
desired_velocity.angular.z = 0
# go straigth
for i in range(40):
pub.publish(desired_velocity)
if stop:
return
rate.sleep()
# turn direct
desired_velocity.linear.x = 0 desired_velocity.angular.z = pi/2
中等职业技术学校
for i in range(10):
pub.publish(desired_velocity)
if stop:安宫牛黄丸说明书
return
rate.sleep()
if __name__ == "__main__":
try:
publisher()
正宗羊肉汤except rospy.ROSInterruptException: pass

本文发布于:2023-05-13 19:50:25,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/894010.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:机器   碰到   矩形   男友   销售   简笔画
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图