当前位置: 首页 > news >正文

ROS 自动驾驶多点巡航

ROS 自动驾驶多点巡航:

1、首先创建工作空间:

基于我们的artca_ws;

2、创建功能包:

进入src目录,输入命令:

catkin_create_pkg point_pkg std_msgs rospy roscpp

test_pkg 为功能包名,后面两个是依赖;
在这里插入图片描述

3、创建python文件

我们通过vscode打开src下功能包:
创建 point.py:
在这里插入图片描述
代码内容写入 :

#!/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.")  

4、编译:

nano@nano-desktop:~/artcar_ws/src$ cd ..
nano@nano-desktop:~/artcar_ws$ catkin build 

在这里插入图片描述

5、案例实操;

启动小车并进入到相应环境:

(1)打开终端,启动底盘环境,输入如下命令:

$ roslaunch artcar_nav artcar_bringup.launch

(2)启动导航程序:

$ roslaunch artcar_nav artcar_move_base.launch

(3)启动RVIZ:

(4)获取点位:

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

(5)修改point.py文件中点位数据的位置:

在这里插入图片描述

(6 ) 然后开启终端执行:

nano@nano-desktop:~/artcar_ws/src/point_pkg/src$ ./point.py 

在这里插入图片描述

此时确定位置是否准确,准确的话,在此终端中输入:0
小车开始多点运行。

相关文章:

ROS 自动驾驶多点巡航

ROS 自动驾驶多点巡航: 1、首先创建工作空间: 基于我们的artca_ws; 2、创建功能包: 进入src目录,输入命令: catkin_create_pkg point_pkg std_msgs rospy roscpptest_pkg 为功能包名,后面两个是依赖&a…...

SQL学习,大厂面试真题(1):观看各个视频的平均完播率

各个视频的平均完播率 1、视频信息表 IDAuthorNameCategoryAgeStart Time1张三影视302024-01-01 7:00:002李四美食602024-01-01 7:00:003王麻子旅游902024-01-01 7:00:00 (video_id-视频ID, AuthorName-创作者, tag-类别标签, duration-视频时长(秒&…...

2023年全国大学生数学建模竞赛C题蔬菜类商品的自动定价与补货决策(含word论文和源代码资源)

文章目录 一、题目二、word版实验报告和源代码(两种获取方式) 一、题目 2023高教社杯全国大学生数学建模竞赛题目 C题 蔬菜类商品的自动定价与补货决策 在生鲜商超中,一般蔬菜类商品的保鲜期都比较短,且品相随销售时间的增加而…...

inpaint下载安装2024-inpaint软件安装包下载v5.0.6官网最新版附加详细安装步骤

Inpaint软件最新版是一款功能强大的图片去水印软件,这款软件拥有强大的智能算法,能够根据照片的背景为用户去除照片中的各种水印,并修补好去除水印后的图片。并且软件操作简单、界面清爽,即使是修图新手也能够轻松上手&#xff0c…...

分享三个仓库

Hello , 我是恒。大概有半个月没有发文章了,都写在文档里了 今天分享三个我开源的项目,比较小巧但是有用 主页 文档导航 Github地址: https://github.com/lmliheng/document 在线访问:http://document.liheng.work/ 里面有各种作者书写的文档&#xff…...

MacOS - 启动台多了个『卸载 Adobe Photoshop』

问题描述 今天安装好了 Adobe Ps,但是发现启动台多了个『卸载 Adobe Photoshop』强迫症又犯了,想把它干掉! 解决方案 打开访达 - 前往 - 资源库,搜索要卸载的名字就可以看到,然后移除到垃圾筐...

PHP 日期处理完全指南

PHP 日期处理完全指南 引言 在PHP开发中,日期和时间处理是一个常见且重要的任务。PHP提供了丰富的内置函数来处理日期和时间,包括日期的格式化、计算、解析等。本文将详细介绍PHP中日期处理的相关知识,帮助读者全面理解和掌握这一技能。 1. PHP日期函数基础 1.1 date()函…...

KVB:怎么样选择最优交易周期?

摘要 在金融交易中,周期的选择是影响交易成败的重要因素之一。不同的交易周期对应不同的市场环境和交易策略,选择合适的周期可以提高交易的成功率。本文将详细探讨交易中如何选择最优周期,包括短周期、中周期和长周期的特点及适用情况&#…...

前端面试题日常练-day69 【面试题】

题目 希望这些选择题能够帮助您进行前端面试的准备,答案在文末 TypeScript中,以下哪个关键字用于声明一个变量的类型为联合类型? a) union b) any c) all d) | 在TypeScript中,以下哪个符号用于声明一个变量的类型为对象类型&am…...

