matlab控制turtlebot,Turtlebot与Matlab入门教程-控制机器人
说明:
介绍如何控制机器人
步骤:
在turtlebot端
启动turtlebot
$ roslaunch turtlebot_bringup minimal.launch
启动雷达
$ roslaunch rplidar_ros rplidar.launch
在Matlab端
运行myTeleop.m文件
输入ROS_MASTERR_URI,http://192.168.0.93:11311
输入话题,/mobile_base/commands/velocity
按键前,后,左,右,控制机器人运动
代码如下:
function varargout = myTeleop(varargin)
% MYTELEOP MATLAB code for myTeleop.fig
% MYTELEOP, by itself, creates a new MYTELEOP or raises the existing
% singleton*.
%
% H = MYTELEOP returns the handle to a new MYTELEOP or the handle to
% the existing singleton*.
%
% MYTELEOP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYTELEOP.M with the given input arguments.
%
% MYTELEOP('Property','Value',...) creates a new MYTELEOP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before myTeleop_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to myTeleop_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help myTeleop
% Last Modified by GUIDE v2.5 20-Jun-2017 15:24:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @myTeleop_OpeningFcn, ...
'gui_OutputFcn', @myTeleop_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before myTeleop is made visible.
function myTeleop_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to myTeleop (see VARARGIN)
% Choose default command line output for myTeleop
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes myTeleop wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = myTeleop_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% 声明一些全局变量
% ROS Master URI和Topic name
global rosMasterUri
global teleopTopicName
rosMasterUri = 'http://192.168.1.202:11311';
teleopTopicName = '/cmd_vel';
% 机器人的运行速度
global leftVelocity
global rightVelocity
global forwardVelocity
global backwardVelocity
leftVelocity = 1; % 角速度 (rad/s)
rightVelocity = -1; % 角速度 (rad/s)
forwardVelocity = 0.2; % 线速度 (m/s)
backwardVelocity = -0.2; % 线速度 (m/s)
% 设置ROS Master URI
function URIEdit_Callback(hObject, eventdata, handles)
% hObject handle to URIEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of URIEdit as text
% str2double(get(hObject,'String')) returns contents of URIEdit as a double
global rosMasterUri
rosMasterUri = get(hObject,'String')
% --- Executes during object creation, after setting all properties.
function URIEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to URIEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% 设置Topic name
function TopicEdit_Callback(hObject, eventdata, handles)
% hObject handle to TopicEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of TopicEdit as text
% str2double(get(hObject,'String')) returns contents of TopicEdit as a double
global teleopTopicName
teleopTopicName = get(hObject,'String')
% --- Executes during object creation, after setting all properties.
function TopicEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to TopicEdit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% 建立连接并初始化ROS publisher
% --- Executes on button press in ConnectButton.
function ConnectButton_Callback(hObject, eventdata, handles)
% hObject handle to ConnectButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global rosMasterUri
global teleopTopicName
global robot
global velmsg
setenv('ROS_MASTER_URI',rosMasterUri)
rosinit
robot = rospublisher(teleopTopicName,'geometry_msgs/Twist');
velmsg = rosmessage(robot);
% 断开连接,关闭ROS
% --- Executes on button press in DisconnectButton.
function DisconnectButton_Callback(hObject, eventdata, handles)
% hObject handle to DisconnectButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rosshutdown
% 向前
% --- Executes on button press in ForwardButton.
function ForwardButton_Callback(hObject, eventdata, handles)
% hObject handle to ForwardButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global velmsg
global robot
global teleopTopicName
global forwardVelocity
velmsg.Angular.Z = 0;
velmsg.Linear.X = forwardVelocity;
send(robot,velmsg);
latchpub = rospublisher(teleopTopicName, 'IsLatching', true);
%向左
% --- Executes on button press in LeftButton.
function LeftButton_Callback(hObject, eventdata, handles)
% hObject handle to LeftButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global velmsg
global robot
global teleopTopicName
global leftVelocity
velmsg.Angular.Z = leftVelocity;
velmsg.Linear.X = 0;
send(robot,velmsg);
latchpub = rospublisher(teleopTopicName, 'IsLatching', true);
% 向右
% --- Executes on button press in RightButton.
function RightButton_Callback(hObject, eventdata, handles)
% hObject handle to RightButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global velmsg
global robot
global teleopTopicName
global rightVelocity
velmsg.Angular.Z = rightVelocity;
velmsg.Linear.X = 0;
send(robot,velmsg);
latchpub = rospublisher(teleopTopicName, 'IsLatching', true);
% 向后
% --- Executes on button press in BackwardButton.
function BackwardButton_Callback(hObject, eventdata, handles)
% hObject handle to BackwardButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global velmsg
global robot
global teleopTopicName
global backwardVelocity
velmsg.Angular.Z = 0;
velmsg.Linear.X = backwardVelocity;
send(robot,velmsg);
latchpub = rospublisher(teleopTopicName, 'IsLatching', true);
clear;
rosshutdown;
效果如下:
matlab控制turtlebot,Turtlebot与Matlab入门教程-控制机器人相关推荐
- matlab控制turtlebot,Turtlebot3与Matlab入门教程-控制移动
说明: 介绍如何使用Matlab控制turtlebot3移动 步骤: 在turtlebot3端 启动turtlebot3 $ roslaunch turtlebot3_bringup turtlebo ...
- turtlebot matlab,Turtlebot与Matlab入门教程-控制小海龟
说明: 介绍如何在matlab中控制小海龟 步骤: 在Ubuntu端 启动roscore $ roscore 启动turtlesim $ rosrun turtlesim turtlesim_node ...
- matlab定义机器人位置,ROS与Matlab语言入门教程-差动机器人的路径跟踪
该例程演示如何使用机器人运动模型控制机器人跟踪目标路径.该例程使用"Pure Persuit"路径跟踪控制器驱动仿真机器人沿着预先决定的路径运动.要求的路径时一系列的陆标,该陆标是 ...
- matlab选址与GIS选址,ArcGIS入门教程(13)——多条件学校选址分析
实验十三 多条件学校选址分析 一.实验目的 通过本次实验,熟悉 ArcGIS 矢栅数据简单距离分析.栅格数据重分类.表面分析以及栅格计算等空间分析功能,并理解其原理:熟练掌握使用 ArcGIS 空间分 ...
- walking与Matlab入门教程-ros2命令
系列文章目录 walking与Matlab入门教程-安装matlab 2022a软件 walking与Matlab入门教程-安装visual studio 2019软件 walking与Matlab入 ...
- ESP32-C3入门教程——导读
文章目录 一.环境篇 二.基础篇 三.系统篇 四.WiFi篇 五.蓝牙篇 六.网络篇 七.IoT篇 八.问题篇 九.开源代码 十.视频演示 关于更新进度 有超链接的文章是已经完成的,可以点击跳转直接看 ...
- ros2与windows入门教程-windows上安装ROS2 foxy
系列文章目录 ros2与windows入门教程-windows上安装ROS2 foxy ros2与windows入门教程-控制小乌龟 ros2与windows入门教程-监听和发布话题 ros2与win ...
- matlab中if语句多个_MATLAB入门教程 | 003基础知识
一.认识MATLAB 1. MATLAB概述 (1)在欧美各高等学校, Matlab成为线性代数.自动控制理论.数字信号处理.时间序列分析.动态系统仿真.图像处理等诸多课程的基本教学工具,成为本科生. ...
- 图像设定阈值二值matlab,“图像类型转换II——使用“导入、导出和转换”中的“阈值法”转换为二值图像”,MATLABImageProcessingToolbox,入门教程,七,之...
1 imbinarize函数 在 [MATLAB Image Processing Toolbox 入门教程二]快速入门之"亮度校正"和"目标识别" 中我们已经 ...
最新文章
- php除去重复数组算法,如何从PHP中的多维数组中删除重复值
- You are using pip version 8.1.1, however version 20.1.1 is available
- 组件生命周期管理和通信方案
- 解惑:什么才是真正的迅驰2平台本本
- oracle long转为string,实现全局拦截前端传入的Long类型id转String
- 《深度学习》图像超分初识
- 卡尔曼滤波估算车辆质量——matab simulink仿真
- 大数据培训:小白如何学好大数据
- b站黑马springCloud-常见面试题,多多三连
- 使用pgd和fgsm方法进行攻击并使用map方法评估
- gms认证流程_Android P(9.0)GMS认证新要求
- ruby 之watir
- 计算机系统盘怎么扩充,Win7如何给C盘扩容 Win7系统电脑C盘扩容的办法
- 考研单词记录 4.11day4
- Excel学习日记:L19-定义名称Indirect函数下拉选单设定
- 小程序开发费用一览表,如果你也想要用低成本制作出自己的小程序,来了解一下!
- 小红书商城店铺所有商品接口(整店商品API接口)
- 纯HTML+CSS带说明的黄色导航菜单
- 个人网站性能优化经历(10)网站增加访客记录
- JavaSE基础知识之常用类和集合
热门文章
- resnet50过拟合处理
- PHP的几种数据类型
- 在Tomcat中添加支持3GP/MP4格式文件的下载
- mysql怎么建组合索引_mysql索引及建立组合索引原则
- Vue 基础快速入门(二)
- 期权、期货及其他衍生品 Chapter13 二叉树
- 手机免费远程控制电脑,RdViewer远程管理 1.5.0,取代常常断线的TeamViewer,外网内网都能用,是你们要的一键傻瓜版!
- 寒假“最小生成树”题解
- android fps 获取,Android下获取FPS的几种方法
- 游戏中的FPS是啥意思?