Explore Basic Behavior of the TurtleBot ---3
原创博文:转载请标明出处(周学伟):http://www.cnblogs.com/zxouxuewei/tag/
Introduction
此示例帮助您使用turtlebot的自主性。 驱动机器人向前移动并且当存在障碍物时改变其方向。 您将订阅激光扫描主题并发布速度主题以控制turtlebot。
Hardware Support Package for turtlebot
本示例使用ROS接口的TurtleBot。 基于TurtleBot的机器人支持包为TurtleBot提供了一个更简洁的界面。
它允许您:
获取传感器数据并发送控制命令,而不显式调用ROS命令。
与Gazebo中的模拟机器人或物理TurtleBot进行透明通信。
要安装支持包,在MATLAB Home选项卡上打开Add-Ons>获取硬件支持包,然后选择“TurtleBot-Based Robots”。 或者,使用roboticsAddons命令。
Connect to the TurtleBot
确保你有一个TurtleBot运行在通过Gazebo或真实硬件的模拟。 有关启动过程,请参阅开始使用Gazebo和模拟TurtleBot或开始使用Real TurtleBot。
再此我没有Turtlebot 也不想用Gazebo,我用自己开发的zxbot机器人。按照相应的指令启动机器人。


链接机器人的wifi ZXBOT,远程登录机器人:
ssh ubuntu@192.168.1.159
roslaunch odom_tf_package zxbot_start.launch
keysi_start.launch文件内容如下:github链接:https://github.com/ZXWBOT
<launch>
<param name="use_sim_time" value="false" /> <!--Set the TF tree for the keysi robot-->
<node name="link_laser" pkg="tf" type="static_transform_publisher" args="0.15 0 0.15 0 0 1.0 6.12323399574e-17 base_link laser 50"/>
<node name="link_camera" pkg="tf" type="static_transform_publisher" args="0.15 0 0.15 0 0 0 base_link camera_link 50"/>
<node name="link_footprint" pkg="tf" type="static_transform_publisher" args="0 0 0 0 0 0 base_link base_footprint 50"/> <!--Start the robot's base control code and publish the odometer data-->
<node pkg="keysi_package" type="keysi_start_node" name="publish_odom" output="screen">
<param name="usart_port" type="string" value="/dev/zxbot_base"/>
<param name="baud_data" type="int" value=""/>
<param name="robot_frame_id" type="string" value="base_link"/>
<param name="smoother_cmd_vel" type="string" value="/smoother_cmd_vel"/>
</node>
<!--Open the Radar Startup Package and publish the Scan data-->
<node name="rplidarNode" pkg="rplidar_ros" type="rplidarNode" output="screen">
<param name="serial_port" type="string" value="/dev/zxbot_rplidar"/>
<param name="serial_baudrate" type="int" value=""/>
<param name="frame_id" type="string" value="laser"/>
<param name="inverted" type="bool" value="false"/>
<param name="angle_compensate" type="bool" value="true"/>
<param name="Angle_Laser" type="int" value=""/>
</node>
<arg name="node_name" value="velocity_smoother"/>
<arg name="nodelet_manager_name" value="nodelet_manager"/>
<arg name="config_file" value="$(find keysi_package)/config/yocs_velocity_smoother.yaml"/>
<arg name="raw_cmd_vel_topic" value="cmd_vel"/>
<arg name="smooth_cmd_vel_topic" value="smoother_cmd_vel"/>
<arg name="robot_cmd_vel_topic" value="robot_cmd_vel"/>
<arg name="odom_topic" value="odom"/> <node pkg="nodelet" type="nodelet" name="$(arg nodelet_manager_name)" args="manager"/> <include file="$(find yocs_velocity_smoother)/launch/velocity_smoother.launch">
<arg name="node_name" value="$(arg node_name)"/>
<arg name="nodelet_manager_name" value="$(arg nodelet_manager_name)"/>
<arg name="config_file" value="$(arg config_file)"/>
<arg name="raw_cmd_vel_topic" value="$(arg raw_cmd_vel_topic)"/>
<arg name="smooth_cmd_vel_topic" value="$(arg smooth_cmd_vel_topic)"/>
<arg name="robot_cmd_vel_topic" value="$(arg robot_cmd_vel_topic)"/>
<arg name="odom_topic" value="$(arg odom_topic)"/>
</include> </launch>
初始化ROS。 通过用ZXBOT的IP地址替换示例IP地址(192.168.1.1),连接到ZXBOT。
ipaddress = '192.168.1.215' //机器人主机的IP rosinit(ipaddress)

