Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 363

Answered: 1 week ago