ROS1云课→29如何借助导航实现走迷宫机器人
先一键配置吧,否则很多内容无法展开讲。
代码语言:javascript复制echo "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQINBFzvJpYBEADY8l1YvO7iYW5gUESyzsTGnMvVUmlV3XarBaJz9bGRmgPXh7jc
VFrQhE0L/HV7LOfoLI9H2GWYyHBqN5ERBlcA8XxG3ZvX7t9nAZPQT2Xxe3GT3tro
u5oCR SyHN9xPnUwDuqUSvJ2eqMYb9B/Hph3OmtjG30jSNq9kOF5bBTk1hOTGPH4
K/AY0jzT6OpHfXU6ytlFsI47ZKsnTUhipGsKucQ1CXlyirndZ3V3k70YaooZ55rG
aIoAWlx2H0J7sAHmqS29N9jV9mo135d d TdLBXI0PXtiHzE9IPaX ctdSUrPnp
TwR99lxglpIG6hLuvOMAaxiqFBB/Jf3XJ8OBakfS6nHrWH2WqQxRbiITl0irkQoz
pwNEF2Bv0 Jvs1UFEdVGz5a8xexQHst/RmKrtHLct3iOCvBNqoAQRbvWvBhPjO/p
V5cYeUljZ5wpHyFkaEViClaVWqa6PIsyLqmyjsruPCWlURLsQoQxABcL8bwxX7UT
hM6CtH6tGlYZ85RIzRifIm2oudzV5l 8oRgFr9yVcwyOFT6JCioqkwldW52P1pk/
/SnuexC6LYqqDuHUs5NnokzzpfS6QaWfTY5P5tz4KHJfsjDIktly3mKVfY0fSPVV
okdGpcUzvz2hq1fqjxB6MlB/1vtk0bImfcsoxBmF7H 4E9ZN1sX/tSb0KQARAQAB
tCZPcGVuIFJvYm90aWNzIDxpbmZvQG9zcmZvdW5kYXRpb24ub3JnPokCVAQTAQgA
PgIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgBYhBMHPbjHmut6IaLFytPQu1vur
F8ZUBQJgsdhRBQkLTMW7AAoJEPQu1vurF8ZUTMwP/3f7EkOPIFjUdRmpNJ2db4iB
RQu5b2SJRG KIdbvQBzKUBMV6/RUhEDPjhXZI3zDevzBewvAMKkqs2Q1cWo9WV7Z
PyTkvSyey/Tjn PozcdvzkvrEjDMftIk8E1WzLGq7vnPLZ1q/b6Vq4H373Z EDWa
DaDwW72CbCBLWAVtqff80CwlI2x8fYHKr3VBUnwcXNHR4 nRABfAWnaU4k oTshC
Qucsd8vitNfsSXrKuKyz91IRHRPnJjx8UvGU4tRGfrHkw1505EZvgP02vXeRyWBR
fKiL1vGy4tCSRDdZO3ms2J2m08VPv65HsHaWYMnO rNJmMZj9d9JdL/9GRf5F6U0
quoIFL39BhUEvBynuqlrqistnyOhw8W/IQy/ymNzBMcMz6rcMjMwhkgm/LNXoSD1
1OrJu4ktQwRhwvGVarnB8ihwjsTxZFylaLmFSfaA OAlOqCLS1OkIVMzjW Ul6A6
qjiCEUOsnlf4CGlhzNMZOx3low6ixzEqKOcfECpeIj80a2fBDmWkcAAjlHu6VBhA
TUDG9e2xKLzV2Z/DLYsb3 n9QW7KO0yZKfiuUo6AYboAioQKn5jh3iRvjGh2Ujpo
22G oae3PcCc7G z12j6xIY709FQuA49dA2YpzMda0/OX4LP56STEveDRrO CnV6
WE F5FaIKwb72PL4rLi4
=i0tj
-----END PGP PUBLIC KEY BLOCK-----" >> ~/ros.asc
sudo apt-key add ros.asc
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt update
sudo apt install ros-kinetic-turtlebot-simulator -y
roslaunch turtlebot_stdr turtlebot_in_stdr.launch
保存为initnav.sh。
1 gedit initnav.sh 2 chmod x initnav.sh 3 ./initnav.sh 4 ls 5 gedit initnav.sh 6 ./initnav.sh
需要源码下载:
代码语言:javascript复制git clone https://gitcode.net/ZhangRelay/ros_book.git
/opt/ros/kinetic/share/turtlebot_stdr/maps
改环境,同样一键配置
代码语言:javascript复制export TURTLEBOT_STDR_MAP_FILE=/opt/ros/kinetic/share/turtlebot_stdr/maps/simple_rooms.yaml
roslaunch turtlebot_stdr turtlebot_in_stdr.launch
效果如下:
更通用案例:
代码语言:javascript复制export TURTLEBOT_STDR_MAP_FILE=/opt/ros/kinetic/share/turtlebot_stdr/maps/mines.yaml
echo "<!--
Turtlebot navigation simulation:
- stdr
- move_base
- amcl
- map_server
- rviz view
-->
<launch>
<arg name="base" default="$(optenv TURTLEBOT_BASE kobuki)"/> <!-- create, rhoomba -->
<arg name="stacks" default="$(optenv TURTLEBOT_STACKS hexagons)"/> <!-- circles, hexagons -->
<arg name="3d_sensor" default="$(optenv TURTLEBOT_3D_SENSOR kinect)"/> <!-- kinect, asus_xtion_pro -->
<arg name="laser_topic" default="robot0/laser_0"/> <!-- default laser topic in stdr for 1 robot -->
<arg name="odom_topic" default="robot0/odom"/>
<arg name="odom_frame_id" default="map"/>
<arg name="base_frame_id" default="robot0"/>
<arg name="global_frame_id" default="world"/>
<!-- Name of the map to use (without path nor extension) and initial position -->
<arg name="map_file" default="$(env TURTLEBOT_STDR_MAP_FILE)"/>
<arg name="initial_pose_x" default="1.5"/>
<arg name="initial_pose_y" default="1.5"/>
<arg name="initial_pose_a" default="0.0"/>
<arg name="min_obstacle_height" default="0.0"/>
<arg name="max_obstacle_height" default="5.0"/>
<!-- ******************** Stdr******************** -->
<include file="$(find stdr_robot)/launch/robot_manager.launch" />
<!-- Run STDR server with a prefedined map-->
<node pkg="stdr_server" type="stdr_server_node" name="stdr_server" output="screen" args="$(arg map_file)"/>
<!--Spawn new robot at init position 2 2 0-->
<node pkg="stdr_robot" type="robot_handler" name="$(anon robot_spawn)" args="add $(find turtlebot_stdr)/robot/turtlebot.yaml $(arg initial_pose_x) $(arg initial_pose_y) 0"/>
<!-- Run Gui -->
<include file="$(find stdr_gui)/launch/stdr_gui.launch"/>
<!-- Run the relay to remap topics -->
<include file="$(find turtlebot_stdr)/launch/includes/relays.launch.xml"/>
<!-- ***************** Robot Model ***************** -->
<include file="$(find turtlebot_bringup)/launch/includes/robot.launch.xml">
<arg name="base" value="$(arg base)" />
<arg name="stacks" value="$(arg stacks)" />
<arg name="3d_sensor" value="$(arg 3d_sensor)" />
</include>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
<param name="use_gui" value="true"/>
</node>
<!-- Command Velocity multiplexer -->
<node pkg="nodelet" type="nodelet" name="mobile_base_nodelet_manager" args="manager"/>
<node pkg="nodelet" type="nodelet" name="cmd_vel_mux" args="load yocs_cmd_vel_mux/CmdVelMuxNodelet mobile_base_nodelet_manager">
<param name="yaml_cfg_file" value="$(find turtlebot_bringup)/param/mux.yaml"/>
<remap from="cmd_vel_mux/output" to="mobile_base/commands/velocity"/>
</node>
<!-- ****** Maps ***** -->
<node name="map_server" pkg="map_server" type="map_server" args="$(arg map_file)">
<param name="frame_id" value="$(arg global_frame_id)"/>
</node>
<!-- ************** Navigation *************** -->
<include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml">
<arg name="odom_topic" value="$(arg odom_topic)"/>
<arg name="laser_topic" value="$(arg laser_topic)"/>
<arg name="odom_frame_id" value="$(arg odom_frame_id)"/>
<arg name="base_frame_id" value="$(arg base_frame_id)"/>
<arg name="global_frame_id" value="$(arg global_frame_id)"/>
</include>
<!-- ***************** Manually setting some parameters ************************* -->
<param name="move_base/local_costmap/obstacle_layer/scan/min_obstacle_height" value="$(arg min_obstacle_height)"/>
<param name="move_base/local_costmap/obstacle_layer/scan/max_obstacle_height" value="$(arg max_obstacle_height)"/>
<param name="move_base/global_costmap/obstacle_layer/scan/min_obstacle_height" value="$(arg min_obstacle_height)"/>
<param name="move_base/global_costmap/obstacle_layer/scan/max_obstacle_height" value="$(arg max_obstacle_height)"/>
<!-- ************** AMCL ************** -->
<include file="$(find turtlebot_navigation)/launch/includes/amcl/amcl.launch.xml">
<arg name="scan_topic" value="$(arg laser_topic)"/>
<arg name="use_map_topic" value="true"/>
<arg name="odom_frame_id" value="$(arg odom_frame_id)"/>
<arg name="base_frame_id" value="$(arg base_frame_id)"/>
<arg name="global_frame_id" value="$(arg global_frame_id)"/>
<arg name="initial_pose_x" value="$(arg initial_pose_x)"/>
<arg name="initial_pose_y" value="$(arg initial_pose_y)"/>
<arg name="initial_pose_a" value="$(arg initial_pose_a)"/>
</include>
<!-- ********** Small tf tree connector between robot0 and base_footprint********* -->
<node name="tf_connector" pkg="turtlebot_stdr" type="tf_connector.py" output="screen"/>
<!-- **************** Visualisation **************** -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find turtlebot_stdr)/rviz/robot_navigation.rviz"/>
</launch>" >> ~/mines.launch
roslaunch mines.launch
或者:
代码语言:javascript复制export TURTLEBOT_STDR_MAP_FILE=/opt/ros/kinetic/share/turtlebot_stdr/maps/mines.yaml
roslaunch turtlebot_stdr turtlebot_in_stdr.launch
需要修改机器人初始坐标到合适的位置。
课堂中教室建图和导航案例需补充。
然后将其导入的ROS云实践镜像中。
注意一些参数配置,例如机器人和坐标位置等。
<arg name="initial_pose_x" default="1.5"/> <arg name="initial_pose_y" default="1.5"/> <arg name="initial_pose_a" default="0.0"/>
坐标要对应地图参数进行调整。
设置地图:
export TURTLEBOT_STDR_MAP_FILE=/opt/ros/kinetic/share/turtlebot_stdr/maps/***.yaml
其中,***对应具体地图名称。
launch文件简单介绍:
<!-- Turtlebot navigation simulation: - stdr - move_base - amcl - map_server - rviz view -->
包含功能如上。
<launch> <arg name="base" default="
基本主题和坐标
<!-- Name of the map to use (without path nor extension) and initial position --> <arg name="map_file" default="$(env TURTLEBOT_STDR_MAP_FILE)"/> <arg name="initial_pose_x" default="1.5"/> <arg name="initial_pose_y" default="1.5"/> <arg name="initial_pose_a" default="0.0"/> <arg name="min_obstacle_height" default="0.0"/> <arg name="max_obstacle_height" default="5.0"/>
初始位置参数和障碍物 <!-- ******************** Stdr******************** --> <include file="(anon robot_spawn)" args="add (arg initial_pose_x) (arg initial_pose_y) 0"/> <!-- Run Gui --> <include file="(find stdr_gui)/launch/stdr_gui.launch"/> <!-- Run the relay to remap topics --> <include file="(find turtlebot_bringup)/launch/includes/robot.launch.xml"> <arg name="base" value="(arg stacks)" /> <arg name="3d_sensor" value="
机器人模型详细参数 <!-- Command Velocity multiplexer --> <node pkg="nodelet" type="nodelet" name="mobile_base_nodelet_manager" args="manager"/> <node pkg="nodelet" type="nodelet" name="cmd_vel_mux" args="load yocs_cmd_vel_mux/CmdVelMuxNodelet mobile_base_nodelet_manager"> <param name="yaml_cfg_file" value="$(find turtlebot_bringup)/param/mux.yaml"/> <remap from="cmd_vel_mux/output" to="mobile_base/commands/velocity"/> </node>
速度 <!-- ****** Maps ***** --> <node name="map_server" pkg="map_server" type="map_server" args="(find turtlebot_navigation)/launch/includes/move_base.launch.xml"> <arg name="odom_topic" value="(arg laser_topic)"/> <arg name="odom_frame_id" value="(arg base_frame_id)"/> <arg name="global_frame_id" value="
导航 <!-- ***************** Manually setting some parameters ************************* --> <param name="move_base/local_costmap/obstacle_layer/scan/min_obstacle_height" value="(arg min_obstacle_height)"/> <param name="move_base/global_costmap/obstacle_layer/scan/max_obstacle_height" value="
自定义参数 <!-- ************** AMCL ************** --> <include file="(arg odom_frame_id)"/> <arg name="base_frame_id" value="(arg global_frame_id)"/> <arg name="initial_pose_x" value="(arg initial_pose_y)"/> <arg name="initial_pose_a" value="
自适应蒙特卡罗定位 <!-- ********** Small tf tree connector between robot0 and base_footprint********* --> <node name="tf_connector" pkg="turtlebot_stdr" type="tf_connector.py" output="screen"/>
坐标 <!-- **************** Visualisation **************** --> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find turtlebot_stdr)/rviz/robot_navigation.rviz"/>
可视化 </launch>
坐标:
代码语言:javascript复制#!/usr/bin/env python
__author__ = 'mehdi tlili'
import rospy
from tf2_msgs.msg import TFMessage
import tf
class Remapper(object):
def __init__(self):
self.br = tf.TransformBroadcaster()
rospy.Subscriber("/tf", TFMessage, self.tf_remapper)
def tf_remapper(self, msg):
if msg.transforms[0].header.frame_id == "/robot0":
self.br.sendTransform((0, 0, 0),
tf.transformations.quaternion_from_euler(0, 0, 0),
rospy.Time.now(),
"base_footprint",
"robot0")
if __name__ == '__main__':
rospy.init_node('remapper_nav')
remapper = Remapper()
rospy.spin()