walking与Matlab入门教程-介绍示例模型
系列文章目录
walking与Matlab入门教程-安装matlab 2022a软件
walking与Matlab入门教程-安装visual studio 2019软件
walking与Matlab入门教程-安装python和cmake环境
walking与Matlab入门教程-介绍示例模型
walking与Matlab入门教程-连接到walking机器人
walking与Matlab入门教程-查看话题内容
walking与Matlab入门教程-订阅雷达、里程计、相机信息
walking与Matlab入门教程-发布里程计并使用订阅者回调绘制位置
walking与Matlab入门教程-控制walking机器人移动
walking与Matlab入门教程-从Simulink生成代码来创建ROS2节点
walking与Matlab入门教程-ros2命令
说明:
- 介绍在Matlab的示例模型
示例模型:
- 键盘控制 exampleHelperROS2TurtleBotKeyboardControl.m
function poses = exampleHelperROS2TurtleBotKeyboardControl(handles)
keyObj = ExampleHelperTurtleBotKeyInput();
velMsg = ros2message(handles.velPub);
reply = 0;while reply~='q'forwardV = 0; % Initialize linear and angular velocitiesturnV = 0; reply = getKeystroke(keyObj);switch replycase 'i' % iforwardV = 0.5;case 'k' % kforwardV = -0.5;case 'j' % jturnV = 1;case 'l' % lturnV = -1;endvelMsg.linear.x = forwardV;velMsg.angular.z = turnV;send(handles.velPub,velMsg);odomMsg = handles.odomSub.LatestMessage;handles.poses = [handles.poses;exampleHelperGet2DPose(odomMsg)]; endposes = handles.poses;closeFigure(keyObj);
end
- 键盘控制 ExampleHelperTurtleBotKeyInput.m
classdef ExampleHelperTurtleBotKeyInput < handle%ExampleHelperTurtleBotKeyInput - Class for obtaining keyboard input% OBJ = ExampleHelperTurtleBotKeyInput() creates a figure with instructions for Turtlebot% keyboard control. The object keeps track of the figure and axes handles% and converts keyboard input into ASCII values.%% ExampleHelperTurtleBotKeyInput methods:% getKeystroke - Returns ASCII value for keystroke% closeFigure - Closes the figure and cleans up%% ExampleHelperTurtleBotKeyInput properties:% Figure - Stores the figure handle% Axes - Stores the axes handle%% See also exampleHelperTurtleBotKeyboardControl% Copyright 2014-2015 The MathWorks, Inc.propertiesFigure = []; % Stores the figure handleAxes = []; % Stores the axes handleendmethodsfunction obj = ExampleHelperTurtleBotKeyInput()%ExampleHelperTurtleBotKeyInput - Constructor for KeyInput classcallstr = 'set(gcbf,''Userdata'',double(get(gcbf,''Currentcharacter''))) ; uiresume ' ;obj.Figure = figure(...'Name','Press a key', ...'KeyPressFcn',callstr, ...'Position',[500 500 500 300],...'UserData','Timeout');obj.Axes = axes('Color','k','Visible','Off','XLim',[0,100],'YLim',[0,100]);text(50,80,'i = Forward','HorizontalAlignment','center','EdgeColor','k');text(50,40,'k = Backward','HorizontalAlignment','center','EdgeColor','k');text(25,60,'j = Left','HorizontalAlignment','center','EdgeColor','k');text(75,60,'l = Right','HorizontalAlignment','center','EdgeColor','k');text(50,20,'q = Quit','HorizontalAlignment','center','EdgeColor','r');text(50,0,'Keep this figure in scope to give commands','HorizontalAlignment','center');endfunction keyout = getKeystroke(obj)%GETKEYSTROKE - Returns ASCII value for keystroketryuiwait(obj.Figure);keyout = get(obj.Figure,'Userdata') ;catchkeyout = 'q';endendfunction closeFigure(obj)%CLOSEFIGURE - Closes the figure and cleans uptryfigure(obj.Figure);close(obj.Figure);catchendendendend
- 绘制雷达数据 ExampleHelperQoSTurtleBotPlotScan.m
function ExampleHelperQoSTurtleBotPlotScan(scanMsg,plotobj,odomSub)
% Lidar subscriber's callback to plot the latest odometry and lidar sensor
% readingodomMsg = odomSub.LatestMessage;
% laserdata = rosReadCartesian(scanMsg);
laserdata = rosReadCartesian(scanMsg);
pose = readPose(odomMsg);
plotData(plotobj,pose,laserdata * [0 1; -1 0]);
endfunction pose = readPose(msg)
%readPose Extract the robot odometry reading as [x y theta] vector
poseMsg = msg.pose.pose;% Extract the x, y, and theta coordinates
xpos = poseMsg.position.x;
ypos = poseMsg.position.y;
quat = poseMsg.orientation;
angles = quat2eul([quat.w quat.x quat.y quat.z]);
theta = angles(1);pose = [xpos, ypos, theta];
end
- 绘制相机数据 ExampleHelperQoSTurtleBotPlotImage.m
function ExampleHelperQoSTurtleBotPlotImage(imageMsg,AxesHandleCamera)
img = permute(reshape(imageMsg.data,[3 1280 720]),[3 2 1]); % to be updated with rosReadImage
image(AxesHandleCamera,img)
end
- 绘制里程计数据 exampleHelperROS2PlotOdom.m
function exampleHelperROS2PlotOdom(msg,hAxes,linespec)
%exampleHelperROS2PlotOdom Subscriber callback function for odometry data
% exampleHelperROS2PlotOdom(MESSAGE,AXES,LINESPEC) returns no arguments.
% Instead it plots the position of the robot, using the provided marker,
% and noting the timestamp of the message next to the position.
%
% See also ManageQualityOfServicePoliciesInROS2Example.% Copyright 2019 The MathWorks, Inc.% Set up axes
hold(hAxes,"on")% Plot the robot position
msgTimestamp = double(msg.header.stamp.sec)+...double(msg.header.stamp.nanosec)*1e-9;
plot(hAxes,msg.pose.pose.position.x,msg.pose.pose.position.y,linespec)
text(hAxes,msg.pose.pose.position.x,msg.pose.pose.position.y,sprintf(" %.0d",msgTimestamp))
end
- 获取位置信息 exampleHelperGet2DPose.m
function pose = get2DPose(odomMsg)
% GET2DPOSE Helper function that extracts [x y theta] 2D pose
% from a ROS odometry message.
% Copyright 2018 The MathWorks, Inc.% Unwrap positionposition = odomMsg.pose.pose.position;x = position.x;y = position.y;% Unwrap orientationorientation = odomMsg.pose.pose.orientation;q = [orientation.w, orientation.x, ...orientation.y, orientation.z];r = quat2eul(q);theta = r(1); % Extract Z componentpose = [x, y, theta];end
- 处理传感数据 ExampleHelperQoSTurtleBotSetupVisualizer.m
function [plotobj,axHandle,checkPointText,Axes] = ExampleHelperQoSTurtleBotSetupVisualizer(velPub)
% Initialize the visualizers of robot's current postion with Lidar scan,
% and camera images
plotobj = ExampleHelperQoSTurtleBotVisualizer([-2,6,-2,6]);
figHandle = figure('Name','Camera Image','Visible','on');
axHandle = axes('Parent',figHandle);
% Create a teleoperation controller visulizer
f = figure(...'Visible','on',...'Name','Press a key',...'KeyPressFcn',{@getKey,velPub},...'DeleteFcn',@deleteKey);Axes = axes(...f,'Color','k',...'Visible','Off',...'XLim',[0,100],...'YLim',[0,100]);
text(...Axes,50,70,'i = Forward',...'HorizontalAlignment','center',...'EdgeColor','k');
text(...Axes,50,30,'k = Backward',...'HorizontalAlignment','center',...'EdgeColor','k');
text(...Axes,25,50,'j = Left',...'HorizontalAlignment','center',...'EdgeColor','k');
text(...Axes,75,50,'l = Right',...'HorizontalAlignment','center',...'EdgeColor','k');
text(...Axes,50,10,'s = Stop',...'HorizontalAlignment','center',...'EdgeColor','r');
text(...Axes,50,0,'Keep this figure in scope to give commands',...'HorizontalAlignment','center');
checkPointText = text(...Axes,20,90,'Find the next sign!',...'HorizontalAlignment','center',...'FontSize',14,...'FontWeight','bold',...'Color','b');
endfunction getKey(~,eventData,velPub)
% getKey UI callback to read a key pressed and send the velocity command
keyPressed = eventData.Key;
switch keyPressedcase 'i' % iforwardV = 0.3;turnV = 0;case 'k' % kforwardV = -0.3;turnV = 0;case 'j' % jforwardV = 0;turnV = 0.3;case 'l' % lforwardV = 0;turnV = -0.3;case 's'forwardV = 0;turnV = 0;
end
if isempty(forwardV) || isempty(turnV)forwardV = 0;turnV = 0;
end
setVel(velPub,forwardV,turnV);
endfunction deleteKey(obj,~)
obj.KeyPressFcn = [];
endfunction setVel(pub,vLin,vAng)
velMsg = ros2message(pub);
velMsg.linear.x = vLin;
velMsg.angular.z = vAng;
send(pub,velMsg);
end
walking与Matlab入门教程-介绍示例模型相关推荐
- walking与Matlab入门教程-ros2命令
系列文章目录 walking与Matlab入门教程-安装matlab 2022a软件 walking与Matlab入门教程-安装visual studio 2019软件 walking与Matlab入 ...
- 【台大郭彦甫】Matlab入门教程超详细学习笔记二:基本操作与矩阵运算(附PPT链接)
Matlab入门教程超详细学习笔记二:基本操作与矩阵运算 前言 一.基本操作 1.把matlab当作计算器使用 2.变量 3.控制格式输出 二.矩阵运算 1.矩阵 2.矩阵索引 3.使用:创建向量 4 ...
- MATLAB入门教程(基础知识点)
转自: http://blog.csdn.net/lxdfigo/article/details/8279962 MATLAB入门教程 1.MATLAB的基本知识 1-1.基本运算与函数 ...
- 数模matlab入门教程-001-xlsread用法
数模matlab入门教程-001 1.函数介绍 2.数据读入 3.后续内容 数模要开始了,整理了一些基本资料提供给没有基础的同学.本文以2017届D题为例,21天数学建模从入门到精通. 这个题目可以在 ...
- Matlab 入门教程
入门教程 Getting started Matlab入门教程音频:00:0002:09 Matlab软件介绍 Matlab software introduction Matlab和Mathemat ...
- oak深度相机入门教程-创建自定义模型
系列文章目录: oak深度相机入门教程-识别眼睛的凝视方向 oak深度相机入门教程-检测是否佩戴口罩 oak深度相机入门教程-文本检测+光学字符识别(OCR)管道 oak深度相机入门教程-识别人的 ...
- oak深度相机入门教程-使用NN模型生成点云
系列文章目录: oak深度相机入门教程-识别眼睛的凝视方向 oak深度相机入门教程-检测是否佩戴口罩 oak深度相机入门教程-文本检测+光学字符识别(OCR)管道 oak深度相机入门教程-识别人的 ...
- Koa入门教程之示例应用
Koa入门教程之示例应用 Koa范例 一个包含一些小示例的存储库,这些示例说明了如何使用Koa创建Web应用程序和其他HTTP服务器. 源码地址 https://github.com/koajs/ex ...
- Matlab入门教程--基本运算与函数(一)
Matlab入门教程--基本运算与函数(一) 在MATLAB下进行基本数学运算,只需将运算式直接打入提示号(>>)之後,并按入Enter键即可.例如: >>(5*2+1.3-0 ...
- [Matlab]入门教程基础向笔记(B站视频)
[Matlab]入门教程基础向笔记(B站视频) 快捷操作 clc:清除命令行窗口历史操作 用⬆(上箭头)表示快捷输入上一段代码 计算细节 矩阵相乘 A*B:表示现代中的相乘运算 A.B:表示各个数字分 ...
最新文章
- 判断输入的字符是不是数字
- EasyTable2.1 功能更加强大,bug全面修复的html table插件!
- 全球及中国甲基丙烯酸烷基酯行业深度研究与未来投资潜力分析报告2022版
- PyCharm编写shell脚本无法运行
- 使用Spring的缓存管理器缓存Web内容
- 【注】【精】【火】博主考研去了,现在的博文都是以前的笔记或者算法。
- linux下安装telnet服务
- Google 要放弃 Android 了?
- 如何在一场面试中展现你对Python的coding能力?
- hbase shell基础和常用命令详解
- 两个时间相减(vb.net)
- ajax实例详解(2)
- 命令行基础-tar命令详解
- Qt之调用Windows图片查看器预览图片
- Bitmap createBitmap()裁剪图片
- Java 获取月初时间
- dell笔记本外接显示器_笔记本就一个 hdmi 的接口,如何外接 2 个 dell 显示器?...
- 金山现任CEO张宏江将退休 西山居CEO继任
- [LOJ3086] [GXOI2019] 逼死强迫症
- 如何打造一个优秀的软件研发团队
热门文章
- 数据仓库之-历史数据存储方案
- 博士申请 | 美国达特茅斯学院杨耀青老师招收深度学习方向全奖博士生
- 关于Unity中unitypackage文件的图标显示及打开方式异常问题的解决
- GCD中dispatch_semaphore(信号量)的使用方法
- GEE-Python遥感大数据分析、管理与可视化
- Python股市数据分析教程——学会它,或可以实现半“智能”炒股 (Part 2)
- Removing unused resources requires unused code shrinking to be turned on
- cmd输入光标消失解决
- html 空格 正则表达式,正则表达式清除空格和html标签中的 空格
- 黑客如何用线程注射技术隐藏自己的病毒