PLEASE WRITE THIS IN MATLAB!!
A ground robot is represented by a triangle in the figure
below.
We represent the location/orientation of the robot with a vector
x
where rx and ry are the coordinates of the robot position, and
theta is the angle between the reference x axis and the robot's x
axis (positive counterclockwise). The initial state of the robot
is
At each of the 150 time steps, the robot is moving 3 meters
forward (along its x axis) and its rotating 3 degrees
counterclockwise. We represent this movement with the vector
The movement of the robot from time step k to time step (k+1)
can be written in the state-space form as x(k+1) = x(k) + Bu
with
where theta-k is the angle between the reference x axis and the
robots x axis at the k-th time step.
Please find the code of file main.m and the two template files
tcomp.m and getObservation.m below
Part 1:
Complete the tcomp.m file by coding the state-space form
above.
Part 2:
The robot has a sensor pointing along its x axis that is able to
measure the range and bearing angle to 6 land-features when these
features are less than 100 meters away and when they are inside a
20 degree field of view. The locations of the features are shown in
red in the figure below and are the columns of the following
matrix:
Complete getObservation.m by computing the range and angle to
all features and determining if they are visible by the robot. You
must compute:
1. the 1x6 vector 'range' containing either zero when the i-th
feature is not visible or the range to it when it is visible
2. the 1x6 vector 'bearing' containing either zero when the i-th
feature is not visible or the bearing angle to it when it is
visible.
3. the 1x6 vector 'ifFeature' containing either zero when the
i-th feature is not visible or one when it is visible.
Again, a feature is not visible when it is either more than 100
meters away or more than 20 degrees from the robots x axis. Once
you have completed this problem you can run the main.m file for an
animation of the robot moving and sensing the features.
Some hints for part 2:
- calculate the 2D relative position of a feature with respect
to the robot
- the range is simply the magnitude of this 2D relative
position
- the bearing angle is the angle between this 2D relative
position and the robots x axis. when working with two vectors make
sure to express them both in the same coordinate system.
** complete files tcomp.m and
getObservation.m
The code for the tcomp.m and getObservation.m and main.m
is below.
tcomp.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
INPUTS:
x_k = 3x1 vector containing position and orientation of robot at
beginning of
step
u = 3x1 vector containing motion of robot
OUTPUTS:
x_kp1 = 3x1 vector containing position and orientation of robot at
end of step
DESCRIPTION:
This function calculate the motion of the robot
%}
function x_kp1=tcomp(x_k,u)
x_kp1 = x_k;
end
getObservation.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
INPUTS:
xRobot = 3x1 vector containing position and orientation of
robot
SensorSettings = structure containing two fields:
SensorSettings.Bearing = 20 deg, the field of view of the
sensor
SensorSettings.Range = 100 m, the range of the sensor
LandFeatures = 2x6 matrix containing the location of land features
the robot
can observe
OUTPUTS:
range = 1x6 vector containing either zero or the measured range to
each feature
(latter when in view)
bearing = 1x6 vector containing either zero or the measured bearing
angle to
each feature (latter when in view)
iFeature = 1x6 vector containing either zero or one (latter when in
view)
DESCRIPTION:
This function calculate the range and bearing angle to each feature
and
determines if they are in view of the sensor onboard the
robot
%}
function [range, bearing, iFeature] =
GetObservation(xRobot,SensorSettings,LandFeatures)
l =size(LandFeatures,2); % number of landmarks
range = zeros(1,l);
bearing = zeros(1,l);
iFeature = zeros(1,l); % return negative, no detection at all by
default
main.m
close all; clear all; clc
% Setting of the sensors specs
SensorSettings.Bearing = 20*pi/180; % Degrees => Rad
SensorSettings.Range =100; % Meters
% Size Map
WorldSize =400;
nLandFeatures = 6;
LandFeatures = zeros(2,nLandFeatures);
LandFeatures(:,1)=[60 -30]';
LandFeatures(:,2)=[50 50]';
LandFeatures(:,3)=[-10 70]';
LandFeatures(:,4)=[-80 30]';
LandFeatures(:,5)=[-70 0]';
LandFeatures(:,6) = [-50,-70];
xVehicle = [ 50 0 90*pi/180]';
nSteps = 150; % change to extend the length of the simulation
u =[3; 0 ; 3*pi/180];
%% Start time loop
for k = 2:nSteps
xVehicle = tcomp(xVehicle, u);
[range, bearing, iFeature] =
GetObservation(xVehicle,SensorSettings,LandFeatures);
figure(1); clf; hold on; grid off; axis equal;
meas = 0;
for ii=1:nLandFeatures
if iFeature(ii)
plot(LandFeatures(1,ii),LandFeatures(2,ii),'bo');
plot(LandFeatures(1,ii),LandFeatures(2,ii),'b+');
meas = ii;
else
plot(LandFeatures(1,ii),LandFeatures(2,ii),'r+');
end
end
if meas
text(50,175,['range = ',num2str(range(meas)), ' m'])
text(50,150,['angle = ',num2str(bearing(meas)*180/pi), '
deg'])
else
text(50,175, 'range = n/a')
text(50,150, 'angle = n/a')
end
set(gcf,'doublebuffer','on');
axis([ -WorldSize/2 WorldSize/2 -WorldSize/2 WorldSize/2]);
DoVehicleGraphics(xVehicle(1:3));
drawnow
end % Time loop ends
return
function DoVehicleGraphics(Xr)
p=0.02; % percentage of axes size
a=axis;
l1=(a(2)-a(1))*p;
l2=(a(4)-a(3))*p;
P=[-1 1 0 -1; -1 -1 3 -1]; % basic triangle
theta = Xr(3)-pi/2; % rotate to point along x axis (theta =
0)
c=cos(theta);
s=sin(theta);
P=[c -s; s c]*P; % rotate by theta
P(1,:)=P(1,:)*l1+Xr(1); % scale and shift to x
P(2,:)=P(2,:)*l2+Xr(2);
plot(P(1,:),P(2,:),'b','LineWidth',0.1);% draw
plot(Xr(1),Xr(2),sprintf('%s+','b'));
end
thank you for your help!!!!!
** Please complete the code for both of the files
(tcomp. and getObservation.m). There is only two parts to
this question, one of them is to complete tcomp.m file based on the
formulas given above. Part 2 is completing the getObservation.m
file where it computes the range and angle of all the features.
There is a list of what needs to happen above in the part 2
section. The main.m file is completed and can be run after the two
other files are completed. You can disreguard the main.m file if it
is confusing. There are also some hints for part 2 above.
robot x-axis reference y-axis robot y-axis robot position reference x-axis
(Үх — Х л Т. у -Ө
x(0) = = 50 m От 90 deg
U= 3m 0m [3 deg,
COS ( Ꮎ ) (Ok) -sin (@k) 07 B = sin (Ok) (Ok) 0 0 0 COS
60 1230 L = 50 -10 50 70 -80 30 -70 0 -500 m m
200 range = na 150 angle - na 100 50 + -50 -100 - 150 -200 -200 - 150 8 -100 1 -50 0 50 100 150 200
PLEASE WRITE THIS IN MATLAB!! A ground robot is represented by a triangle in the figure below. We represent the location
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
PLEASE WRITE THIS IN MATLAB!! A ground robot is represented by a triangle in the figure below. We represent the location
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!