摘要: 原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/

我们现在准备用move_base简单的移动机器人记住,一个“pose”在ros的意思是一个位置和方向。

1.首先启动turtlebot机器人。

  1. roslaunch rbx1_bringup fake_turtlebot.launch

2.在另一个终端运行:

  1. roslaunch rbx1_nav fake_move_base_blank_map.launch

3.打开rviz视图查看机器人。

  1. rosrun rviz rviz -d `rospack find rbx1_nav`/nav.rviz

4.运行move_base_square.py脚本移动机器人。

  1. rosrun rbx1_nav move_base_square.py

5.rviz视图如下:

6.rqt_graph节点框图如下:

7.节点move_base_square.py代码如下:

  1. #!/usr/bin/env python
  2.  
  3. import rospy
  4. import actionlib
  5. from actionlib_msgs.msg import *
  6. from geometry_msgs.msg import Pose, Point, Quaternion, Twist
  7. from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
  8. from tf.transformations import quaternion_from_euler
  9. from visualization_msgs.msg import Marker
  10. from math import radians, pi
  11.  
  12. class MoveBaseSquare():
  13. def __init__(self):
  14. rospy.init_node('nav_test', anonymous=False)
  15.  
  16. rospy.on_shutdown(self.shutdown)
  17.  
  18. # How big is the square we want the robot to navigate?
  19. square_size = rospy.get_param("~square_size", 1.0) # meters
  20.  
  21. # Create a list to hold the target quaternions (orientations)
  22. quaternions = list()
  23.  
  24. # First define the corner orientations as Euler angles
  25. euler_angles = (pi/, pi, *pi/, )
  26.  
  27. # Then convert the angles to quaternions
  28. for angle in euler_angles:
  29. q_angle = quaternion_from_euler(, , angle, axes='sxyz')
  30. q = Quaternion(*q_angle)
  31. quaternions.append(q)
  32.  
  33. # Create a list to hold the waypoint poses
  34. waypoints = list()
  35.  
  36. # Append each of the four waypoints to the list. Each waypoint
  37. # is a pose consisting of a position and orientation in the map frame.
  38. waypoints.append(Pose(Point(square_size, 0.0, 0.0), quaternions[]))
  39. waypoints.append(Pose(Point(square_size, square_size, 0.0), quaternions[]))
  40. waypoints.append(Pose(Point(0.0, square_size, 0.0), quaternions[]))
  41. waypoints.append(Pose(Point(0.0, 0.0, 0.0), quaternions[]))
  42.  
  43. # Initialize the visualization markers for RViz
  44. self.init_markers()
  45.  
  46. # Set a visualization marker at each waypoint
  47. for waypoint in waypoints:
  48. p = Point()
  49. p = waypoint.position
  50. self.markers.points.append(p)
  51.  
  52. # Publisher to manually control the robot (e.g. to stop it, queue_size=)
  53. self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=)
  54.  
  55. # Subscribe to the move_base action server
  56. self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
  57.  
  58. rospy.loginfo("Waiting for move_base action server...")
  59.  
  60. # Wait seconds for the action server to become available
  61. self.move_base.wait_for_server(rospy.Duration())
  62.  
  63. rospy.loginfo("Connected to move base server")
  64. rospy.loginfo("Starting navigation test")
  65.  
  66. # Initialize a counter to track waypoints
  67. i =
  68.  
  69. # Cycle through the four waypoints
  70. while i < and not rospy.is_shutdown():
  71. # Update the marker display
  72. self.marker_pub.publish(self.markers)
  73.  
  74. # Intialize the waypoint goal
  75. goal = MoveBaseGoal()
  76.  
  77. # Use the map frame to define goal poses
  78. goal.target_pose.header.frame_id = 'map'
  79.  
  80. # Set the time stamp to "now"
  81. goal.target_pose.header.stamp = rospy.Time.now()
  82.  
  83. # Set the goal pose to the i-th waypoint
  84. goal.target_pose.pose = waypoints[i]
  85.  
  86. # Start the robot moving toward the goal
  87. self.move(goal)
  88.  
  89. i +=
  90.  
  91. def move(self, goal):
  92. # Send the goal pose to the MoveBaseAction server
  93. self.move_base.send_goal(goal)
  94.  
  95. # Allow minute to get there
  96. finished_within_time = self.move_base.wait_for_result(rospy.Duration())
  97.  
  98. # If we don't get there in time, abort the goal
  99. if not finished_within_time:
  100. self.move_base.cancel_goal()
  101. rospy.loginfo("Timed out achieving goal")
  102. else:
  103. # We made it!
  104. state = self.move_base.get_state()
  105. if state == GoalStatus.SUCCEEDED:
  106. rospy.loginfo("Goal succeeded!")
  107.  
  108. def init_markers(self):
  109. # Set up our waypoint markers
  110. marker_scale = 0.2
  111. marker_lifetime = # is forever
  112. marker_ns = 'waypoints'
  113. marker_id =
  114. marker_color = {'r': 1.0, 'g': 0.7, 'b': 1.0, 'a': 1.0}
  115.  
  116. # Define a marker publisher.
  117. self.marker_pub = rospy.Publisher('waypoint_markers', Marker, queue_size=)
  118.  
  119. # Initialize the marker points list.
  120. self.markers = Marker()
  121. self.markers.ns = marker_ns
  122. self.markers.id = marker_id
  123. self.markers.type = Marker.CUBE_LIST
  124. self.markers.action = Marker.ADD
  125. self.markers.lifetime = rospy.Duration(marker_lifetime)
  126. self.markers.scale.x = marker_scale
  127. self.markers.scale.y = marker_scale
  128. self.markers.color.r = marker_color['r']
  129. self.markers.color.g = marker_color['g']
  130. self.markers.color.b = marker_color['b']
  131. self.markers.color.a = marker_color['a']
  132.  
  133. self.markers.header.frame_id = 'odom'
  134. self.markers.header.stamp = rospy.Time.now()
  135. self.markers.points = list()
  136.  
  137. def shutdown(self):
  138. rospy.loginfo("Stopping the robot...")
  139. # Cancel any active goals
  140. self.move_base.cancel_goal()
  141. rospy.sleep()
  142. # Stop the robot
  143. self.cmd_vel_pub.publish(Twist())
  144. rospy.sleep()
  145.  
  146. if __name__ == '__main__':
  147. try:
  148. MoveBaseSquare()
  149. except rospy.ROSInterruptException:
  150. rospy.loginfo("Navigation test finished.")

