Professional Documents
Culture Documents
14 April 2021
Task 1.b: Moving along a circle trajectory with constant orientation.
This task implements the trajectory of the youBot robot which has to follow a circle.
The robot should keep the constant orientation while moving along a circle. The radius
of the circle is passed to the control program through the variable-length argument
list in the run_simulation function (in this code radius = 1.234m) and the running
argument used is run_simulation(@solution1b, false, 1.234).
The control program is implemented as a two-state finite state machine (initial and
move) the latter is responsible for computation of the required linear and angular
velocities. At the initial state, the coordinate of the circle center is stored. And the
robot moves infinitely (no stopping condition)
CODE
function [forwBackVel, leftRightVel, rotVel, finish] = solution1b(pts,
contacts, position, orientation, varargin)
% The control loop callback function - the solution for task 1B
% declare the persistent variable that keeps the state of the Finite
% State Machine (FSM)
persistent state;
if isempty(state)
% the initial state of the FSM is 'init'
state = 'init';
end
theta = orientation(3);
leftRightVel = vel_L(1);
forwBackVel = vel_L(2);
rotVel = 0;
% Calculate norm
function norm = calculate_norm(pos)
% calculate the norm of distance
norm = sqrt(pos(1)^2 + pos(2)^2);
end
As it is seen from the above pictures the robot follows circular trajectory infinitely without
changing the orientation of the robot.