How can make dynamic obstacles in map
34 次查看(过去 30 天)
显示 更早的评论
If i have 2D path, generated from a map. and I want to animate a robot following this path and some obstacles moves randomly in the is map
2 个评论
采纳的回答
Vinayak Choyyan
2023-2-13
Hello mohammed alany,
As per my understanding, you have a 2D path for a robot. You would like to have N number of obstacles that move randomly in the environment, and you would like to visually see this in action.
Please refer to the demo code below. I have used an ‘occupancyMap’ in this example to showcase the animation as it visually looks the most similar to the example image you have provided. Alternatively, you could also create a ‘robotScenario’ or use ‘dynamicCapsuleList’. In the code below, I have generated N=10 obstacles and moved them all diagonally upwards. You can modify the code to have each obstacle’s location be updated based on your requirement and kinematic constraints. I have set the path of the robot to move from (90,90) to (50,50). The robot is the only one moving diagonally downwards in the example. Do consider increasing timeSteps and decreasing the change in value per timeStep to have a smoother animation. But this will come at the cost of some extra performance.
clc;clear;
%create a list of starting locations for n obstacles
n=10;
timeSteps=20;
obstacleStartLocation=100.*rand(n,2);
obstacleStartLocation=ceil(obstacleStartLocation);
pathX=90:-2:90-(2*(timeSteps-1));
pathY=90:-2:90-(2*(timeSteps-1));
path=[pathX' pathY'];
for i=1:timeSteps
map = occupancyMap(zeros(100,100));%clear map
updateOccupancy(map,obstacleStartLocation,ones(10,1));%add obstacles to map
updateOccupancy(map,path(i,:),1);%add main path point for current time step
inflate(map,0.5);%make point bigger as per size of obstacles
show(map);
pause(0.1);
%update path of other obstacles randomly. I am just moving them
%diagonally upwards in this example. please change it as per your
%requiremnt
for j=1:n
obstacleStartLocation(j,1)=obstacleStartLocation(j,1)+1;
obstacleStartLocation(j,2)=obstacleStartLocation(j,2)+1;
end
end
If you wish to read more about the following, please refer to the following documentation.
- occupancyMap Create 2-D occupancy map - MATLAB - MathWorks India
- robotScenario Generate robot simulation scenario - MATLAB - MathWorks India
- dynamicCapsuleList Dynamic capsule-based obstacle list - MATLAB - MathWorks India
- Avoid Obstacles Using Reinforcement Learning for Mobile Robots Avoid Obstacles Using Reinforcement Learning for Mobile Robots - MATLAB & Simulink - MathWorks India
If you wish to read more about the functions used in the above code, please refer to these documentations
- updateOccupancy Update occupancy probability at locations - MATLAB updateOccupancy - MathWorks India
- inflate Inflate each occupied location - MATLAB inflate - MathWorks India
I hope this helps resolve the issue you were facing.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Robotics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!