使用move_base导航 ---13的更多相关文章

  1. 利用move_base导航--42

    摘要: 原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 各位博友好长时间又没有写博客了,突然发现上班和在学校是不一样的,在公司的却没有时间写博客了,不过 ...

  2. 多个精美的导航样式web2.0源码

    效果体验:http://keleyi.com/keleyi/phtml/divcss/6.htm 兼容多浏览器,例如IE,Chrome,火狐 等. 完整代码,保存到htm文件打开也可以查看效果: &l ...

  3. javascript权威指南第13章 事件示例代码

    html 部分 <!DOCTYPE html> <html> <head> <title>Event Bubling Example</title ...

  4. 企业IT管理员IE11升级指南【9】—— IE10与IE11的功能对比

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  5. ROS--导航、路径规划和SLAM

    一.用move_base导航走正方形 1. roscore 2.执行 roslaunch rbx1_bringup fake_turtlebot.launch 然后 roslaunch rbx1_na ...

  6. 前端组件库 - 搭建web app常用的样式/组件等收集列表(移动优先)

    0. 前端自动化(Workflow) 前端构建工具 Webpack - module bundler Yeoman - a set of tools for automating developmen ...

  7. MVC官方教程索引

    1.MVC教程首页http://www.asp.net/learn/mvc/?lang=cs 2.MVC概况2.1创建一个基于数据库的"电影"web应用http://www.asp ...

  8. Javascript导航菜单13则

    来源:http://www.noupe.com/ajax/13-awesome-java-script-css-menu.html翻译:http://parandroid.com下面为你准备了13个利 ...

  9. iOS开发笔记13:顶部标签式导航栏及下拉分类菜单

    当内容及分类较多时,往往采用顶部标签式导航栏,例如网易新闻客户端的顶部分类导航,最近刚好有这样的应用场景,参考网络上一些demo,实现了这种导航效果,记录一些要点. 效果图(由于视频转GIF掉帧,滑动 ...

随机推荐

  1. WP8.1 Study12:文件压缩与Known Folder(包含SD卡操作)

    一.文件压缩 当应用程序保存和加载数据,它可以使用压缩. 1.使用 Windows.Storage.Compression.Compressor 压缩,获得一个Compressor stream. v ...

  2. Session初识

    web服务器没有短期记忆,所以需要使用session来跟踪用户的整个会话活动.会话管理有3种解决方案: 1)使用隐藏域(很少使用) 在显示页面中使用隐藏域来保存会话ID.例如,在JSP中将input标 ...

  3. 用Qt实现简单的视频播放器

    ui 在.pro文件中添加 QT +=phonon 头文件 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> ...

  4. 自定义ImageView

    package com.example.myimageview; import android.content.Context;import android.graphics.Bitmap;impor ...

  5. 压力测试工具——Galting

    为什么要写Gatling呢?网上已经有一些介绍Gatling的好文章了,比如两位TW同事的文章,可以看这里(我知道Gatling也是因为这位作者介绍的),还有这里.主要是因为最近在使用Gatling做 ...

  6. Chrome 应用推荐 - 下载管理扩展: Chrono

    地址:http://goo.gl/JVdxvg Chrono下载管理器让你轻松高效地管理Chrome浏览器中的下载任务.Chrono与Chrome浏览器紧密地整合在一起,如菜单.工具栏支持等等.Chr ...

  7. SharePoint 2013 开发——SharePoint APP介绍

     博客地址:http://blog.csdn.net/FoxDave 新的APP模型让我们能够创建看起来像是SharePoint的一部分的应用程序,但是它完全运行在独立于SharePoint服务器 ...

  8. Mac下SVN服务器环境的搭建和配置(除展示图片外,所有命令在Linux/Unix下适用)

    这几天领导没有安排工作,闲着没事就想把自己这两年做iOS开发时感觉知识有欠缺的地方想好好深入地补习一下,昨天和今天就计划好好学习下SVN和git的从创建和到原理,到命令,到界面的使用.一不小心被另一领 ...

  9. c#图像处理入门(-bitmap类和图像像素值获取方法) 转

    一.Bitmap类 Bitmap对象封装了GDI+中的一个位图,此位图由图形图像及其属性的像素数据组成.因此Bitmap是用于处理由像素数据定义的图像的对象.该类的主要方法和属性如下: 1. GetP ...

  10. hdu1505 dp

    //Accepted 5196 KB 109 ms //类似hdu1506 //输入数据的格式没有明确的限制 //可能出现以下情况 //5 5 //R //F //F F F //F F F F F ...