ROS仿真多点导航

仿真环境启动:

1、启动并进入到相应环境:

roscar@roscar-virtual-machine:~/artcar_simulation$
启动gazebo环境:

roslaunch artcar_gazebo artcar_gazebo.launch 

启动move_base:

roslaunch artcar_nav artcar_move_base.launch

获取点位:

 rostopic echo /move_base_sile/goal 

在这里插入图片描述

获取点位

roscar@roscar-virtual-machine:~/artcar_simulation/src$ rostopic echo /move_base_simple/goal 
WARNING: no messages received and simulated time is active.
Is /clock being published?
header: seq: 0stamp: secs: 405nsecs: 141000000frame_id: "odom"
pose: position: x: 5.21420097351y: -2.07076597214z: 0.0orientation: x: 0.0y: 0.0z: -0.69109139328w: 0.722767380375
---
header: seq: 1stamp: secs: 422nsecs:  52000000frame_id: "odom"
pose: position: x: 3.50902605057y: -5.78046607971z: 0.0orientation: x: 0.0y: 0.0z: 0.999777096296w: 0.0211129752124
---

配置多点导航功能

#!/usr/bin/env python  
import rospy  
import actionlib  
import collections
from actionlib_msgs.msg import *  
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped, Point, Quaternion, Twist  
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal  
from random import sample  
from math import pow, sqrt  class MultiNav():  def __init__(self):  rospy.init_node('MultiNav', anonymous=True)  rospy.on_shutdown(self.shutdown)  # How long in seconds should the robot pause at each location?  self.rest_time = rospy.get_param("~rest_time", 10)  # Are we running in the fake simulator?  self.fake_test = rospy.get_param("~fake_test", False)  # Goal state return values  goal_states = ['PENDING', 'ACTIVE', 'PREEMPTED','SUCCEEDED',  'ABORTED', 'REJECTED','PREEMPTING', 'RECALLING',   'RECALLED','LOST']  # Set up the goal locations. Poses are defined in the map frame.  # An easy way to find the pose coordinates is to point-and-click  # Nav Goals in RViz when running in the simulator.  # Pose coordinates are then displayed in the terminal  # that was used to launch RViz.  locations = collections.OrderedDict()  locations['point-1'] = Pose(Point(5.21, -2.07, 0.00), Quaternion(0.000, 0.000, -0.69, 0.72)) locations['point-2'] = Pose(Point(3.50, -5.78, 0.00), Quaternion(0.000, 0.000, 0.99, 0.021))#locations['point-3'] = Pose(Point(-6.95, 2.26, 0.00), Quaternion(0.000, 0.000, 0.000, 1.000))#locations['point-4'] = Pose(Point(-6.50, 2.04, 0.00), Quaternion(0.000, 0.000, 0.000, 1.000))# Publisher to manually control the robot (e.g. to stop it)  self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=5)  # Subscribe to the move_base action server  self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)  rospy.loginfo("Waiting for move_base action server...")  # Wait 60 seconds for the action server to become available  self.move_base.wait_for_server(rospy.Duration(10))  rospy.loginfo("Connected to move base server")  # A variable to hold the initial pose of the robot to be set by the user in RViz  initial_pose = PoseWithCovarianceStamped()  # Variables to keep track of success rate, running time, and distance traveled  n_locations = len(locations)  n_goals = 0  n_successes = 0  i = 0  distance_traveled = 0  start_time = rospy.Time.now()  running_time = 0  location = ""  last_location = ""  # Get the initial pose from the user  rospy.loginfo("Click on the map in RViz to set the intial pose...")  rospy.wait_for_message('initialpose', PoseWithCovarianceStamped)  self.last_location = Pose()  rospy.Subscriber('initialpose', PoseWithCovarianceStamped, self.update_initial_pose) keyinput = int(input("Input 0 to continue,or reget the initialpose!\n"))while keyinput != 0:rospy.loginfo("Click on the map in RViz to set the intial pose...")  rospy.wait_for_message('initialpose', PoseWithCovarianceStamped)  rospy.Subscriber('initialpose', PoseWithCovarianceStamped, self.update_initial_pose) rospy.loginfo("Press y to continue,or reget the initialpose!")keyinput = int(input("Input 0 to continue,or reget the initialpose!"))# Make sure we have the initial pose  while initial_pose.header.stamp == "":  rospy.sleep(1)  rospy.loginfo("Starting navigation test")  # Begin the main loop and run through a sequence of locations  for location in locations.keys():  rospy.loginfo("Updating current pose.")  distance = sqrt(pow(locations[location].position.x  - initial_pose.pose.pose.position.x, 2) +  pow(locations[location].position.y -  initial_pose.pose.pose.position.y, 2))  initial_pose.header.stamp = ""  # Store the last location for distance calculations  last_location = location  # Increment the counters  i += 1  n_goals += 1  # Set up the next goal location  self.goal = MoveBaseGoal()  self.goal.target_pose.pose = locations[location]  self.goal.target_pose.header.frame_id = 'map'  self.goal.target_pose.header.stamp = rospy.Time.now()  # Let the user know where the robot is going next  rospy.loginfo("Going to: " + str(location))  # Start the robot toward the next location  self.move_base.send_goal(self.goal)  # Allow 5 minutes to get there  finished_within_time = self.move_base.wait_for_result(rospy.Duration(300))  # Check for success or failure  if not finished_within_time:  self.move_base.cancel_goal()  rospy.loginfo("Timed out achieving goal")  else:  state = self.move_base.get_state()  if state == GoalStatus.SUCCEEDED:  rospy.loginfo("Goal succeeded!")  n_successes += 1  distance_traveled += distance  else:  rospy.loginfo("Goal failed with error code: " + str(goal_states[state]))  # How long have we been running?  running_time = rospy.Time.now() - start_time  running_time = running_time.secs / 60.0  # Print a summary success/failure, distance traveled and time elapsed  rospy.loginfo("Success so far: " + str(n_successes) + "/" +  str(n_goals) + " = " + str(100 * n_successes/n_goals) + "%")  rospy.loginfo("Running time: " + str(trunc(running_time, 1)) +  " min Distance: " + str(trunc(distance_traveled, 1)) + " m")  rospy.sleep(self.rest_time)  def update_initial_pose(self, initial_pose):  self.initial_pose = initial_pose  def shutdown(self):  rospy.loginfo("Stopping the robot...")  self.move_base.cancel_goal()  rospy.sleep(2)  self.cmd_vel_pub.publish(Twist())  rospy.sleep(1)  
def trunc(f, n):  # Truncates/pads a float f to n decimal places without rounding  slen = len('%.*f' % (n, f))  return float(str(f)[:slen])  if __name__ == '__main__':  try:  MultiNav()  rospy.spin()  except rospy.ROSInterruptException:  rospy.loginfo("AMCL navigation test finished.")  

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/12711.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

