MATLAB移动机器人搬运教程2.

您所在的位置:网站首页 matlab轨迹跟踪 MATLAB移动机器人搬运教程2.

MATLAB移动机器人搬运教程2.

2023-03-25 09:20| 来源: 网络整理| 查看: 265

原文链接:机器翻译莫见怪哈!

openExample('robotics/PathFollowingControllerExample')

这个例子演示了如何使用机器人模拟器控制机器人沿着所需的路径行驶。 该示例使用纯追逐路径跟踪控制器来驱动模拟机器人沿预定路径行驶。 所需路径是使用路径规划器明确定义或计算的一组路点(请参阅不同复杂环境中的路径规划)。 建立了用于模拟差动驱动机器人的纯追踪路径跟踪控制器,并计算控制命令以跟踪给定的路径。 基于纯追踪控制器,计算出的控制命令用于驱动模拟机器人沿着期望的轨迹沿着期望的路径前进。

注意:从R2016b开始,不使用Step方法来执行系统对象™定义的操作,而是可以使用参数调用对象,就像它是一个函数一样。 例如,y=step(obj,x)和y=obj(X)执行相同的操作。

定义航路点

定义机器人所需路径的一组路点

path = [2.00 1.00; 1.25 1.75; 5.25 8.25; 7.25 8.75; 11.75 10.75; 12.00 10.00];

按照路径定义设置机器人的当前位置和目标位置。

robotInitialLocation = path(1,:); robotGoal = path(end,:);

假定机器人初始方向(机器人方向是机器人头部和正X轴之间的角度,逆时针测量)。

initialOrientation = 0;

定义机器人的当前姿势[x y theta]

robotCurrentPose = [robotInitialLocation initialOrientation]';

创建机器人运动学模型

初始化机器人模型并指定初始姿势。 模拟的机器人具有两轮差动驱动机器人的运动学方程。 这个模拟机器人的输入是线速度和角速度。

robot = differentialDriveKinematics("WheelRadius",0.1525,"TrackWidth", 0.5940, "VehicleInputs", "VehicleSpeedHeadingRate");

设想所需路径

figure plot(path(:,1), path(:,2),'k--d') xlim([0 13]) ylim([0 13])

定义路径跟踪控制器

基于上面定义的路径和机器人运动模型,您需要一个路径跟随控制器来沿路径驱动机器人。 使用 controllerPurePursuit对象创建路径跟随控制器。

controller = controllerPurePursuit;

使用上面定义的路径为控制器设置所需的路点

controller.Waypoints = path;

根据控制器参数设置路径。 在本例中,所需的线速度设置为0.6米/秒。

controller.DesiredLinearVelocity = 0.6;

最大角速度用作旋转速度的饱和限制,在本例中设置为2弧度/秒。

controller.MaxAngularVelocity = 2;

一般来说,对于平滑路径,前视距离应大于所需的线速度。当前方距离较大时,机器人可能会抄近路。相反,很小的向前看距离会导致不稳定的路径跟随行为。本例选择的值为0.3 m。

controller.LookaheadDistance = 0.3;

使用路径跟踪控制器,驱动机器人越过所需的航路点

路径跟踪控制器为机器人提供输入控制信号,机器人使用这些信号驱动自己沿着所需的路径前进。

定义目标半径,即机器人最终位置和目标位置之间所需的距离阈值。 一旦机器人到达目标的这个距离内,它就会停下来。 此外,还可以计算机器人位置和目标位置之间的当前距离。 根据目标半径连续检查该距离,当该距离小于目标半径时,机器人停止。

请注意,目标半径值太小可能导致机器人错过目标,这可能导致目标附近出现意外行为。

goalRadius = 0.1; distanceToGoal = norm(robotInitialLocation - robotGoal);

controllerPurePursuit对象为机器人计算控制命令。 使用这些控制命令驱动机器人,直到它到达目标半径内。 如果您使用的是外部模拟器或物理机器人,则应将控制器输出应用于机器人,并且可能需要定位系统来更新机器人的姿势。 控制器以10HZ的频率运行。

