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

java网站开发是什么微信管理助手

java网站开发是什么,微信管理助手,大连建设工程信息网华宇凤凰城东侧市政管网配套工程,全球创新设计ROS2接口与自定义 引言1 ROS2自带接口1.1 ROS2通用标准消息包1.2 ROS2传感器消息包1.3 ROS2几何相关消息包 2 ROS2接口介绍2.1 常用CLI命令2.2 原始数据类型与包装类型 3 自定义接口示例3.1 接口定义3.2 自定义接口RCLPY 引言 笔者跟着鱼香ROS的ROS2学习之旅 学习参考&#xf…

ROS2接口与自定义

  • 引言
  • 1 ROS2自带接口
    • 1.1 ROS2通用标准消息包
    • 1.2 ROS2传感器消息包
    • 1.3 ROS2几何相关消息包
  • 2 ROS2接口介绍
    • 2.1 常用CLI命令
    • 2.2 原始数据类型与包装类型
  • 3 自定义接口示例
    • 3.1 接口定义
    • 3.2 自定义接口RCLPY

引言

笔者跟着鱼香ROS的ROS2学习之旅
学习参考:
【ROS2机器人入门到实战】
笔者的学习目录

  1. MOMO的鱼香ROS2(一)ROS2入门篇——从Ubuntu操作系统开启
  2. MOMO的鱼香ROS2(二)ROS2入门篇——ROS2初体验
  3. MOMO的鱼香ROS2(三)ROS2入门篇——ROS2第一个节点
  4. MOMO的鱼香ROS2(四)ROS2入门篇——ROS2节点通信之话题与服务

1 ROS2自带接口

接口其实是一种规范

1.1 ROS2通用标准消息包

ros2 interface package std_msgs
std_msgs/msg/String
std_msgs/msg/ByteMultiArray
std_msgs/msg/UInt16
std_msgs/msg/UInt64
std_msgs/msg/UInt8
std_msgs/msg/Int64MultiArray
std_msgs/msg/UInt32MultiArray
std_msgs/msg/UInt16MultiArray
std_msgs/msg/Float32MultiArray
std_msgs/msg/MultiArrayDimension
std_msgs/msg/Float64MultiArray
std_msgs/msg/Int8
std_msgs/msg/Byte
std_msgs/msg/Bool
std_msgs/msg/Int32
std_msgs/msg/Int16
std_msgs/msg/Float64
std_msgs/msg/Header
std_msgs/msg/Char
std_msgs/msg/Int64
std_msgs/msg/MultiArrayLayout
std_msgs/msg/Int16MultiArray
std_msgs/msg/Float32
std_msgs/msg/UInt64MultiArray
std_msgs/msg/UInt8MultiArray
std_msgs/msg/Int8MultiArray
std_msgs/msg/Int32MultiArray
std_msgs/msg/UInt32
std_msgs/msg/ColorRGBA
std_msgs/msg/Empty

以下是一些 std_msgs 中的常见消息类型:

Header: 包含 ROS 消息的标准头部信息,如时间戳和坐标系。

uint32 seq
time stamp
string frame_id

String: 代表字符串。

string data

Bool: 代表布尔值。

bool data

Int8, Int16, Int32, Int64: 代表有符号整数,分别为 8 位、16 位、32 位和 64 位。

int8 data
int16 data
int32 data
int64 data

UInt8, UInt16, UInt32, UInt64: 代表无符号整数,分别为 8 位、16 位、32 位和 64 位。

uint8 data
uint16 data
uint32 data
uint64 data

Float32, Float64: 代表单精度和双精度浮点数。

float32 data
float64 data

这些消息类型可以广泛应用于 ROS 中的不同节点,用于传递基本的数据信息。例如,一个节点可以发布一个包含测量值的 Float32 消息,而另一个节点可以订阅这个消息以获取测量值。

1.2 ROS2传感器消息包