3D数字化技术如何改变汽车行业?

近年来,新能源汽车行业加速发展,新车型密集发布,汽车保有量和车龄的增加,也同时点燃了汽车后市场的增长引擎。对于车企而言,如何全方面优化汽车从研发、生产、售后到营销的各个环节,以便适应快速变化的市场…

中文域名和英文域名有什么区别?中文域名有哪些优势?

作为企业网站的重要标识,域名在数字化时代扮演着重要角色。而随着中国互联网的快速发展,中文域名也逐渐崭露头角,受到国内企业和用户的关注。本文国科云作为中国科学院控股有限公司旗下的域名管理品牌,简单为大家介绍下中文域名和…

使用make_blobs生成数据并使用KNN机器学习算法进行分类和预测以及可视化

生成数据 使用make_blobs生成数据并使用matplotlib进行可视化 完整代码: from sklearn.datasets import make_blobs # KNN 分类器 from sklearn.neighbors import KNeighborsClassifier # 画图工具 import matplotlib.pyplot as plt # 数据集拆分工具 from sklea…

【代码随想录】链表

2024.5.11-2024.5.15 移除链表元素 #判断头节点是否空,#并且头节点为要删除的值,头节点向后移while head and head.valval:headhead.nextif not head: returncurhead#当前指针指向的下一个元素为val,当前指针指向下一个的下一个#否则,当前指…

Win7远程桌面连接不上:原因及专业解决方案

Win7远程桌面连接作为一种方便的工具,使得用户可以从一台计算机远程访问和操作另一台计算机。然而,有时用户可能会遇到Win7远程桌面连接不上的情况,这可能是由于多种原因导致的。 一、原因分析 1. 网络设置问题:确保计算机与远程…

Java 语言的特点分析及应用

Java语言自问世以来,因其独特的设计理念和广泛的应用领域,成为了编程语言中的一颗璀璨明星。以下是对Java语言特点的详细分析及其实际应用场景,希望能帮助面试者更好地理解和掌握Java的优势。 1. 简单易学 Java的语法简单,类似于…

可用在vue自动导入的插件unplugin-auto-import

在大多数vue3开发中,基本所有页面都会引用vue3 componsition api,如下代码 想这种vue3 架构中自带的api,如果在全局配置一下的话,就可以减少一部分代码量,只是在代码编译的时候,会添加相应的引用&#xff…

