当前位置: 首页 > 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证件识别中的身份证识别接口

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

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

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

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑:陈萍萍的公主一点人工一点智能 未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战,在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...

设计模式和设计原则回顾

设计模式和设计原则回顾 23种设计模式是设计原则的完美体现,设计原则设计原则是设计模式的理论基石, 设计模式 在经典的设计模式分类中(如《设计模式:可复用面向对象软件的基础》一书中),总共有23种设计模式,分为三大类: 一、创建型模式(5种) 1. 单例模式(Sing…...

逻辑回归:给不确定性划界的分类大师

想象你是一名医生。面对患者的检查报告(肿瘤大小、血液指标),你需要做出一个**决定性判断**:恶性还是良性?这种“非黑即白”的抉择,正是**逻辑回归(Logistic Regression)** 的战场&a…...

基于ASP.NET+ SQL Server实现(Web)医院信息管理系统

医院信息管理系统 1. 课程设计内容 在 visual studio 2017 平台上,开发一个“医院信息管理系统”Web 程序。 2. 课程设计目的 综合运用 c#.net 知识,在 vs 2017 平台上,进行 ASP.NET 应用程序和简易网站的开发;初步熟悉开发一…...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

Linux简单的操作

ls ls 查看当前目录 ll 查看详细内容 ls -a 查看所有的内容 ls --help 查看方法文档 pwd pwd 查看当前路径 cd cd 转路径 cd .. 转上一级路径 cd 名 转换路径 …...

Springcloud:Eureka 高可用集群搭建实战(服务注册与发现的底层原理与避坑指南)

引言:为什么 Eureka 依然是存量系统的核心? 尽管 Nacos 等新注册中心崛起,但金融、电力等保守行业仍有大量系统运行在 Eureka 上。理解其高可用设计与自我保护机制,是保障分布式系统稳定的必修课。本文将手把手带你搭建生产级 Eur…...

微服务商城-商品微服务

数据表 CREATE TABLE product (id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 商品id,cateid smallint(6) UNSIGNED NOT NULL DEFAULT 0 COMMENT 类别Id,name varchar(100) NOT NULL DEFAULT COMMENT 商品名称,subtitle varchar(200) NOT NULL DEFAULT COMMENT 商…...

Rapidio门铃消息FIFO溢出机制

关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系,以下是深入解析: 门铃FIFO溢出的本质 在RapidIO系统中,门铃消息FIFO是硬件控制器内部的缓冲区,用于临时存储接收到的门铃消息(Doorbell Message)。…...

Pinocchio 库详解及其在足式机器人上的应用

Pinocchio 库详解及其在足式机器人上的应用 Pinocchio (Pinocchio is not only a nose) 是一个开源的 C 库,专门用于快速计算机器人模型的正向运动学、逆向运动学、雅可比矩阵、动力学和动力学导数。它主要关注效率和准确性,并提供了一个通用的框架&…...