Plot binaryOccupancyMap in Matlab App Designer

1 visualizzazione (ultimi 30 giorni)
Hello, I am trying to plot the path plan plot generated from using the A* hybrid path plan planner. Howerver, not sure how to plot it on the Matlab App Designer.
I included the original code I used for path planning where I can generate a plot.
I believe the bit I still need to implement in the App Designer is the show(binaryOccupancyMap(localmatrixmap)) bit.
This is what I got so far in the Matlab App Designer:
% Button pushed function: PlotpathplanButton
function PlotpathplanButtonPushed(app, event)
startPose = [50 30 pi/2]; %pi/2 is forward, pi is left, -pi/2 down, 0 right
goalPose = [51 71 pi/2];
% Create a binary occupancy map
map = vehicleCostmap(app.localmatrixmap);%vehicleCostmap/binaryOccupancyMap
%map.CollisionChecker = inflationCollisionChecker("InflationRadius",7);
%Specify the collision-checking configuration in the CollisionChecker property of the costmap.
%NOTE: InflationRadius and VehicleDimensions properties have been removed
%since R2020b
vehicleDims = vehicleDimensions(4.5,1.7); % 1 m long, 1 m wide
numCircles = 3;
ccConfig = inflationCollisionChecker(vehicleDims,numCircles);
map.CollisionChecker = ccConfig;
%Create a state space
stateSpace = stateSpaceSE2;
% Update state space bounds to be the same as map limits - used in binarymap not vehiclecostMap
%stateSpace.StateBounds = [map.XWorldLimits;map.YWorldLimits;[-pi pi]];
% Construct a state validator object using the statespace and map object
validator = validatorVehicleCostmap(stateSpace,Map=map);
%validator = validatorOccupancyMap(stateSpace,Map=map);
% Set the validation distance for the validator
validator.ValidationDistance = 0.01;
% PROPERTIES - Assign the state validator object to the plannerHybridAStar object
%planner = plannerHybridAStar(validator,AnalyticExpansionInterval=5,InterpolationDistance=5,NumMotionPrimitives=5,DirectionSwitchingCost=10), MotionPrimitiveLength=3;
planner = plannerHybridAStar(validator,InterpolationDistance=2,AnalyticExpansionInterval=1,NumMotionPrimitives=5);
%planner = plannerHybridAStar(validator);
% Compute a path for the given start and goal poses
%pathObj = plan(planner,startPose,goalPose,SearchMode='exhaustive');
pathObj = plan(planner,startPose,goalPose);
% Extract the path poses from the path object
hybridPath = pathObj.States;
show(binaryOccupancyMap(app.localmatrixmap))
hold on
% Start state
scatter(app.UIAxes_3,startPose(1,1),startPose(1,2),"g","filled")
% Goal state
scatter(app.UIAxes_3,goalPose(1,1),goalPose(1,2),"r","filled")
% Path
legend(app.UIAxes_3,"Start Pose","Goal Pose","Hybrid A* Generated Path")
legend(app.UIAxes_3,Location="northwest")
set(app.UIAxes_3,'YDir','normal') %use 'reverse' if required to flip the x-axis
%Plot path map - UIAXES_3
plot(app.UIAxes_3,hybridPath(:,1),hybridPath(:,2),"r-",LineWidth=2)
rotate3d(app.UIAxes_2,'on')
%app.UIAxes_3.XLim = [35 70];
%app.UIAxes_3.YLim = [35 70];
view(app.UIAxes_3, 2);
disp('Path map plotted');
%Angles in degrees
app.hybridPathInDegrees = hybridPath;
app.hybridPathInDegrees(:,3) = 180/pi * hybridPath(:,3);
end
  3 Commenti
JIAN-HONG YE ZHU
JIAN-HONG YE ZHU il 24 Apr 2023
I managed to plot it by using surf() and using scatter3 upon the surf() plot.
I think show() and binaryOccupancyMap() are not supported by the Matlab App Designer, at least from what I have looked at the UIAxes Matlab webpage?
Walter Roberson
Walter Roberson il 24 Apr 2023
Unfortunately I do not have that toolbox to test with.