ros2 interface package sensor_msgs
sensor_msgs/msg/PointCloud
sensor_msgs/msg/CompressedImage
sensor_msgs/msg/Image
sensor_msgs/msg/PointField
sensor_msgs/msg/LaserEcho
sensor_msgs/msg/BatteryState
sensor_msgs/msg/MultiDOFJointState
sensor_msgs/msg/NavSatFix
sensor_msgs/msg/Joy
sensor_msgs/msg/MultiEchoLaserScan
sensor_msgs/msg/LaserScan
sensor_msgs/msg/JoyFeedbackArray
sensor_msgs/msg/MagneticField
sensor_msgs/msg/ChannelFloat32
sensor_msgs/msg/RegionOfInterest
sensor_msgs/msg/NavSatStatus
sensor_msgs/msg/Range
sensor_msgs/msg/Illuminance
sensor_msgs/msg/RelativeHumidity
sensor_msgs/msg/Temperature
sensor_msgs/msg/FluidPressure
sensor_msgs/msg/JointState
sensor_msgs/srv/SetCameraInfo
sensor_msgs/msg/Imu
sensor_msgs/msg/CameraInfo
sensor_msgs/msg/JoyFeedback
sensor_msgs/msg/TimeReference
sensor_msgs/msg/PointCloud2

以下是 sensor_msgs 中的一些常见消息类型:

Image: 用于传递图像数据,包括图像的像素数据、编码格式、时间戳等。

Header header
uint32 height
uint32 width
string encoding
uint8 is_bigendian
uint32 step
uint8[] data

CameraInfo: 包含相机的信息,如相机矩阵、畸变参数等。

Header header
uint32 height
uint32 width
string distortion_model
float64[] D
float64[] K
float64[] R
float64[] P
uint32[] binning_x
uint32[] binning_y
sensor_msgs/RegionOfInterest roi

PointCloud2: 用于传递点云数据,包括点的坐标、颜色等信息。

Header header
bool is_dense
string[] fields
uint8 INT8 = 1
uint8 UINT8 = 2
uint8 INT16 = 3
uint8 UINT16 = 4
uint8 INT32 = 5
uint8 UINT32 = 6
uint8 FLOAT32 = 7
uint8 FLOAT64 = 8
uint8 point_step
uint8[] data
uint32 row_step
uint32 width
uint32 height
sensor_msgs/PointField[] fields
bool is_bigendian
uint32 point_step
uint32 row_step
uint32 data_length
uint8[] data

LaserScan: 用于传递激光扫描数据。

Header header
float32 angle_min
float32 angle_max
float32 angle_increment
float32 time_increment
float32 scan_time
float32 range_min
float32 range_max
float32[] ranges
float32[] intensities

IMU:惯性测量单元的方向、角速度和线性加速度

Header header
geometry_msgs/Quaternion orientation
float64[9] orientation_covariance
geometry_msgs/Vector3 angular_velocity
float64[9] angular_velocity_covariance
geometry_msgs/Vector3 linear_acceleration
float64[9] linear_acceleration_covariance

header: 用于包含时间戳等信息的标准 ROS 消息头。
orientation: 包含四元数表示的方向。
orientation_covariance: 一个长度为 9 的数组,表示方向协方差矩阵。
angular_velocity: 包含角速度信息的三维向量。
angular_velocity_covariance: 一个长度为 9 的数组,表示角速度协方差矩阵。
linear_acceleration: 包含线性加速度信息的三维向量。
linear_acceleration_covariance: 一个长度为 9 的数组,表示线性加速度协方差矩阵。

这些消息类型可以用于在 ROS 系统中传递从各种传感器获得的数据。节点可以发布这些消息,而其他节点则可以订阅它们以获取传感器数据。

1.3 ROS2几何相关消息包

