使用move_base导航 ---13
摘要: 原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/
我们现在准备用move_base简单的移动机器人记住,一个“pose”在ros的意思是一个位置和方向。
1.首先启动turtlebot机器人。
roslaunch rbx1_bringup fake_turtlebot.launch
2.在另一个终端运行:
roslaunch rbx1_nav fake_move_base_blank_map.launch
3.打开rviz视图查看机器人。
rosrun rviz rviz -d `rospack find rbx1_nav`/nav.rviz
4.运行move_base_square.py脚本移动机器人。
rosrun rbx1_nav move_base_square.py
5.rviz视图如下:
6.rqt_graph节点框图如下:
7.节点move_base_square.py代码如下:
#!/usr/bin/env python import rospy
import actionlib
from actionlib_msgs.msg import *
from geometry_msgs.msg import Pose, Point, Quaternion, Twist
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from tf.transformations import quaternion_from_euler
from visualization_msgs.msg import Marker
from math import radians, pi class MoveBaseSquare():
def __init__(self):
rospy.init_node('nav_test', anonymous=False) rospy.on_shutdown(self.shutdown) # How big is the square we want the robot to navigate?
square_size = rospy.get_param("~square_size", 1.0) # meters # Create a list to hold the target quaternions (orientations)
quaternions = list() # First define the corner orientations as Euler angles
euler_angles = (pi/, pi, *pi/, ) # Then convert the angles to quaternions
for angle in euler_angles:
q_angle = quaternion_from_euler(, , angle, axes='sxyz')
q = Quaternion(*q_angle)
quaternions.append(q) # Create a list to hold the waypoint poses
waypoints = list() # Append each of the four waypoints to the list. Each waypoint
# is a pose consisting of a position and orientation in the map frame.
waypoints.append(Pose(Point(square_size, 0.0, 0.0), quaternions[]))
waypoints.append(Pose(Point(square_size, square_size, 0.0), quaternions[]))
waypoints.append(Pose(Point(0.0, square_size, 0.0), quaternions[]))
waypoints.append(Pose(Point(0.0, 0.0, 0.0), quaternions[])) # Initialize the visualization markers for RViz
self.init_markers() # Set a visualization marker at each waypoint
for waypoint in waypoints:
p = Point()
p = waypoint.position
self.markers.points.append(p) # Publisher to manually control the robot (e.g. to stop it, queue_size=)
self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=) # Subscribe to the move_base action server
self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction) rospy.loginfo("Waiting for move_base action server...") # Wait seconds for the action server to become available
self.move_base.wait_for_server(rospy.Duration()) rospy.loginfo("Connected to move base server")
rospy.loginfo("Starting navigation test") # Initialize a counter to track waypoints
i = # Cycle through the four waypoints
while i < and not rospy.is_shutdown():
# Update the marker display
self.marker_pub.publish(self.markers) # Intialize the waypoint goal
goal = MoveBaseGoal() # Use the map frame to define goal poses
goal.target_pose.header.frame_id = 'map' # Set the time stamp to "now"
goal.target_pose.header.stamp = rospy.Time.now() # Set the goal pose to the i-th waypoint
goal.target_pose.pose = waypoints[i] # Start the robot moving toward the goal
self.move(goal) i += def move(self, goal):
# Send the goal pose to the MoveBaseAction server
self.move_base.send_goal(goal) # Allow minute to get there
finished_within_time = self.move_base.wait_for_result(rospy.Duration()) # If we don't get there in time, abort the goal
if not finished_within_time:
self.move_base.cancel_goal()
rospy.loginfo("Timed out achieving goal")
else:
# We made it!
state = self.move_base.get_state()
if state == GoalStatus.SUCCEEDED:
rospy.loginfo("Goal succeeded!") def init_markers(self):
# Set up our waypoint markers
marker_scale = 0.2
marker_lifetime = # is forever
marker_ns = 'waypoints'
marker_id =
marker_color = {'r': 1.0, 'g': 0.7, 'b': 1.0, 'a': 1.0} # Define a marker publisher.
self.marker_pub = rospy.Publisher('waypoint_markers', Marker, queue_size=) # Initialize the marker points list.
self.markers = Marker()
self.markers.ns = marker_ns
self.markers.id = marker_id
self.markers.type = Marker.CUBE_LIST
self.markers.action = Marker.ADD
self.markers.lifetime = rospy.Duration(marker_lifetime)
self.markers.scale.x = marker_scale
self.markers.scale.y = marker_scale
self.markers.color.r = marker_color['r']
self.markers.color.g = marker_color['g']
self.markers.color.b = marker_color['b']
self.markers.color.a = marker_color['a'] self.markers.header.frame_id = 'odom'
self.markers.header.stamp = rospy.Time.now()
self.markers.points = list() def shutdown(self):
rospy.loginfo("Stopping the robot...")
# Cancel any active goals
self.move_base.cancel_goal()
rospy.sleep()
# Stop the robot
self.cmd_vel_pub.publish(Twist())
rospy.sleep() if __name__ == '__main__':
try:
MoveBaseSquare()
except rospy.ROSInterruptException:
rospy.loginfo("Navigation test finished.")
使用move_base导航 ---13的更多相关文章
- 利用move_base导航--42
摘要: 原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 各位博友好长时间又没有写博客了,突然发现上班和在学校是不一样的,在公司的却没有时间写博客了,不过 ...
- 多个精美的导航样式web2.0源码
效果体验:http://keleyi.com/keleyi/phtml/divcss/6.htm 兼容多浏览器,例如IE,Chrome,火狐 等. 完整代码,保存到htm文件打开也可以查看效果: &l ...
- javascript权威指南第13章 事件示例代码
html 部分 <!DOCTYPE html> <html> <head> <title>Event Bubling Example</title ...
- 企业IT管理员IE11升级指南【9】—— IE10与IE11的功能对比
企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...
- ROS--导航、路径规划和SLAM
一.用move_base导航走正方形 1. roscore 2.执行 roslaunch rbx1_bringup fake_turtlebot.launch 然后 roslaunch rbx1_na ...
- 前端组件库 - 搭建web app常用的样式/组件等收集列表(移动优先)
0. 前端自动化(Workflow) 前端构建工具 Webpack - module bundler Yeoman - a set of tools for automating developmen ...
- MVC官方教程索引
1.MVC教程首页http://www.asp.net/learn/mvc/?lang=cs 2.MVC概况2.1创建一个基于数据库的"电影"web应用http://www.asp ...
- Javascript导航菜单13则
来源:http://www.noupe.com/ajax/13-awesome-java-script-css-menu.html翻译:http://parandroid.com下面为你准备了13个利 ...
- iOS开发笔记13:顶部标签式导航栏及下拉分类菜单
当内容及分类较多时,往往采用顶部标签式导航栏,例如网易新闻客户端的顶部分类导航,最近刚好有这样的应用场景,参考网络上一些demo,实现了这种导航效果,记录一些要点. 效果图(由于视频转GIF掉帧,滑动 ...
随机推荐
- php 判断是否 是手机访问
//判断是否属手机 function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_agents = Array(& ...
- 浏览器Firefox新标签页默认打开地址设置
1.地址栏输入about:config 2.找到browser.newtab.url 修改它的值为你想要的地址,如:https://www.baidu.com
- 戴文的Linux内核专题:05配置内核(1)
转自Linux中国 现在我们已经了解了内核,现在我们可以进入主要工作:配置并编译内核代码.配置内核代码并不会花费太长时间.配置工具会询问许多问题并且允许开发者配置内核的每个方面.如果你有不确定的问题或 ...
- “人少也能办大事”---K2 BPM老客户交流会
主题:固铂轮胎工作流项目分享-K2 SmartForm下的工作流快速开发 嘉宾:王彦(固铂轮胎IT资深经理) 国内业务规模越来越大,流程越来越复杂,跨部门跨组织的流程纸质审批非常复杂,内控的要求越来越 ...
- CCNA 4.14 TP Correction
All people seem to need data processing ( Application presentation session transport network data li ...
- Linux登陆和欢迎信息修改
edit file: /etc/issue,/etc/motd 这样还改不了,生成的脚本在目录/etc/update-motd.d/中: 假如要打开一个文本文件,可以修改10-help-text: ( ...
- Map-Reduce的工作机制
Mapper “Map-Reduce”的思想就是“分而治之” Mapper负责“分”,即把复杂的任务分解为若干个“简单的任务”而执行 “简单的任务”有几个意思:1.数据或计算规模相对于原任务要大大缩小 ...
- JDBC体会
1.把mysql-connector XXXX版本导入buildpath 2.通过DriverManager 的getConnection 方法获得一个Connnection引用,方法的参数是 url ...
- MongoDB 语法(转)
Mongod.exe 是用来连接到mongo数据库服务器的,即服务器端. Mongo.exe 是用来启动MongoDB shell的,即客户端. 其他文件: mongodump 逻辑备份工具. mon ...
- UVALive 4682 XOR Sum (trie)
题意:求一段连续的数字使得它们的异或和最大. 思路:首先利用前缀和求sum[i],这样求某段连续数字异或和最大就是求某两个j和i满足sum[i]^sum[j-1]最大,问题就变成了找两个数的异或最大. ...