Accedi per commentare.

Risposte (1)

Praveen Reddy
Praveen Reddy il 10 Mag 2023
Modificato: Praveen Reddy il 12 Mag 2023
Hi JIAN-HONG,
I understand that you are trying to create an app to plot the path plan generated from A* hybrid path and unable to use ‘show()’ method to display the binary occupancy grid in the app UI axis. You can pass app UI axis object to the show() method as suggested below.
boMap=binaryOccupancyMap(app.localmatrixmap);
show(boMap, 'Parent', app.UIAxes);
Here is the modified call back function and few properties:
properties (Access = private)
localmatrixmap;
hybridPath;
hybridPathInDegrees;
end
function PlotPathPlanButtonPushed(app, event)
localstructmap=load("localmap.mat");
app.localmatrixmap=cell2mat(struct2cell(localstructmap));
tic
startPose = [50 30 pi/2]; %pi/2 is forward, pi is left, -pi/2 down, 0 right
goalPose = [51 71 pi/2];
% Create a binary occupancy map
map = vehicleCostmap(app.localmatrixmap);%vehicleCostmap/binaryOccupancyMap
%map.CollisionChecker = inflationCollisionChecker("InflationRadius",7);
%Specify the collision-checking configuration in the CollisionChecker property of the costmap.
%NOTE: InflationRadius and VehicleDimensions properties have been removed
%since R2020b
vehicleDims = vehicleDimensions(4.5,1.7); % 1 m long, 1 m wide
numCircles = 3;
ccConfig = inflationCollisionChecker(vehicleDims,numCircles);
map.CollisionChecker = ccConfig;
%Create a state space
stateSpace = stateSpaceSE2;
% Update state space bounds to be the same as map limits - used in binarymap not vehiclecostMap
%stateSpace.StateBounds = [map.XWorldLimits;map.YWorldLimits;[-pi pi]];
% Construct a state validator object using the statespace and map object
validator = validatorVehicleCostmap(stateSpace,Map=map);
%validator = validatorOccupancyMap(stateSpace,Map=map);
% Set the validation distance for the validator
validator.ValidationDistance = 0.01;
% PROPERTIES - Assign the state validator object to the plannerHybridAStar object
%planner = plannerHybridAStar(validator,AnalyticExpansionInterval=5,InterpolationDistance=5
% ,NumMotionPrimitives=5,DirectionSwitchingCost=10), MotionPrimitiveLength=3;
planner = plannerHybridAStar(validator,InterpolationDistance=2,AnalyticExpansionInterval=1, ...
NumMotionPrimitives=5);
%planner = plannerHybridAStar(validator);
% Compute a path for the given start and goal poses
%pathObj = plan(planner,startPose,goalPose,SearchMode='exhaustive');
pathObj = plan(planner,startPose,goalPose);
% Extract the path poses from the path object
app.hybridPath = pathObj.States;
boMap=binaryOccupancyMap(app.localmatrixmap);
show(boMap, 'Parent', app.UIAxes);
hold(app.UIAxes,'on');
% Start state
scatter(app.UIAxes,startPose(1,1),startPose(1,2),"g","filled");
hold(app.UIAxes,'on');
% Goal state
scatter(app.UIAxes,goalPose(1,1),goalPose(1,2),"r","filled");
hold(app.UIAxes,'on');
% Path
plot(app.UIAxes,app.hybridPath(:,1),app.hybridPath(:,2),"r-",LineWidth=2);
title(app.UIAxes,'Path Planning Map')
legend(app.UIAxes,"Start Pose","Goal Pose","Hybrid A* Generated Path")
legend(app.UIAxes,Location="northwest")
set(app.UIAxes,'YDir','normal') %use 'reverse' if required to flip the x-axis
%Angles in degrees
app.hybridPathInDegrees = app.hybridPath;
app.hybridPathInDegrees(:,3) = 180/pi * app.hybridPath(:,3);
toc
end
Refer the attached “.mlapp” file which plots the path plan.
Please refer to the following MATLAB documentation to know more about "show()" method : https://www.mathworks.com/help/nav/ref/binaryoccupancymap.show.html

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by