Java 解析xml文件-工具类

Java 解析xml文件-工具类 简述 Java解析xml文件,对应的Javabean是根据xml中的节点来创建,如SeexmlZbomord、SeexmlIdoc等等 工具类代码 import cn.hutool.core.io.FileUtil; import com.alibaba.cloud.commons.io.IOUtils; import com.seexml.bom.Se…...

PyQt5学习系列之新项目创建并使用widget

PyQt5学习系列之新项目创建并使用widget 前言报错新建项目程序完整程序总结 前言 新建项目,再使用ui转py,无论怎么样都打不开py文件,直接报错。 报错 Connected to pydev debugger (build 233.11799.298)新建项目程序 # Press ShiftF10 to…...

mtk8675 安卓端assert函数的坑

8675 安卓端, assert(pthread_mutex_init(&mutex_data_, &mattr) 0);用这行代码发现pthread_mutex_init函数没有被调用,反汇编发现不光没调用assert,pthread_mutex_init也没调用。直接pthread_mutex_init(&mutex_data_, &ma…...

编程入门笔记:从基础到进阶的探索之旅

编程入门笔记:从基础到进阶的探索之旅 编程,作为现代科技的基石,正日益渗透到我们生活的方方面面。对于初学者来说,掌握编程技能不仅有助于提升解决问题的能力,还能开启通往创新世界的大门。本篇文章将从四个方面、五…...

小规模自建 Elasticsearch 的部署及优化

本文将详细介绍如何在 CentOS 7 操作系统上部署并优化 Elasticsearch 5.3.0,以承载千万级后端服务的数据采集。要使用Elasticsearch至少需要三台独立的服务器,本文所用服务器配置为4核8G的ECS云服务器,其中一台作为 master + data 节点、一台作为 client + data 节点、最后一…...

MySQL 示例数据库大全

前言: 我们练习 SQL 时,总会自己创造一些测试数据或者网上找些案例来学习,其实 MySQL 官方提供了好几个示例数据库,在 MySQL 的学习、开发和实践中具有非常重要的作用,能够帮助初学者更好地理解和应用 MySQL 的各种功…...

VirtualBox、Centos7下安装docker后pull镜像问题、ftp上传文件问题

Docker安装篇(CentOS7安装)_docker 安装 centos7-CSDN博客 首先,安装docker可以根据这篇文章进行安装,安装完之后,我们就需要去通过docker拉取相关的服务镜像,然后安装相应的服务容器,比如我们通过docker来安装mysql,…...

链表 题目汇总

237. 删除链表中的节点...

grafana连接influxdb2.x做数据大盘

连接influxdb 展示数据 新建仪表盘 选择存储库 设置展示...

Java证件识别中的身份证识别接口

现如今,越来越多的互联网应用需要对身份证进行实名认证,但不知道大家有没有发现,从最初的手动录入身份证信息转变到了现在的图片上传自动识别呢?其实,这都是因为集成了身份证识别接口功能,今天,…...

迷你小风扇哪个品牌好?迷你小风扇前十名公开揭晓!

随着夏日的炎热袭来,迷你小风扇成为了许多人随身携带的清凉利器。无论是在办公室、户外活动,还是在旅行途中,迷你小风扇都以其小巧便携、强劲风力和持久续航的优势,迅速俘获了大批用户的喜爱。然而,市面上迷你小风扇品…...

Python:操作 Excel 折叠

💖亲爱的技术爱好者们,热烈欢迎来到 Kant2048 的博客!我是 Thomas Kant,很开心能在CSDN上与你们相遇~💖 本博客的精华专栏: 【自动化测试】 【测试经验】 【人工智能】 【Python】 Python 操作 Excel 系列 读取单元格数据按行写入设置行高和列宽自动调整行高和列宽水平…...

【大模型RAG】Docker 一键部署 Milvus 完整攻略

本文概要 Milvus 2.5 Stand-alone 版可通过 Docker 在几分钟内完成安装;只需暴露 19530(gRPC)与 9091(HTTP/WebUI)两个端口,即可让本地电脑通过 PyMilvus 或浏览器访问远程 Linux 服务器上的 Milvus。下面…...

React Native在HarmonyOS 5.0阅读类应用开发中的实践

一、技术选型背景 随着HarmonyOS 5.0对Web兼容层的增强,React Native作为跨平台框架可通过重新编译ArkTS组件实现85%以上的代码复用率。阅读类应用具有UI复杂度低、数据流清晰的特点。 二、核心实现方案 1. 环境配置 (1)使用React Native…...

渲染学进阶内容——模型

最近在写模组的时候发现渲染器里面离不开模型的定义,在渲染的第二篇文章中简单的讲解了一下关于模型部分的内容,其实不管是方块还是方块实体,都离不开模型的内容 🧱 一、CubeListBuilder 功能解析 CubeListBuilder 是 Minecraft Java 版模型系统的核心构建器,用于动态创…...

全志A40i android7.1 调试信息打印串口由uart0改为uart3

一,概述 1. 目的 将调试信息打印串口由uart0改为uart3。 2. 版本信息 Uboot版本:2014.07; Kernel版本:Linux-3.10; 二,Uboot 1. sys_config.fex改动 使能uart3(TX:PH00 RX:PH01),并让boo…...

VM虚拟机网络配置(ubuntu24桥接模式):配置静态IP

编辑-虚拟网络编辑器-更改设置 选择桥接模式,然后找到相应的网卡(可以查看自己本机的网络连接) windows连接的网络点击查看属性 编辑虚拟机设置更改网络配置,选择刚才配置的桥接模式 静态ip设置: 我用的ubuntu24桌…...

GitFlow 工作模式(详解)

今天再学项目的过程中遇到使用gitflow模式管理代码,因此进行学习并且发布关于gitflow的一些思考 Git与GitFlow模式 我们在写代码的时候通常会进行网上保存,无论是github还是gittee,都是一种基于git去保存代码的形式,这样保存代码…...

MySQL JOIN 表过多的优化思路

当 MySQL 查询涉及大量表 JOIN 时,性能会显著下降。以下是优化思路和简易实现方法: 一、核心优化思路 减少 JOIN 数量 数据冗余:添加必要的冗余字段(如订单表直接存储用户名)合并表:将频繁关联的小表合并成…...

深度学习之模型压缩三驾马车:模型剪枝、模型量化、知识蒸馏

一、引言 在深度学习中,我们训练出的神经网络往往非常庞大(比如像 ResNet、YOLOv8、Vision Transformer),虽然精度很高,但“太重”了,运行起来很慢,占用内存大,不适合部署到手机、摄…...

论文阅读:Matting by Generation

今天介绍一篇关于 matting 抠图的文章,抠图也算是计算机视觉里面非常经典的一个任务了。从早期的经典算法到如今的深度学习算法,已经有很多的工作和这个任务相关。这两年 diffusion 模型很火,大家又开始用 diffusion 模型做各种 CV 任务了&am…...