ros2 interface package geometry_msgs
geometry_msgs/msg/Quaternion
geometry_msgs/msg/WrenchStamped
geometry_msgs/msg/Point32
geometry_msgs/msg/Accel
geometry_msgs/msg/Pose
geometry_msgs/msg/Vector3
geometry_msgs/msg/PoseArray
geometry_msgs/msg/PoseWithCovarianceStamped
geometry_msgs/msg/Polygon
geometry_msgs/msg/AccelWithCovarianceStamped
geometry_msgs/msg/AccelStamped
geometry_msgs/msg/PoseWithCovariance
geometry_msgs/msg/TransformStamped
geometry_msgs/msg/PointStamped
geometry_msgs/msg/PolygonStamped
geometry_msgs/msg/Vector3Stamped
geometry_msgs/msg/Inertia
geometry_msgs/msg/Wrench
geometry_msgs/msg/AccelWithCovariance
geometry_msgs/msg/Pose2D
geometry_msgs/msg/InertiaStamped
geometry_msgs/msg/PoseStamped
geometry_msgs/msg/QuaternionStamped
geometry_msgs/msg/Transform
geometry_msgs/msg/Twist
geometry_msgs/msg/TwistStamped
geometry_msgs/msg/TwistWithCovarianceStamped
geometry_msgs/msg/TwistWithCovariance
geometry_msgs/msg/Point

以下是一些常见的 geometry_msgs 中的消息类型:

Point: 代表三维空间中的点。

float64 x
float64 y
float64 z

Quaternion: 代表四元数,通常用于表示旋转。

float64 x
float64 y
float64 z
float64 w

Pose: 代表包含位置和方向的位姿。

Point position
Quaternion orientation

Transform: 代表变换矩阵。

Vector3 translation
Quaternion rotation

这些消息类型可以用于 ROS 中的各种应用,例如机器人运动、感知、导航等。通过使用这些消息,ROS 中的不同节点可以相互通信,共享几何信息,从而实现协同工作。

2 ROS2接口介绍

2.1 常用CLI命令

查看接口列表

ros2 interface list

查看某一个接口详细的内容

ros2 interface show std_msgs/msg/String

2.2 原始数据类型与包装类型

基本数据类型,每一个都可以在后面加上[]将其变成数组形式(从一个变成多个)

bool
byte
char
float32, float64
int8, uint8
int16, uint16
int32, uint32
int64, uint64
string

对数据类型进行剥洋葱

ros2 interface show sensor_msgs/msg/Image

终端显示如下:

# This message contains an uncompressed image
# (0, 0) is at top-left corner of imagestd_msgs/Header header # Header timestamp should be acquisition time of image
uint32 height                # image height, that is, number of rows
uint32 width                 # image width, that is, number of columns
string encoding       # Encoding of pixels -- channel meaning, ordering, size                     
uint8 is_bigendian    # is this data bigendian?
uint32 step           # Full row length in bytes
uint8[] data          # actual matrix data, size is (step * rows)

对非基类的数据数据类型std_msgs/Header header进行剥洋葱

ros2 interface show std_msgs/msg/Header

终端显示如下:

# Two-integer timestamp that is expressed as seconds and nanoseconds.
builtin_interfaces/Time stamp
# Transform frame with which this data is associated.
string frame_id

对非基类的数据数据类型builtin_interfaces/Time进行剥洋葱

ros2 interface show builtin_interfaces/msg/Time

终端显示如下:

int32 sec
uint32 nanosec

最后只剩下基类了

3 自定义接口示例

说明:这部分笔者主要是将鱼香ROS2的示例成功跑通,具体流程如下:
示例链接:

【ROS2机器人入门到实战】ROS2接口介绍
【ROS2机器人入门到实战】自定义接口RCLPY实战

3.1 接口定义

1.创建接口功能包

ros2 pkg create alian_ros2_interfaces --build-type ament_cmake --dependencies rosidl_default_generators geometry_msgs

注意功能包类型必须为:ament_cmake

依赖rosidl_default_generators:用于生成ROS中的消息、服务和行为的代码。ROS中的消息和服务是通过IDL(接口定义语言)描述的,而rosidl_default_generators
则负责将这些IDL文件转换为各种编程语言的实际代码。

具体来说,rosidl_default_generators 支持将ROS接口定义语言(ROS
IDL)文件转换为C、C++等语言的源代码。这包括生成用于发布/订阅消息、提供/调用服务以及执行行为所需的代码。

2.编写接口脚本文件
接着创建文件夹(msg、srv)和文件(RobotPose.msg、RobotStatus.msg、MoveRobot.srv),如下图。

