matlab控制turtlebot,Turtlebot3与Matlab入门教程-控制移动
说明:
介绍如何使用Matlab控制turtlebot3移动
步骤:
在turtlebot3端
启动turtlebot3
$ roslaunch turtlebot3_bringup turtlebot3_robot.launch
在Matlab端
运行myTeleop.m文件
输入ROS_MASTERR_URI,http://192.168.0.93:11311
输入话题,/cmd_vel
按键前,后,左,右,控制机器人运动
代码如下:
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,Turtlebot3与Matlab入门教程-控制移动相关推荐
- matlab控制turtlebot,Turtlebot与Matlab入门教程-控制机器人
说明: 介绍如何控制机器人 步骤: 在turtlebot端 启动turtlebot $ roslaunch turtlebot_bringup minimal.launch 启动雷达 $ roslau ...
- turtlebot matlab,Turtlebot与Matlab入门教程-控制小海龟
说明: 介绍如何在matlab中控制小海龟 步骤: 在Ubuntu端 启动roscore $ roscore 启动turtlesim $ rosrun turtlesim turtlesim_node ...
- matlab选址与GIS选址,ArcGIS入门教程(13)——多条件学校选址分析
实验十三 多条件学校选址分析 一.实验目的 通过本次实验,熟悉 ArcGIS 矢栅数据简单距离分析.栅格数据重分类.表面分析以及栅格计算等空间分析功能,并理解其原理:熟练掌握使用 ArcGIS 空间分 ...
- walking与Matlab入门教程-ros2命令
系列文章目录 walking与Matlab入门教程-安装matlab 2022a软件 walking与Matlab入门教程-安装visual studio 2019软件 walking与Matlab入 ...
- turtlebot3入门教程
旨在用于教育,研究,产品原型和爱好应用的目的. TurtleBot3的目标是大幅降低平台的尺寸和价格,而不会牺牲性能,功能和质量. 由于提供了不同可选,如底盘,计算机和传感器,TurtleBot3 ...
- ESP32-C3入门教程——导读
文章目录 一.环境篇 二.基础篇 三.系统篇 四.WiFi篇 五.蓝牙篇 六.网络篇 七.IoT篇 八.问题篇 九.开源代码 十.视频演示 关于更新进度 有超链接的文章是已经完成的,可以点击跳转直接看 ...
- ros2与windows入门教程-windows上安装ROS2 foxy
系列文章目录 ros2与windows入门教程-windows上安装ROS2 foxy ros2与windows入门教程-控制小乌龟 ros2与windows入门教程-监听和发布话题 ros2与win ...
- turtlebot matlab,Turtlebot与Matlab入门教程-创建UI界面控制turtlebot
说明: 介绍如何创建UI界面控制turtlebot 步骤: 在turtlebot端: [turtlebot] 启动Turtlebot roslaunch turtlebot_bringup minim ...
- matlab中if语句多个_MATLAB入门教程 | 003基础知识
一.认识MATLAB 1. MATLAB概述 (1)在欧美各高等学校, Matlab成为线性代数.自动控制理论.数字信号处理.时间序列分析.动态系统仿真.图像处理等诸多课程的基本教学工具,成为本科生. ...
最新文章
- B 站神曲damedane:精髓在于换脸,五分钟就能学会
- 下位机和上位机是什么意思_焊锡机是什么?焊锡机有几种分类?
- 拾遗:『ext4 Quota』
- Flex与Java通信之HttpService方式
- 用pdftocairo将PDF图片转成svg矢量图
- 树的专项练习(补充)
- win2003服务器安全设置技术实例(一)
- 实验室只有1080显卡,老师还想让发深度学习论文怎么办?
- Android Studio的res自动生成的文件出错了_莫韵乐与bug的奇妙冒险
- 荣耀30s怎么升级鸿蒙,惊喜!4部荣耀手机可升级至华为鸿蒙系统,网友表示:终于等到了...
- 如何将平板设置为笔记本的扩展屏
- 疯子网页采集器教程之采集需要保存图片的教程
- 【Python】PyQT5+爬虫实现简单音乐下载器
- 纯前端实现—猜数字游戏
- 学计算机去海关,霜刃初试显锋芒——一次难忘的海关计算机审计经历
- python控制打印机
- 【计算机基础】组建局域网
- vue、vue 所有图标属性、vue Icon 所有图标属性、vue 图标所有类型属性、vue 自定义图标 Icon属性
- Java2048朝代版
- 二十分钟构建猫VS狗图像分类器