机器人中的轨迹规划(Trajectory Planning )
?
?Figure. Several possible path shapes for a single joint
五次多項式曲線(quintic polynomial)
?
$$\theta(t)=a_0+a_1t+a_2t^2+a_3t^3+a_4t^4+a_5t^5$$
? 考慮邊界條件:
$$\begin{align*}?
\theta_0&=a_0\\
\theta_f&=a_0+a_1t+a_2{t_f}^2+a_3{t_f}^3+a_4{t_f}^4+a_5{t_f}^5\\
\dot{\theta_0}&=a_1\\
\dot{\theta_f}&=a_1+2a_2t_f+3a_3{t_f}^2+4a_4{t_f}^3+5a_5{t_f}^4\\
\ddot{\theta_0}&=2a_2\\
\ddot{\theta_f}&=2a_2+6a_3{t_f}+12a_4{t_f}^2+20a_5{t_f}^3\\
\end{align*}$$
? 這6組約束構成了一個6個未知數的線性方程組,可以求出系數為:
$$\begin{align*}?
a_0&=\theta_0\\
a_1&=\dot{\theta_0}\\
a_2&=\frac{\ddot{\theta_0}}{2}\\
a_3&=\frac{20\theta_f-20\theta_0-(8\dot{\theta_f}+12\dot{\theta_0})t_f-(3\ddot{\theta_0}-\ddot{\theta_f}){t_f}^2}{2{t_f}^3}\\
a_4&=\frac{30\theta_0-30\theta_f+(14\dot{\theta_f}+16\dot{\theta_0})t_f+(3\ddot{\theta_0}-2\ddot{\theta_f}){t_f}^2}{2{t_f}^4}\\
a_5&=\frac{12\theta_f-12\theta_0-(6\dot{\theta_f}+6\dot{\theta_0})t_f-(\ddot{\theta_0}-\ddot{\theta_f}){t_f}^2}{2{t_f}^5}
\end{align*}$$
?
? 在MATLAB機器人工具箱中函數tpoly可以用于計算并生成機器人單軸的五次多項式軌跡曲線。當$t \in [0,T]$時,五次多項式曲線以及其一階導數、二階導數都是連續光滑的多項式曲線:
$$\begin{align*}?
S(t)&=At^5+Bt^4+Ct^3+Dt^2+Et+F\\
\dot{S}(t)&=5At^4+4Bt^3+3Ct^2+2Dt+E\\
\ddot{S}(t)&=20At^3+12Bt^2+6Ct+2D
\end{align*}$$
根據約束條件
可以寫出矩陣方程如下:
利用MATLAB提供的左除(反除)操作符,可以方便的求解線性方程組:Ax=b → x=A\b(表示矩陣A的逆乘以b)
?tpoly.m主要內容如下:
%TPOLY Generate scalar polynomial trajectory% [S,SD,SDD] = TPOLY(S0, SF, T, SD0, SDF) as above but specifies initial % and final joint velocity for the trajectory and time vector T.function [s,sd,sdd] = tpoly(q0, qf, t, qd0, qdf)if isscalar(t)t = (0:t-1)';elset = t(:);endif nargin < 4qd0 = 0;endif nargin < 5qdf = 0;endtf = max(t);% solve for the polynomial coefficients using least squaresX = [0 0 0 0 0 1tf^5 tf^4 tf^3 tf^2 tf 10 0 0 0 1 05*tf^4 4*tf^3 3*tf^2 2*tf 1 00 0 0 2 0 020*tf^3 12*tf^2 6*tf 2 0 0];coeffs = (X \ [q0 qf qd0 qdf 0 0]')';% coefficients of derivatives coeffs_d = coeffs(1:5) .* (5:-1:1);coeffs_dd = coeffs_d(1:4) .* (4:-1:1);% evaluate the polynomialsp = polyval(coeffs, t);pd = polyval(coeffs_d, t);pdd = polyval(coeffs_dd, t);在MATLAB中輸入下面命令生成從位置0運動到1的五次多項式曲線(時間步數為50步):
>> [s, sd, sdd] = tpoly(0, 1, 50);其位置、速度、加速度曲線如下圖所示:
雖然這三條曲線都是連續且光滑的,但卻存在一個很實際的問題。從速圖曲線中可以看出在t=25時速度達到最大值,沒有勻速段,其它時刻速度都小于最大值。平均速度除以最大速度的值為:mean(sd) / max(sd) =?0.5231,即平均速度只有最大速度的一半左右,速度利用率較低。對于大多數實際伺服系統,電機的最大速度一般是固定的,因此希望速度曲線在最大速度的時間盡可能長。
梯形速度曲線 / Linear segment with parabolic?blend (LSPB) trajectory?
? 高次多項式軌跡曲線的計算量比較大,我們也可以考慮用直線段來構造簡單的軌跡曲線,但是在不同直線段的交接處會發生速度跳變的情況(位移曲線不光滑),如果用拋物線(parabolic blend)進行拼接就可以得到光滑的軌跡。如下圖所示,單軸從$t_0$開始勻加速運動(位移曲線為拋物線);$t_b$時刻達到最大速度,進行勻速直線運動(位移曲線為直線段);從$t_f-t_b$時刻開始進行勻減速運動,$t_f$時刻減速為零并到達目標位置。曲線關于時間中點$t_h$對稱,由于這種軌跡的速度曲線是梯形的,因此也稱為梯形速度(trapezoidal velocity trajectory)曲線,在電機驅動器中被廣泛使用。
Figure. Linear segment with parabolic blends
MATLAB機器人工具箱中函數lspb可以用于計算并生成梯形速度曲線,下面的命令生成從位置0運動到1的梯形速度軌跡曲線,時間步數為50步,最大速度為默認值:
>> [s, sd, sdd] = lspb(0, 1, 50);另外也可以指定最大速度(In fact the velocity cannot be chosen arbitrarily, too high or toolow a value for the maximum velocity will result in an infeasible trajectory?):
>> s = lspb(0, 1, 50, 0.025); >> s = lspb(0, 1, 50, 0.035);下圖a是默認最大速度的曲線,圖b是指定不同速度的對比。
?? lspb.m的主要內容如下:
%LSPB Linear segment with parabolic blend % % [S,SD,SDD] = LSPB(S0, SF, M) is a scalar trajectory (Mx1) that varies % smoothly from S0 to SF in M steps using a constant velocity segment and % parabolic blends (a trapezoidal velocity profile). Velocity and % acceleration can be optionally returned as SD (Mx1) and SDD (Mx1) % respectively. % % [S,SD,SDD] = LSPB(S0, SF, M, V) as above but specifies the velocity of % the linear segment which is normally computed automatically.function [s,sd,sdd] = lspb(q0, q1, t, V)if isscalar(t)t = (0:t-1)';elset = t(:);endtf = max(t(:));if nargin < 4 % if velocity not specified, compute itV = (q1-q0)/tf * 1.5;elseV = abs(V) * sign(q1-q0); % 判斷實際速度符號if abs(V) < abs(q1-q0)/tferror('V too small');elseif abs(V) > 2*abs(q1-q0)/tferror('V too big');endendif q0 == q1 % 目標位置和起始位置相同 s = ones(size(t)) * q0;sd = zeros(size(t));sdd = zeros(size(t));returnendtb = (q0 - q1 + V*tf)/V; % 計算勻加減速段時間a = V/tb;s = zeros(length(t), 1);sd = s;sdd = s;for i = 1:length(t)tt = t(i);if tt <= tb % 勻加速段 % initial blends(i) = q0 + a/2*tt^2;sd(i) = a*tt;sdd(i) = a;elseif tt <= (tf-tb) % 勻速段% linear motions(i) = (q1+q0-V*tf)/2 + V*tt;sd(i) = V;sdd(i) = 0else % 勻減速段% final blends(i) = q1 - a/2*tf^2 + a*tf*tt - a/2*tt^2;sd(i) = a*tf - a*tt;sdd(i) = -a;endend?
?多自由度軌跡規劃?
? 機器人工具箱中的函數mtraj可以在內部調用單自由度軌跡生成函數,來生成多個軸的運動軌跡。mtraj第一個參數為單自由度軌跡生成函數的句柄,q0和qf分別為起始和目標點的坐標(是一個多維向量)。
function [S,Sd,Sdd] = mtraj(tfunc, q0, qf, M)if ~isa(tfunc, 'function_handle')error('first argument must be a function handle');endM0 = M;if ~isscalar(M)M = length(M);endif numcols(q0) ~= numcols(qf)error('must be same number of columns in q0 and qf')ends = zeros(M, numcols(q0));sd = zeros(M, numcols(q0));sdd = zeros(M, numcols(q0));for i=1:numcols(q0)% for each axis[s(:,i),sd(:,i),sdd(:,i)] = tfunc(q0(i), qf(i), M);endmtraj可以調用tpoly或lspb,在50步內生成從(0, 2)運動到(1, -1)的軌跡。返回值x是一個50×2的矩陣,每一列代表一個軸的數據,每一行代表一個時間點。
>> x = mtraj(@tpoly, [0 2], [1 -1], 50); >> x = mtraj(@lspb, [0 2], [1 -1], 50);>> plot(x)
在指定的時間內x1從0運動到1,x2從2運動到-1:
?
?
?
參考:
V-rep學習筆記:Reflexxes Motion Library 4
多軸插補為什么普遍使用梯形速度曲線?
工業機器人運動軌跡規劃方法簡述
Introduction to Robotics - Mechanics and Control. Chapter 7 Trajectory generation
Robotics, vision and control fundamental algorithms in MATLAB?Chapter 3 Time and Motion
轉載于:https://www.cnblogs.com/21207-iHome/p/7843517.html
總結
以上是生活随笔為你收集整理的机器人中的轨迹规划(Trajectory Planning )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的第一个爬虫
- 下一篇: webpack4配置vue环境和一些小坑