ros(Melodic)记录

news/2025/2/22 10:41:28

目录

  • 写在前面
  • 安装ros melodic
  • 例程
    • turtlesim
    • TF
  • 点云
  • 命令
    • 编译
  • 消息
  • 资料
  • 参考

写在前面

1、本文内容
ros入门基础
2、平台
windows10, vmware workstation, ubuntu1804
3、转载请注明出处:
https://blog.csdn.net/qq_41102371/article/details/125223367

ros_melodic_9">安装ros melodic

安装虚拟机ubuntu1804
安装ros Melodic,参考官方教程
http://wiki.ros.org/melodic/Installation/Ubuntu

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

sudo apt install curl # if you haven't already installed curl

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

sudo apt update

sudo apt install ros-melodic-desktop-full

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

sudo rosdep init
#rosdep update会失败,网上可找到解决方法https://blog.csdn.net/zbw1185/article/details/123807654
rosdep update

例程

turtlesim

启动roscore

roscore

在这里插入图片描述
打开新的命令行终端

rosrun turtlesim turtlesim_node

在这里插入图片描述

键盘控制小乌龟,打开新的终端输入

rosrun turtlesim turtle_teleop_key

使用上下左右键控制乌龟运动,注意要在输入命令的终端上使用上下左右才行
在这里插入图片描述

计算图,打开新的终端

rqt_graph

在这里插入图片描述
(去掉debug勾选后)
在这里插入图片描述

查看系统节点

rosnode list

在这里插入图片描述
查看节点信息

rosnode info /turtlesim

在这里插入图片描述
查看当前话题

rostopic list

在这里插入图片描述
发布话题控制海龟运动
只发布一次

rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.0"

# 每秒发布10次,海龟一直运动
rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.0"

在这里插入图片描述
查看消息结构

rosmsg show geometry_msgs/Twist

在这里插入图片描述
查看服务

rosservice list

产生新的海龟,坐标(5,5,),名称turtle2

rosservice call /spawn "x: 5.0
y: 5.0
theta: 0.0
name: 'turtle2'"

在这里插入图片描述控制第二个海龟运动

rostopic pub -r 10 /turtle2/cmd_vel geometry_msgs/Twist "linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 1.0"

在这里插入图片描述

话题记录,记录当前的话题数据到文件,以后可以复现该话题


上下左右控制海龟动几下,然后在rosbag record的窗口ctrl+c结束记录
在这里插入图片描述

复现之前的记录
关掉之前的turtlesim,重新打开一个turtlesim,然后复现运动

rosbag play cmd_record.bag

在这里插入图片描述

TF

ROS学习–轻松使用tf https://blog.csdn.net/start_from_scratch/article/details/50762293

点云

rviz点云显示,alpha参数:
http://wiki.ros.org/rviz/DisplayTypes/PointCloud

命令

# 查看当前话题列表
rostopic list
# 查看话题信息
rostopic info /tutlesim
rosmsg show sensor_msgs/PointCloud

在这里插入图片描述

# 话题记录,会记录在cmd_record.bag文件里面
rosbag record -a -O cmd_record
# 话题复现
rosbag play cmed_record.bag

编译

catkin buid
https://blog.csdn.net/dzhongjie/article/details/83868684
catkin clean

#清理某个包
catkin clean pkgname

https://zhuanlan.zhihu.com/p/399753815
catkin文档
https://catkin-tools.readthedocs.io/en/latest/verbs/catkin_clean.html

消息

wait_for_massage
https://vimsky.com/examples/detail/python-method-rospy.wait_for_message.html

抛出异常处理:
c++:
http://wiki.ros.org/roscpp/Overview/Exceptions
https://www.ncnynl.com/archives/201702/1302.html
roscpp所有的异常都继承基类ros::Exception

try{
;
}
catch(ros::Exception &ex){
;
}

python:
http://wiki.ros.org/rospy/Overview/Exceptions

try:
	...
except Exception as e:
	rospy.logerr(e.args)

python取消消息订阅
https://stackoverflow.com/questions/38487816/unsubscribing-from-ros-topic-python

sub = rospy.subscriber("/cameras/left_hand_camera/image",Image,self.callback_viewer)
sub.unregister()

资料

ros cpp 教程 http://wiki.ros.org/roscpp_tutorials/Tutorials
ros API https://wiki.ros.org/APIs

参考

古月居ros教程:
https://www.bilibili.com/video/BV1zt411G7Vn

如有错漏,敬请指正
--------------------------------------------------------------------------------------------诺有缸的高飞鸟202206


http://www.niftyadmin.cn/n/1081965.html

相关文章

移动开发中的通信架构(二)

先罗列一小段代码,这一小段代码代表了通信框架中发送请求的基本方式,读者可以根据这段代码,分析整个请求过程: /** * 典型使用方式: * * StructRequest output new StructRequest(GameConst.COMM_PRICECOUNT_DATA);//…

ubuntu1804安装多版本pcl

目录写在前面准备安装依赖编译源码pcl1.8pcl1.10使用参考完写在前面 1、本文内容 ubuntu1804安装多版本pcl(pcl1.8以上版本) 2、平台 ubuntu1804 3、转载请注明出处: https://blog.csdn.net/qq_41102371/article/details/125600181 准备 创建pcl文件夹 mkdir pc…

移动开发中的通信架构(三)

前面两篇文章讲述了框架的大体情况和请求的封装,这篇文章讲述请求的发送。在本框架中,请求生成以后,并不是马上发送,而是加入一个请求列表。然后有一个线程来维护这个请求列表。 下面来具体分析,从移动开发中的通信架构…

本博客资源链接

说明 本链接是博客里面的代码以及资源链接,由于百度盘的链接经常失效,每次一改就要改全部博客,所以统一放这里,失效请发我私信 链接:https://pan.baidu.com/s/1iy1q_PaRi_0wqY6QMPQkwQ 提取码:6zcy

移动开发中的通信架构(四)

这篇文章讲解真正的网络请求类HttpClient,它负责打开网络链接,获取数据,把数据存放于一个字节数组,让Response解析。 以下是代码: package app.http; import java.io.ByteArrayOutputStream; import java.io.IOExcept…

移动开发中的通信架构(五)

《移动开发中的通信架构》系列文章终于写完了,我整整花了一周多时间才搞定。哎,自己会一样东西是一件事情,然后描述一件东西,又是一件事情。系列文章在发布的时候,又改了大半天。文章中难免有不足的地方,希…

使用vscode debug ros程序(A-LOAM)

目录写在前面源码vscode配置task配置launchdebug单个节点调试参考完写在前面 1、本文内容 使用vscode单步调试A-LOAM源码 2、平台 ubuntu1804, ros melodic, vscode, vscode ros插件 3、转载请注明出处: https://blog.csdn.net/qq_41102371/article/details/12565…

ros多客户端请求服务

目录写在前面代码使用参考写在前面 1、本文内容 一个节点的多个服务被请求时产生消息阻塞,使用多线程来解决 2、平台 ubuntu1804, ros melodic 3、转载请注明出处: https://blog.csdn.net/qq_41102371/article/details/125846107 代码 Service.srv s…