map of outline robot

2 次查看(过去 30 天)
Muhammad
Muhammad 2022-12-8
评论: Fifteen12 2022-12-9
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.

采纳的回答

Fifteen12
Fifteen12 2022-12-8
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 个评论
Muhammad
Muhammad 2022-12-8
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 2022-12-9
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)

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by