turtlebot matlab,Turtlebot与Matlab入门教程-控制小海龟
说明:
介绍如何在matlab中控制小海龟
步骤:
在Ubuntu端
启动roscore
$ roscore
启动turtlesim
$ rosrun turtlesim turtlesim_node
在Matlab端
运行myTeleop.m文件
填写ros master IP
以及对应的话题:/turtle1/pose
点击“前进”,“后退”,“向左”,“向右”,控制机器人运动
代码如下:
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;
turtlebot matlab,Turtlebot与Matlab入门教程-控制小海龟相关推荐
- 【MATLAB Image Processing Toolbox 入门教程六】“导入、导出和转换”之“图像类型转换Ⅰ——在不同图像类型之间转换”
[MATLAB Image Processing Toolbox 入门教程六] 1 gray2ind函数 2 ind2gray函数 3 mat2gray函数 4 rgb2gray函数 5 rgb2in ...
- 【MATLAB Image Processing Toolbox 入门教程三】快速入门之“在多光谱图像中寻找植被”
[MATLAB Image Processing Toolbox 入门教程三] 本篇摘要 一.从多光谱图像文件导入彩色红外通道 二.构建近红外光谱散射图 三.计算植被系数并显示其定位 四.综合实例部分 ...
- ROS入门之使用命令行工具控制小海龟移动
前面的文章主要是说明一下ROS入门需要了解的基本概念,这篇文章则是要说明一下如何使用命令行工具. 2.1 命令行工具的使用 ROS有很多常用命令:rostopic.rosservice.rosnode ...
- ROS入门:运行小海龟
安装配置ROS可参考:https://www.ros.org/ 要注意安装的版本:Ubuntu16.04对应Kinetic版本,Ubuntu18.04对应Melodic版本 ROS学习资料: ROS官 ...
- ROS-手势控制小海龟移动
手势控制小海龟移动 这是很早之前学习ros做的一个小demo,适合初学者学习. 一.要求 要求通过电脑自带摄像头检测手势动作控制小海龟移动 二.问题分析 本设计需要运行三个节点,第一个节点为recon ...
- ROS安装和 控制小海龟画圆
1.ROS软件安装 (1)添加ROS软件源 sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -s ...
- [carla入门教程]-6 小项目:基于carla-ros-bridge构建一个小型比赛赛道
本专栏教程将记录从安装carla到调用carla的pythonAPI进行车辆操控并采集数据的全流程,带领大家从安装carla开始,到最终能够熟练使用carla仿真环境进行传感器数据采集和车辆控制. 第 ...
- matlab控制turtlebot,Turtlebot与Matlab入门教程-控制机器人
说明: 介绍如何控制机器人 步骤: 在turtlebot端 启动turtlebot $ roslaunch turtlebot_bringup minimal.launch 启动雷达 $ roslau ...
- matlab控制turtlebot,Turtlebot3与Matlab入门教程-控制移动
说明: 介绍如何使用Matlab控制turtlebot3移动 步骤: 在turtlebot3端 启动turtlebot3 $ roslaunch turtlebot3_bringup turtlebo ...
最新文章
- python高阶面试题_Python 爬虫面试题 170 道:2019 版
- 安装python时需要勾选_软件应用 | 用Python爬取网络站点数据时需要哪些必备库
- Scikit-Learn (1.Sklearn提供的常用数据集 - 自带的小数据集)
- Echarts中使用china.js
- H5+App开发框架汇总
- 南京邮电大计算机科学与技术,计算机科学与技术专业培养目标与毕业要求-南京邮电大学计算机学院.PDF...
- 记一次机房断电办公室网络瘫痪的恢复经过
- 烤仔TVのCCW | 带宽不可能三角(下)
- 七周成为数据分析师 | 数据库
- Docker中Swarm集群部署
- 【076】朴素贝叶斯介绍
- Springboot的@Aspect使用
- 关于ONVIF协议你不得不知的6个常见问题
- UI设计中图标设计规范是什么
- 启动两个80线的速腾雷达
- 个人小程序实现微信支付
- 铜陵C语言培训,铜陵学院c语言程序设计报告答案
- 简单交错序列前N项和
- matlab边坡可靠性分析,基于ABAQUS-ANFIS-MCS的岩质边坡可靠性分析
- 没有下载券和财富值如何下载文库的资料