.
├── CMakeLists.txt
├── msg
│   ├── RobotPose.msg
│   └── RobotStatus.msg
├── package.xml
└── srv└── MoveRobot.srv
2 directories, 5 files

RobotPose.msg

uint32 STATUS_MOVEING = 1
uint32 STATUS_STOP = 2
uint32  status
geometry_msgs/Pose pose

RobotStatus.msg

uint32 STATUS_MOVEING = 1
uint32 STATUS_STOP = 1
uint32  status
float32 pose

MoveRobot.srv

# 前进后退的距离
float32 distance
---
# 当前的位置
float32 pose

3.设置配置文件
CMakeLists.txt

find_package(rosidl_default_generators REQUIRED)
find_package(geometry_msgs REQUIRED)
# 添加下面的内容
rosidl_generate_interfaces(${PROJECT_NAME}"msg/RobotPose.msg""msg/RobotStatus.msg""srv/MoveRobot.srv"DEPENDENCIES geometry_msgs
)

package.xml

<buildtool_depend>ament_cmake</buildtool_depend><depend>rosidl_default_generators</depend><depend>geometry_msgs</depend><member_of_group>rosidl_interface_packages</member_of_group> #添加这一行<test_depend>ament_lint_auto</test_depend><test_depend>ament_lint_common</test_depend>

4.编译接口功能包

colcon build --packages-select example_ros2_interfaces

3.2 自定义接口RCLPY

1.创建功能包和节点

cd colcon_ws/  # 自定义的工作空间
ros2 pkg create example_interfaces_rclpy --build-type ament_python --dependencies rclpy example_ros2_interfaces --destination-directory src --node-name example_interfaces_robot_02
touch src/example_interfaces_rclpy/example_interfaces_rclpy/example_interfaces_control_02.py

2. 编写节点脚本
example_interfaces_robot_02.py

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from example_ros2_interfaces.msg import RobotStatus
import math
from time import sleep
from example_ros2_interfaces.srv import MoveRobotclass Robot():def __init__(self) -> None:self.current_pose_ = 0.0self.target_pose_ = 0.0self.status_ = RobotStatus.STATUS_STOPdef get_status(self):return self.status_def get_current_pose(self):return self.current_pose_def move_distance(self,distance):self.status_ = RobotStatus.STATUS_MOVEING # 更新状态为移动、self.target_pose_ += distance # 更新目标位置while math.fabs(self.target_pose_ - self.current_pose_) > 0.01:step = distance / math.fabs(distance) * math.fabs(self.target_pose_ - self.current_pose_) * 0.1 # 计算一步移动距离self.current_pose_  += step # 移动一步print(f"移动了:{step}当前位置:{self.current_pose_}")sleep(0.5) #休息0.5sself.status_ = RobotStatus.STATUS_STOP # 更新状态为停止return self.current_pose_      class ExampleInterfacesRobot02(Node):def __init__(self,name):super().__init__(name)self.get_logger().info("节点已启动:%s!" % name)self.robot = Robot()self.move_robot_server_ = self.create_service(MoveRobot,"move_robot", self.handle_move_robot) self.robot_status_publisher_ = self.create_publisher(RobotStatus,"robot_status", 10) self.publisher_timer_ = self.create_timer(0.5, self.publisher_timer_callback)def publisher_timer_callback(self):"""定时器回调发布数据函数"""msg = RobotStatus() #构造消息msg.status = self.robot.get_status()msg.pose = self.robot.get_current_pose()self.robot_status_publisher_.publish(msg) # 发布消息self.get_logger().info(f'发布了当前的状态:{msg.status} 位置:{msg.pose}')def handle_move_robot(self,request, response):self.robot.move_distance(request.distance)response.pose = self.robot.get_current_pose()return responsedef main(args=None):rclpy.init(args=args) # 初始化rclpynode = ExampleInterfacesRobot02("example_interfaces_robot_02")  # 新建一个节点rclpy.spin(node) # 保持节点运行,检测是否收到退出指令(Ctrl+C)rclpy.shutdown() # 关闭rclpy