% Initialize the simulation loop sampleTime = 0.1; vizRate = rateControl(1/sampleTime); % Initialize the figure figure % 确定车架尺寸,以便用plotTransforms最接近地表示车辆 % Determine vehicle frame size to most closely represent vehicle with plotTransforms frameSize = robot.TrackWidth/0.8; while( distanceToGoal > goalRadius ) % Compute the controller outputs, i.e., the inputs to the robot [v, omega] = controller(robotCurrentPose); % Get the robot's velocity using controller inputs vel = derivative(robot, robotCurrentPose, [v omega]); % Update the current pose robotCurrentPose = robotCurrentPose + vel*sampleTime; % Re-compute the distance to the goal distanceToGoal = norm(robotCurrentPose(1:2) - robotGoal(:)); % Update the plot hold off % Plot path each instance so that it stays persistent while robot mesh % moves plot(path(:,1), path(:,2),"k--d") hold all % Plot the path of the robot as a set of transforms plotTrVec = [robotCurrentPose(1:2); 0]; plotRot = axang2quat([0 0 1 robotCurrentPose(3)]); plotTransforms(plotTrVec', plotRot, "MeshFilePath", "groundvehicle.stl", "Parent", gca, "View","2D", "FrameSize", frameSize); light; xlim([0 13]) ylim([0 13]) waitfor(vizRate); end

将路径跟踪控制器与PRM一起使用

如果路径规划器计算出所需的路点集合,则可以以相同的方式使用路径跟随控制器。 首先,将地图可视化。

load exampleMaps map = binaryOccupancyMap(simpleMap); figure show(map)

您可以使用PRM路径规划算法计算路径。有关详细信息,请参见不同复杂性环境中的路径规划。

mapInflated = copy(map); inflate(mapInflated, robot.TrackWidth/2); prm = robotics.PRM(mapInflated); prm.NumNodes = 100; prm.ConnectionDistance = 10;

查找起始位置和结束位置之间的路径。 请注意,由于PRM算法的概率性质,路径将不同。

startLocation = [4.0 2.0]; endLocation = [24.0 20.0]; path = findpath(prm, startLocation, endLocation)

path = 7×2 4.0000 2.0000 4.6385 1.8203 5.3074 11.7062 13.5243 17.0382 21.8564 19.4645 24.3415 19.9228 24.0000 20.0000

显示展开的地图,路线图和最终路径。

show(prm);

您定义了一个路径跟踪控制器,在此控制器之上,您可以重复使用该控制器来计算此地图上机器人的控制命令。 要重复使用控制器并重新定义路点,同时保持其他信息不变,请使用 release 函数。

release(controller); controller.Waypoints = path;

按照路径定义设置机器人的初始位置和目标

robotInitialLocation = path(1,:); robotGoal = path(end,:);

假设机器人的初始方位

initialOrientation = 0;

定义机器人运动的当前姿势[x y theta]

robotCurrentPose = [robotInitialLocation initialOrientation]';

计算到目标位置的距离

distanceToGoal = norm(robotInitialLocation - robotGoal);

定义目标半径

goalRadius = 0.1;

使用给定地图上的控制器输出来驱动机器人,直到它到达目标。 控制器以10赫兹的频率运行。

reset(vizRate); % Initialize the figure figure while( distanceToGoal > goalRadius ) % Compute the controller outputs, i.e., the inputs to the robot [v, omega] = controller(robotCurrentPose); % Get the robot's velocity using controller inputs vel = derivative(robot, robotCurrentPose, [v omega]); % Update the current pose robotCurrentPose = robotCurrentPose + vel*sampleTime; % Re-compute the distance to the goal distanceToGoal = norm(robotCurrentPose(1:2) - robotGoal(:)); % Update the plot hold off show(map); hold all % Plot path each instance so that it stays persistent while robot mesh % moves plot(path(:,1), path(:,2),"k--d") % Plot the path of the robot as a set of transforms plotTrVec = [robotCurrentPose(1:2); 0]; plotRot = axang2quat([0 0 1 robotCurrentPose(3)]); plotTransforms(plotTrVec', plotRot, 'MeshFilePath', 'groundvehicle.stl', 'Parent', gca, "View","3D", "FrameSize", frameSize); light; xlim([0 27]) ylim([0 26]) waitfor(vizRate); end



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3