Question: fix this code to run on matlab % Load a pre - generated occupancy map ( replace with your own ) load ( ' office

fix this code to run on matlab
% Load a pre-generated occupancy map (replace with your own)
load('office_area_gridmap.mat',"occGrid")
show(occGrid);
% Specify start and goal poses (adjust as needed)
startPose =[2,3,-pi]; % starting coordinates
goalPose =[15,8,0]; % goal coordinates
% Visualize the map with start and goal
figure;
hold on;
plot(startPose(1), startPose(2),'go'); % Green start marker
plot(goalPose(1), goalPose(2),'ro'); % Red goal marker
% show start and goal heading
r =0.6;
plot([startPose(1), startPose(1)+ r*cos(startPose(3))],[startPose(2), startPose(2)+ r*sin(startPose(3))],'g-')
plot([goalPose(1), goalPose(1)+ r*cos(goalPose(3))],[goalPose(2), goalPose(2)+ r*sin(goalPose(3))],'r-')
hold off;
title('Occupancy Map with Start and Goal');
% Create a state space for a Dubins car (simple model with turning radius)
% Set the state bounds of the map (adjust to match your occupancy map)
% Set the state bounds of the map (adjust to match your occupancy map)
% Specify the turning radius
ss = stateSpaceDubins;
ss.MinTurningRadius =0.5;
ss.StateBounds =[occGrid.XWorldLimits; occGrid.YWorldLimits; [-pi pi]];
% Create an occupancy map validator (checks collisions)
stateValidator = validatorOccupancyMap(ss);
stateValidator.Map = occGrid;
stateValidator.ValidationDistance =0.2; % Reduce for finer path checking
% Create the RRT planner
planner = plannerRRT(ss, stateValidator);
planner.MaxConnectionDistance =2; % Adjust connection distance
planner.MaxIterations =30400;
planner.GoalReachedFcn = @isGoalReached; % Custom goal-checking function
% Plan the path
[pthObj, solnInfo]= plan(planner, startPose, goalPose);
% Plot the planned path
figure ;
show(occGrid);
hold on;
plot(solnInfo.TreeData(:,1), solnInfo.TreeData(:,2),'.-'); % Tree
plot(pthObj.States(:,1), pthObj.States(:,2),'r-'); % Path
plot(startPose(1), startPose(2),'go');
plot(goalPose(1), goalPose(2),'ro');
hold off;
title('Planned Path with RRT');

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!