您的位置:首页 > 财经 > 产业 > 企业取名字大全免费测试_网页微信版二维码过期怎么办_百度收录网址提交_网络营销渠道策略有哪些

企业取名字大全免费测试_网页微信版二维码过期怎么办_百度收录网址提交_网络营销渠道策略有哪些

2025/2/25 5:49:54 来源:https://blog.csdn.net/suoxd123/article/details/145809233  浏览:    关键词:企业取名字大全免费测试_网页微信版二维码过期怎么办_百度收录网址提交_网络营销渠道策略有哪些
企业取名字大全免费测试_网页微信版二维码过期怎么办_百度收录网址提交_网络营销渠道策略有哪些

1. 编译工具安装

sudo apt update
sudo apt install python3-catkin-pkg python3-rosdep python3-rosinstall-generator python3-wstool python3-rosinstall build-essential
sudo rosdep init
rosdep update

在这里插入图片描述

2. 构建节点

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
ros2 pkg create turtlebot_suo --build-type ament_python --dependencies rclpy sensor_msgs geometry_msgstouch turtlebot_suo/turtlebot_suo/ob_avoid.py
chmod +x turtlebot_suo/turtlebot_suo/ob_avoid.py
# setup.py中定义ros2 run的入口entry_points={'console_scripts': ['ob_avoid = turtlebot_suo.ob_avoid:main',],},
cd ~/ros2_ws
colcon build --packages-select turtlebot_suo
source install/setup.bash

在这里插入图片描述

3. 避障程序


#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twistclass ObstacleAvoidance(Node):def __init__(self):super().__init__('ob_avoid')self.publisher_ = self.create_publisher(Twist, 'cmd_vel', 10)self.subscription_ = self.create_subscription(LaserScan,'scan',self.laser_scan_callback,10)self.subscription_  def laser_scan_callback(self, msg):# 获取前方90度范围内的最小距离front_range = msg.ranges[0:45] + msg.ranges[-45:]min_distance = min(front_range)# 避障逻辑cmd_msg = Twist()if min_distance < 0.5:# 障碍物距离小于0.5米时左转cmd_msg.angular.z = 0.5self.get_logger().info('# 障碍物距离小于0.5米,左转.')else:# 默认按固定速度直行cmd_msg.linear.x = 0.2self.publisher_.publish(cmd_msg)def main(args=None):rclpy.init(args=args)node = ObstacleAvoidance()try:rclpy.spin(node)except KeyboardInterrupt:passfinally:node.destroy_node()rclpy.shutdown()if __name__ == '__main__':main()

4. 效果

# 启动Gazebo仿真
roslaunch turtlebot3_gazebo turtlebot3_world.launch
# 启动避障节点(新终端)
ros2 run turtlebot_suo ob_avoid

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com