为机器人的速度创建一个发布者,并为该主题创建一条消息。
如果你使用的是ZXBOT:
robot = rospublisher('/cmd_vel');
velmsg = rosmessage(robot);
如果你使用的是TURTLEBOT
robot = rospublisher('/mobile_base/commands/velocity');
velmsg = rosmessage(robot);

Receive Scan Data
确保你的硬件已经发布了/scan数据。Subscribe to the topic /scan.
//在机器人端
Turtlebot roslaunch turtlebot_bringup 3dsensor.launch
zxbot roslaunch odom_tf_package zxbot_start.launch
//MATLAB
laser = rossubscriber('/scan');
scan = receive(laser,3)
figure
plot(scan);
如果您看到错误,可能是激光扫描主题没有接收任何数据。 如果您正在模拟中运行,请尝试重新启动Gazebo。 如果您使用硬件,请确保您已正确启动Kinect相机或者激光雷达。

运行以下代码行,其中绘制实时激光扫描进给二十秒。 移动TurtleBot或zxbot前面的一个对象,并使它足够近,直到它不再显示在绘图窗口中。
tic;
while toc <
scan = receive(laser,);
plot(scan);
end
Simple Obstacle Avoidance
基于从激光扫描的距离读数,您可以实现一个简单的障碍物回避算法。 你可以使用一个简单的while循环来实现这个行为。
设置将在处理循环中使用的一些参数。 您可以根据不同的行为修改这些值。
spinVelocity = 0.6; % Angular velocity (rad/s)
forwardVelocity = 0.1; % Linear velocity (m/s)
backwardVelocity = -0.02; % Linear velocity (reverse) (m/s)
distanceThreshold = 0.6; % Distance threshold (m) for turning
运行循环以向前移动机器人并计算与机器人最近的障碍物。 当障碍物在distanceThreshold的界限内时,机器人转动。 该循环在运行时间20秒后停止。 CTRL + C(或Mac上的Control + C)也会停止此循环
tic;
while toc <
% Collect information from laser scan
scan = receive(laser);
plot(scan);
data = readCartesian(scan);
x = data(:,);
y = data(:,);
% Compute distance of the closest obstacle
dist = sqrt(x.^ + y.^);
minDist = min(dist);
% Command robot action
if minDist < distanceThreshold
% If close to obstacle, back up slightly and spin
velmsg.Angular.Z = spinVelocity;
velmsg.Linear.X = backwardVelocity;
else
% Continue on forward path
velmsg.Linear.X = forwardVelocity;
velmsg.Angular.Z = ;
end
send(robot,velmsg);
end
下面你就会看到你的机器人开始移动并且避开障碍物。
Disconnect from the Robot
最好在完成发布者,订阅者和其他ROS相关对象的工作区后清除它们。
clear
一旦你完成使用ROS网络,建议使用rosshutdown。 关闭全局节点并从TurtleBot或者zxbot断开连接。
rosshutdown
Explore Basic Behavior of the TurtleBot ---3的更多相关文章
- 脚本AI与脚本引擎
Scripted AI and Scripting Engines 脚本AI与脚本引擎 This chapter discusses some of the techniques you can us ...
- Five reasons phosphorene may be a new wonder material
A material that you may never have heard of could be paving the way for a new electronic revolution. ...
- Java多线程系列--“JUC锁”03之 公平锁(一)
概要 本章对“公平锁”的获取锁机制进行介绍(本文的公平锁指的是互斥锁的公平锁),内容包括:基本概念ReentrantLock数据结构参考代码获取公平锁(基于JDK1.7.0_40)一. tryAcqu ...
- Java多线程系列--“JUC锁”04之 公平锁(二)
概要 前面一章,我们学习了“公平锁”获取锁的详细流程:这里,我们再来看看“公平锁”释放锁的过程.内容包括:参考代码释放公平锁(基于JDK1.7.0_40) “公平锁”的获取过程请参考“Java多线程系 ...
- Java多线程系列--“JUC锁”05之 非公平锁
概要 前面两章分析了"公平锁的获取和释放机制",这一章开始对“非公平锁”的获取锁/释放锁的过程进行分析.内容包括:参考代码获取非公平锁(基于JDK1.7.0_40)释放非公平锁(基 ...
- PHP生成器Generators
下文的第一个逐行读取文件例子用三种方式实现;普通方法,迭代器和生成器,比较了他们的优缺点,很好,可以引用到自己的代码中 ,支持的php版本(PHP 5 >= 5.5.0) 后面的yield讲解, ...
- android 和iOS的view上的区别
android上的view的类叫View, 以下是它的class overview, This class represents the basic building block for user i ...
- lua weak table 概念解析
lua weak table 经常看到lua表中有 weak table的用法, 例如: weak_table = setmetatable({}, {__mode="v"}) 官 ...
- Apache Solr 访问权限控制
Current state of affairs SSL support was added in version 4.2 (SolrCloud v4.7). Protection of Zookee ...
随机推荐
- kubernetes应用部署原理
Kubernetes应用部署模型解析(原理篇) 十多年来Google一直在生产环境中使用容器运行业务,负责管理其容器集群的系统就是Kubernetes的前身Borg.其实现在很多工作在Kubernet ...
- VB6学习笔记
1.数据库读取 [工程]菜单的[引用]菜单项,打开引用对话框,选中[Microsoft ActiveX Data Objects 6.1 Library] [工程]菜单的[引用]菜单项,打开引用对话框 ...
- w3svc无法启动
w3svc无法启动 运行命令regedit,打开注册表编辑器,进入:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP]: a) Cha ...
- 【C】——const和volatile可以并用吗?
答案是肯定的,可以一起用. 因为很多人误解了const的真正含义,很多初学者认为const修饰的就是常量,而常量不会改变,而既然不会改变,那volatile就没有意义. 但是实际上这正是对const的 ...
- 再谈git的http服务-权限控制gitweb版(未成功)
截至目前,对gitweb的掌握还没达到最终目标,仅仅实现了通过浏览器来浏览项目,通过git命令仍然未能clone项目.但仍然要记录下来,主要是因为打算暂时放弃这条路,而所收获的一些经验还是要记录下来. ...
- 《快学 Go 语言》第 16 课 —— 包管理 GOPATH 和 Vendor
到目前位置我们一直在编写单文件代码,只有一个 main.go 文件.本节我们要开始朝完整的项目结构迈进,需要使用 Go 语言的模块管理功能来组织很多的代码文件. 细数 Go 语言的历史发展,模块管理经 ...
- orcale存储过程学习之路(一)
----------------------------------------- 建表 ------------------------------------------ create table ...
- ggplot ggplot2 画图
折线图-ggplot2 http://blog.163.com/yugao1986@126/blog/static/6922850820131161531421/http://blog.sina.c ...
- Linux Makefile简单模板
########################################### #Makefile for simple programs ########################## ...
- Java Servlet生成JSON格式数据并用jQuery显示
1.Servlet通过json-lib生成JSON格式的数据 import java.io.IOException;import java.io.PrintWriter;import java.uti ...