关于matlab地图规划代码的一些思路

本文介绍了一个使用MATLAB实现的地图规划代码,包括PRM路径规划、RRT算法以及GUI界面。代码涉及了不同移动机器人模型(如单轮、双轮差速和自行车模型),并使用纯追踪控制器进行轨迹规划。通过GUI,用户可以输入起点和终点坐标,选择地图类型和路径规划算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于matlab 地图规划代码的一些思路

可以做demo的用x代替

 

occupancyMatrix = readmatrix('navigation map x ');

 

map = binaryOccupancyMap(occupancyMatrix);

 

show(map)

 

 

 

 

robotRadius = x ;

 

mapInflated = copy(map);

inflate(mapInflated,robotRadius);

 

show(mapInflated);

 

prm = mobileRobotPRM;

prm.Map = mapInflated;

prm.NumNodes = x ;

prm.ConnectionDistance = x;

startLocation = [x x];

endLocation = [x x];

 

path=findpath(prm, startLocation, endLocation);

 

while isempty(path)

    % No feasible path found yet, increase the number of nodes

    prm.NumNodes = prm.NumNodes + x;

    

    % Use the |update| function to re-create the PRM roadmap with the changed

    % attribute

    update(prm);

    

    % Search for a feasible path with the updated PRM

    path = findpath(prm, startLocation, endLocation);

end

 

path

 

show(prm)

 

    1. The code for the kinetic vehicle

%define the condition

unicycle = unicycleKinematics("VehicleInputs","VehicleSpeedHeadingRate");

diffDrive = differentialDriveKinematics("VehicleInputs","VehicleSpeedHeadingRate");

diffDrive.WheelSpeedRange = [-10 10]*2*pi;

bicycle = bicycleKinematics("VehicleInputs","VehicleSpeedHeadingRate","MaxSteeringAngle",pi/8);

carLike = ackermannKinematics;

 

%set up simulation parameters

waypoints = [path];

% Define the total time and the sample rate

sampleTime = x;               % Sample time [s]

tVec = 0:sampleTime:x;          % Time array

 

initPose = [waypoints(1,:)'; 0]; % Initial pose (x y theta)

 

%create controller

% Define a controller. Each robot requires its own controller

controller1 = controllerPurePursuit("Waypoints",waypoints,"DesiredLinearVelocity",3,"MaxAngularVelocity",3*pi);

controller2 = controllerPurePursuit("Waypoints",waypoints,"DesiredLinearVelocity",3,"MaxAngularVelocity",3*pi);

controller3 = controllerPurePursuit("Waypoints",waypoints,"DesiredLinearVelocity",3,"MaxAngularVelocity",3*pi);

 

goalPoints = waypoints(end,:)';

goalRadius = 1;

 

% Compute trajectories for each kinematic model under motion control

[tUnicycle,unicyclePose] = ode45(@(t,y)derivative(unicycle,y,exampleHelperMobileRobotController(controller1,y,goalPoints,goalRadius)),tVec,initPose);

[tBicycle,bicyclePose] = ode45(@(t,y)derivative(bicycle,y,exampleHelperMobileRobotController(controller2,y,goalPoints,goalRadius)),tVec,initPose);

[tDiffDrive,diffDrivePose] = ode45(@(t,y)derivative(diffDrive,y,exampleHelperMobileRobotController(controller3,y,goalPoints,goalRadius)),tVec,initPose);

 

unicycleTranslations = [unicyclePose(:,1:2) zeros(length(unicyclePose),1)];

unicycleRot = axang2quat([repmat([0 0 1],length(unicyclePose),1) unicyclePose(:,3)]);

 

bicycleTranslations = [bicyclePose(:,1:2) zeros(length(bicyclePose),1)];

bicycleRot = axang2quat([repmat([0 0 1],length(bicyclePose),1) bicyclePose(:,3)]);

 

diffDriveTranslations = [diffDrivePose(:,1:2) zeros(length(diffDrivePose),1)];

diffDriveRot = axang2quat([repmat([0 0 1],length(diffDrivePose),1) diffDrivePose(:,3)]);

 

figure

plot(waypoints(:,1),waypoints(:,2),"kx-","MarkerSize",20);

hold all

plotTransforms(unicycleTranslations(1:10:end,:),unicycleRot(1:10:end,:),'MeshFilePath','groundvehicle.stl',"MeshColor","r");

plotTransforms(bicycleTranslations(1:10:end,:),bicycleRot(1:10:end,:),'MeshFilePath','groundvehicle.stl',"MeshColor","b");

plotTransforms(diffDriveTranslations(1:10:end,:),diffDriveRot(1:10:end,:),'MeshFilePath','groundvehicle.stl',"MeshColor","g");

view(0,90)

 

    1. The code for the RRT

ss = stateSpaceSE2;

sv = validatorOccupancyMap(ss);

 

occupancyMatrix = readmatrix('navigation map 2');

 

map = occupancyMap(occupancyMatrix,10);

sv.Map = map;

sv.ValidationDistance = x;

ss.StateBounds = [map.XWorldLimits;map.YWorldLimits; [-pi pi]];

planner = plannerRRT(ss,sv);

planner.MaxConnectionDistance = 0.3;

start = [x x];

goal = [x ,x ,0];

rng(100,'twister'); % for repeatable result

[pthObj,solnInfo] = plan(planner,start,goal);

show(map)

hold

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值