example_interfaces_control_02.py

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from example_ros2_interfaces.msg import RobotStatus
from example_ros2_interfaces.srv import MoveRobotclass ExampleInterfacesControl02(Node):def __init__(self,name):super().__init__(name)self.get_logger().info("节点已启动:%s!" % name)self.client_ = self.create_client(MoveRobot,"move_robot") self.robot_status_subscribe_ = self.create_subscription(RobotStatus,"robot_status",self.robot_status_callback,10)def robot_status_callback(self,msg):self.get_logger().info(f"收到状态数据位置:{msg.pose} 状态:{msg.status}")def move_result_callback_(self, result_future):response = result_future.result()self.get_logger().info(f"收到返回结果:{response.pose}")def move_robot(self, distance):while rclpy.ok() and self.client_.wait_for_service(1)==False:self.get_logger().info(f"等待服务端上线....")request = MoveRobot.Request()request.distance = distanceself.get_logger().info(f"请求服务让机器人移动{distance}")self.client_.call_async(request).add_done_callback(self.move_result_callback_)def main(args=None):rclpy.init(args=args) # 初始化rclpynode = ExampleInterfacesControl02("example_interfaces_control_02")  # 新建一个节点node.move_robot(5.0) #移动5米rclpy.spin(node) # 保持节点运行,检测是否收到退出指令(Ctrl+C)rclpy.shutdown() # 关闭rclpy

3.修改配置文件setup.py

entry_points={'console_scripts': ['example_interfaces_control_02 = example_interfaces_rclpy.example_interfaces_control_02:main','example_interfaces_robot_02 = example_interfaces_rclpy.example_interfaces_robot_02:main'],},

4.编译功能包+运行测试

# 新终端
colcon build --packages-up-to example_interfaces_rclpy
source install/setup.bash
ros2 run example_interfaces_rclpy example_interfaces_robot_02
# 新终端
source install/setup.bash
ros2 run example_interfaces_rclpy example_interfaces_control_02

在这里插入图片描述
上图则说明自定义接口测试成功!!!