【Stable Diffusion】 训练方法篇

一、四种模型训练方法简介 Stable Diffusion 有四种训练模型的方法:Textual Inversion、Hypernetwork、LoRA 和 Dreambooth 。它们的训练方法存在一定差异,我们可以通过下面对比来评估使用哪种训练方式最适合你的项目。 如果你知道模型中已经可以产生你…

企业架构系统之-IT系统建设如何做好技术选型

背景 近日有幸与行业同仁交流工作心得,在讨论中,他们提到一个平时工作当中我们都会遇到和经历的一个问题:作为架构师,在日常工作中应如何进行技术选型?面对众多框架和组件中,我们又应如何选择,…

Postgresql源码(128)深入分析JIT中的函数内联llvm_inline

相关 《Postgresql源码(127)投影ExecProject的表达式执行分析》 《LLVM的ThinLTO编译优化技术在Postgresql中的应用》 《LLVM(5)ORC实例分析》 1 JIT优化效果 create table t1(i int primary key, j int, k int); insert into t1…

Google IO 2024有哪些看点呢?

有了 24 小时前 OpenAI 用 GPT-4o 带来的炸场之后,今年的 Google I/O 还未开始,似乎就被架在了一个相当尴尬的地位,即使每个人都知道 Google 将发布足够多的新 AI 内容,但有了 GPT-4o 的珠玉在前,即使是 Google 也不得…

秋招算法——AcWing101——拦截导弹

文章目录 题目描述思路分析实现源码分析总结 题目描述 思路分析 目前是有一个笨办法,就是创建链表记录每一个最长下降子序列所对应的节点的链接,然后逐个记录所有结点的访问情况,直接所有节点都被访问过。这个方法不是很好,因为需…

一件代发海外仓系统解决方案:提升效率,海外仓管理更轻松

现在跨境电商的发展真的太快了,很多商家也开始转战跨境,希望能打开国际市场。作为跨境电商非常重要的一环,海外仓的需求自然也越来越大。 随着海外仓市场的火爆,越来越多的海外仓企业都意识到,提升海外仓运营的效率变得…

互联网摸鱼日报(2024-05-15)

互联网摸鱼日报(2024-05-15) 36氪新闻 宇树发布 Unitree G1人形机器人,9.9万元起 | 最前线 腾讯游戏恢复流水增长,金融科技与企业服务收入占比持续超三成 好利来推的茶饮副牌“好茶”,有点霸王茶姬的感觉 OpenAI全部的秘密,藏…

消防物资存储|基于SSM+vue的消防物资存储系统的设计与实现(源码+数据库+文档)

消防物资存储系统 目录 基于SSM+vue的消防物资存储系统的设计与实现 一、前言 二、系统设计 三、系统功能设计 1用户功能模块 2 管理员功能模块 四、数据库设计 五、核心代码 六、论文参考 七、最新计算机毕设选题推荐 八、源码获取: 博主介…

动规解决01背包/完全背包精讲

还不会用动态规划解决01背包/完全背包?看这一篇文章就够了! 首先我们要明白什么是01背包和完全背包。 背包问题总体问法就是: 你有一个背包,最多能容纳的体积是V。 现在有n个物品,第i个物品的体积为vi​ ,价值为wi​…

干货教程【AI篇】| Topaz Video Enhance AI超好用的视频变清晰变流畅的AI工具,免费本地使用

关注文章底部公众号,回复关键词【tvea】即可获取Topaz Video Enhance AI。 一款非常好用的视频变清晰变流畅的AI工具,即提高视频的分辨率和FPS,亲测效果非常nice!! 免费!免费!免费&#xff01…

基于Sentinel-1遥感数据的水体提取

本文利用SAR遥感图像进行水体信息的提取,相比光学影像,SAR图像不受天气影响,在应急情况下应用最多,针对水体,在发生洪涝时一般天气都是阴雨天,云较多,光学影像质量较差,基本上都是利…

【案例】使用Vue实现标题项元素上下移动

效果图 效果说明 每一组数据只能在对应的二级类目中进行上下移动,当点击上移图标的时候【左边的】会将当前元素与上一个元素交换位置,当点击的元素为该组的第一个元素时,将提示已经是第一项了并且不能进行移动;当点击下移图标的时…

java中if-else的代替写法是什么?

在Java中,有一种常见的if-else的替代写法是使用三元运算符(Ternary Operator)或者switch语句。下面是这两种替代写法的示例: 三元运算符:result (condition) ? value1 : value2;这表示如果条件(condition)为真&…