map of outline robot

3 views (last 30 days)
Muhammad
Muhammad on 8 Dec 2022
Commented: Fifteen12 on 9 Dec 2022
hip shared below but I do not understand how to code this in Matlab as I am a nwbie with very less understanding of Matlab.

Accepted Answer

Fifteen12
Fifteen12 on 8 Dec 2022
For animation techniques to make the robot move, you might want to check this out: https://www.mathworks.com/help/matlab/creating_plots/animation-techniques-1.html
For mapping your robot onto some space, what you have is the centroid of the object and it's orientation. Imagine the robot is a box, you have the (x,y) point of it's centroid, as well as which direction the robot is facing. As for the obstacle, I assume you know the orientation of the IR sensor?
The rotation matrix you pasted in the question is good for getting the coordinates of the box around the centroid. To graph an arbitary patch you can do the following:
figure(1)
axis([-10, 10, -10, 10])
h = drawBox(0, 0, 0);
pause(1)
delete(h)
h = drawBox(3, 3, pi/4);
function [handle] = drawBox(x, y, theta)
width = 5;
height = 8;
% Get coordinates of box corners if it was at the origin
x0_coord = [-width / 2, width / 2, width / 2, -width / 2];
y0_coord = [-height / 2, -height / 2, height / 2, height / 2];
% Rotate by theta
rotation = [cos(theta), -sin(theta); sin(theta), cos(theta)];
% Translate to new x,y location
for i = 1:4
to_shift(:,i) = rotation * [x0_coord(i); y0_coord(i)];
end
shifted_coord = [x; y] + to_shift;
% Plot
handle = patch(...
'Vertices', [shifted_coord(1,:); shifted_coord(2,:)]', 'Faces', [1 2 3 4],...
'FaceColor','k','EdgeColor','k','LineWidth',2);
end
  2 Comments
Muhammad
Muhammad on 8 Dec 2022
Hi John, I need an outline map of the obstacle, this creates a black box even though the obstacle has to look like this.
Fifteen12
Fifteen12 on 9 Dec 2022
Hi Muhammad, the code I provided is just a starting place, it will definitely need to be modified. Hopefully you can see where a set of x and y coordinates are mapped to a new, transformed set of coordinates. Following this process you could take that initial set and include any new point that you would like.
As for the obstacle mapping, I don't know exactly what information you're dealing with. Do you have a vector of coordiantes for the obstacle? If that's the case, then you can just do this:
xcoord = 10 * rand(100, 1) - 5;
ycoord = 10 * rand(100, 1) - 5;
plot(xcoord, ycoord, '.r', 'MarkerSize', 10)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!