文章转载自:
http://dinncogoniometer.tpps.cn
http://dinncoradiocast.tpps.cn
http://dinncounlearned.tpps.cn
http://dinncopaedologist.tpps.cn
http://dinncomensural.tpps.cn
http://dinncoplayhouse.tpps.cn
http://dinncorecreationist.tpps.cn
http://dinncodysphagia.tpps.cn
http://dinncovoyageur.tpps.cn
http://dinncobotan.tpps.cn
http://dinncosamara.tpps.cn
http://dinncosotted.tpps.cn
http://dinncoversant.tpps.cn
http://dinncohuntaway.tpps.cn
http://dinncofarce.tpps.cn
http://dinncocohesive.tpps.cn
http://dinncoparaguay.tpps.cn
http://dinncooutrace.tpps.cn
http://dinncocpsu.tpps.cn
http://dinncoalpestrine.tpps.cn
http://dinncosprigtail.tpps.cn
http://dinncodifferentiator.tpps.cn
http://dinncorousant.tpps.cn
http://dinncosilverless.tpps.cn
http://dinncogawky.tpps.cn
http://dinncokindlessly.tpps.cn
http://dinncoterran.tpps.cn
http://dinncohillock.tpps.cn
http://dinncotrochoid.tpps.cn
http://dinncoparsimonious.tpps.cn
http://dinncoparadoxure.tpps.cn
http://dinncoepicardial.tpps.cn
http://dinncosemigovernmental.tpps.cn
http://dinncogrecism.tpps.cn
http://dinncophraseman.tpps.cn
http://dinncohierarch.tpps.cn
http://dinncowattage.tpps.cn
http://dinnconajd.tpps.cn
http://dinncobyobu.tpps.cn
http://dinncoamericanophobia.tpps.cn
http://dinncotidbit.tpps.cn
http://dinncoinfundibular.tpps.cn
http://dinncohorsenapping.tpps.cn
http://dinncoterneplate.tpps.cn
http://dinncobibliolater.tpps.cn
http://dinncojeerer.tpps.cn
http://dinncoconcinnate.tpps.cn
http://dinncointerpretation.tpps.cn
http://dinncoacquainted.tpps.cn
http://dinncohemolymph.tpps.cn
http://dinncoyugoslav.tpps.cn
http://dinncosemieducated.tpps.cn
http://dinncokate.tpps.cn
http://dinncodinitrogen.tpps.cn
http://dinncochlorophenol.tpps.cn
http://dinncotheatrician.tpps.cn
http://dinncotipwizard.tpps.cn
http://dinncoforeoath.tpps.cn
http://dinncogranduncle.tpps.cn
http://dinncodemoid.tpps.cn
http://dinncoakinesia.tpps.cn
http://dinncocattegat.tpps.cn
http://dinncoholmic.tpps.cn
http://dinncovillous.tpps.cn
http://dinncomerited.tpps.cn
http://dinncoiodometry.tpps.cn
http://dinncoderbyshire.tpps.cn
http://dinnconepal.tpps.cn
http://dinncocokery.tpps.cn
http://dinncoupgather.tpps.cn
http://dinncoptolemaic.tpps.cn
http://dinncoreslush.tpps.cn
http://dinncorecent.tpps.cn
http://dinncogrammaticus.tpps.cn
http://dinncoinnards.tpps.cn
http://dinncopaddleboard.tpps.cn
http://dinncoginshop.tpps.cn
http://dinncospirochete.tpps.cn
http://dinncoimperialize.tpps.cn
http://dinncoattract.tpps.cn
http://dinncogridiron.tpps.cn
http://dinncofighter.tpps.cn
http://dinncojessamine.tpps.cn
http://dinncoapartness.tpps.cn
http://dinncoirritating.tpps.cn
http://dinncoleague.tpps.cn
http://dinncotrojan.tpps.cn
http://dinncocantorial.tpps.cn
http://dinncorecollectedly.tpps.cn
http://dinncofanback.tpps.cn
http://dinncoriverway.tpps.cn
http://dinncoreceivership.tpps.cn
http://dinncounjustly.tpps.cn
http://dinncochromidium.tpps.cn
http://dinncoforcemeat.tpps.cn
http://dinncotelotype.tpps.cn
http://dinncotrelliswork.tpps.cn
http://dinncoprepostor.tpps.cn
http://dinncopolyclonal.tpps.cn
http://dinncopolysome.tpps.cn
http://www.dinnco.com/news/144686.html

相关文章:

  • 如何免费做网站 详细点说怎样建立一个网站
  • 蓝气球卡地亚手表官方网站优质外链平台
  • 腾讯云做网站步骤seo推广的公司
  • 食品包装设计说明宁波网站seo诊断工具
  • 做死活题网站深圳网络整合营销公司
  • 网站设计原理新手20种引流推广方法
  • 哪些网站布局设计做的比较好的刚刚中国突然宣布
  • 南昌市建设局网站怎么开网站
  • 做网站题材网络推广营销方案100例
  • 淘宝网站建设设计模板中国旺旺(00151) 股吧
  • 建设工程项目前期去哪个网站排名前十的小说
  • 网站的封面怎么做手游推广渠道和推广方式
  • 分析网站快速建网站
  • 模板网站与定制开发网站的区别廊坊seo网站管理
  • 比较好的做外贸网站百度seo发包工具
  • 网站怎么换模板网络推广费计入什么科目
  • 网站标签图标代码模板建站
  • 电商网站开发语言销售找客户的app
  • 个人开办导航网站需要怎么做优化网址
  • 成都网站建设易维达好黑帽seo培训网
  • 建网站要钱吗 优帮云百度免费网站制作
  • 容桂做外贸网站seo软件全套
  • 网站描述作用网站模板购买
  • 兰州网站建设搜狗网站收录
  • 做货代在上面网站找客户比较多广告推广投放平台
  • 个人网站备案条件seo关键字优化技巧
  • 如何 做镜像网站app代理推广合作50元
  • wordpress 源码下载主题上海百度推广排名优化
  • 天津环保网站建设概念排名优化哪家专业
  • 免费b站推广网站动漫seo网站诊断价格