How angular velocity is determined in the example "Path Following with Obstacle Avoidance in Simulink"

10 views (last 30 days)
The example "Path Following with Obstacle Avoidance in Simulink" contains a matlab function block that calculates linear and angular velocity adjustments given a desired heading. Here is the example function:
function w = exampleHelperComputeAngularVelocity(steeringDir, wMax)
% W = exampleHelperComputeAngularVelocity(STEERINGDIR, WMAX)
% returns the angular velocity W for a differential drive robot in radians
% per second for a given steering direction STEERINGDIR in the robot's
% coordinate frame in radians and maximum angular velocity WMAX in
% radians per second. The output angular velocity is saturated based on
% the WMAX.
% Example:
% w = exampleHelperComputeAngularVelocity(0.2, 1);
% Copyright 2015 The MathWorks, Inc.
% Allow variable input arguments
if nargin == 1
wMax = inf;
validateattributes(steeringDir, {'double'},{'real'},...
'exampleHelperComputeAngularVelocity', 'STEERINGDIR', 1);
validateattributes(wMax, {'double'},{'real', 'positive'},...
'exampleHelperComputeAngularVelocity', 'WMAX', 2);
% Computing in robot's coordinate frame
curPose = [0 0 0];
% The following computation is similar to robotics.PurePursuit
lookaheadPoint = [cos(steeringDir), sin(steeringDir)];
slope = atan2((lookaheadPoint(2) - curPose(2)), ...
(lookaheadPoint(1) - curPose(1)));
alpha = angdiff(curPose(3), slope);
% Angular velocity command for a differential drive robot is
% equal to the desired curvature to be followed by the robot.
w = (2*sin(alpha));
% Pick a constant rotation when robot is facing in the opposite
% direction of the path
if abs(abs(alpha) - pi) < 1e-12
w = sign(w)*1;
if abs(w) > wMax
w = sign(w)*wMax;
My question is how does the line:
w = (2*sin(alpha));
Compute the required angular velocity of the robot to meet the desired heading?

Answers (1)

Yiping Liu
Yiping Liu on 17 Jan 2020
Edited: David on 17 Jan 2020
There are multiple similification here.
kai - desired curvature
L - wheelbase
d = desired steering angle
d = atan(kai*L)
atan(x) is a monotonic increasing function of x and is close to y=x function when x is in [-1,1],
so desired streering angle at the instant is simplied to just kai*L
You in general want the steering velocity to be proportional to the steering angle value (i.e. the larger steering angle is needed, the faster you want to turn the steering wheel), and L is just a constant scalar here, so eventually, w is simplified to just kai.
Such a series of simplification is probably not generally applicable, but in this example helper it gets the job done.
  1 Comment
Farid Sahebsara
Farid Sahebsara on 25 Jan 2022
Can you suggest me some references? I need to derive the expression or read something to see how the matlab code finally ends up with:
w = (2*sin(alpha));

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!