?? interpolation-api.sgml
字號:
<para>This 1D interpolator generates a motion from thecurrent state (position, velocity, acceleration) to a desiredvelocity, which must be reached with zero acceleration. The positionat that moment, as well as the duration of the motion, result from theinterpolation algorithm, and are not required as input parameters.</para><para>So, the interpolator's <emphasis role="strong">inputs</emphasis> are:desired end velocity; initial position; initial velocity; and initialacceleration. The <emphasis role="strong">properties</emphasis> are:maximum velocity, maximum acceleration, and maximum jerk. The initial acceleration should not exceed the maximum acceleration.</para><para>In fact, the mathematics of this interpolator is very similar tothe <link linkend="trapezoidal-velocity">trapezoidal velocity</link>interpolator to reach a given <emphasis>position</emphasis>: justreplace position by velocity, velocity by acceleration, andacceleration by jerk. The interpolation in this Section has one extracomplexity: the initial conditions of velocity and acceleration arenot zero, while the <parameter>SingleSCurve</parameter> of<xref linkend="trapezoidal-velocity"> works with all zero initialconditions.</para><para><anchor id="trap-acc-phases">The interpolated motion profile has<emphasis role="strong">three different phases</emphasis>,corresponding to “jerk pulses”(<xref linkend="fig-trap-acc-to-velocity">):<orderedlist numeration="lowerroman"><listitem><para>Maximum jerk pulse, i.e., linearly growing acceleration until maximumacceleration.</para></listitem><listitem><para>Zero jerk, i.e., constant acceleration at maximum acceleration, or,equivalently, linearly growing velocity.</para></listitem><listitem><para>Maximum jerk pulse, i.e., linearly decreasing acceleration, until zeroacceleration.</para></listitem></orderedlist>The magnitude of the jerk pulse determines the slope of theacceleration profile. The maximum acceleration determines the width ofthe jerk pulse, as well as the (maximum) slope of the velocityprofile.<xref linkend="fig-trap-acc-to-velocity"> shows a typical motionprofile generated in this way.</para><para><figure id="fig-trap-acc-to-velocity" float="1" pgwide="0"><title>Trapezoidal acceleration interpolation to reach a given velocity.(The position is plotted at one-tenth of the scale.)</title><mediaobject><imageobject><imagedata fileref="../pictures/trapacc_vel.png" format="PNG"></imageobject><imageobject><imagedata fileref="../pictures/trapacc_vel.eps" format="EPS"></imageobject></mediaobject></figure></para><para>So, the mathematics are a simple extension of<xref linkend="fig-acceleration-integrations">, as shown in<xref linkend="fig-jerk-integrations-vel">.</para><para><figure id="fig-jerk-integrations-vel" float="1" pgwide="0"><title>Formulas for the integration of jerk pulses, with a magnitudeof j<subscript>m</subscript> and a sign σ.</title><mediaobject><imageobject> <imagedata align="center" fileref="../pictures/jerk-integrations-vel.png" format="PNG"></imageobject><imageobject> <imagedata align="center" fileref="../pictures/jerk-integrations-vel.eps" format="EPS"></imageobject><textobject> <phrase><![CDATA[\begin{displaymath}\begin{aligned}j(t) = \phantom{\frac{1}{2}}&j_m\ \sigma \left\{ I_0(t-t_0) - I_0(t-t_1) - I_0(t-t_2) + I_0(t-t_3) \right\}\\\\a(t) = \phantom{\frac{1}{2}}&j_m\ \sigma \left\{ I_1(t-t_0) - I_1(t-t_1) - I_1(t-t_2) + I_1(t-t_3) \right\}\\ &+ a_0\\\\v(t) = \frac{1}{2} &j_m\ \sigma \left\{ I_2(t-t_0) - I_2(t-t_1) - I_2(t-t_2) + I_2(t-t_3) \right\}\\ &+ a_0 (t-t_0) + v_0\\\\p(t) = \frac{1}{6} &j_m\ \sigma \left\{ I_3(t-t_0) - I_3(t-t_1) - I_3(t-t_2) + I_3(t-t_3) \right\} \\ &+ \frac{1}{2} a_0 (t-t_0)^2 + v_0 (t-t_0) + p_0\\\\p_0 = p(t&=t_0), \quadv_0 = v(t=t_0), \quada_0 = a(t=t_0)\\\\I_y(x) &= \begin{cases} x^y, \quad x > 0 \\ 0, \quad x \le 0 \end{cases}\end{aligned}\end{displaymath}]]> </phrase></textobject></mediaobject></figure></para><para><xref linkend="fig-trap-acc-to-velocity"> is produced with thefollowing (<ulink url="http://www.octave.org">Octave</ulink>) code,which is a direct implementation of the code in<xref linkend="fig-jerk-integrations-vel">:<programlisting><![CDATA[%% input arguments:startpos = -10; startvel = -1; startacc = 0.8; endvel = 12;%% interpolator property values:maxvel = 3; maxacc = 2; maxjrk = 1; %% find out whether we must accelerate or decelerate:tmp1 = startacc/maxjrk;deltavel = endvel - startvel;direction = sign ( deltavel + sign(startacc) * startacc * tmp1 /2); %% magnitude of first jerk pulse:startjrk = direction * maxjrk;%% time of maximum deceleration phase:deltatime3 = maxacc / maxjrk;%% time of maximum acceleration phase:deltatime1 = deltatime3 - direction * tmp1;%% time of zero acceleration phase:deltatime2 = (direction * deltavel + tmp1 * startacc / 2) / maxacc - deltatime3; if (deltatime2 < 0) %% maximum acceleration not reached deltatime3 = sqrt( (direction * deltavel + tmp1 * startacc / 2)/maxjrk ); deltatime1 = deltatime3 - direction * tmp1; deltatime2 = 0;endif%% time instant when maximum acceleration is reached:time1 = deltatime1;%% time instant when maximum acceleration phase ends:time2 = time1 + deltatime2;%% time instant when acceleration reaches zero, and end velocity is %reached:time3 = time2 + deltatime3;t = [0:0.01:time3+1]; %% we calculate one time instant longer than motion[nr,nc] = size(t);jrk = zeros(nr,nc); acc = zeros(nr,nc); vel = zeros(nr,nc); pos = zeros(nr,nc); for i = 1:nc time = t(i); if (time < 0) error("time instant must be positive"); elseif (time < time1) jrk(i) = startjrk; acc(i) = startjrk * time + startacc; vel(i) = startjrk * time**2 / 2 + startacc * time + startvel; pos(i) = startjrk * time**3 / 6 + startacc * time**2/2 + startvel * time + startpos; elseif (time < time2) jrk(i) = 0; tt1 = time -time1; acc(i) = startjrk * (time - tt1) + startacc; vel(i) = startjrk * (time**2 - tt1**2)/ 2 + startacc * time + startvel; pos(i) = startjrk * (time**3 - tt1**3) / 6 + startacc * time**2/2 + startvel * time + startpos; elseif (time < time3) tt1 = time -time1; tt2 = time -time2; jrk(i) = -startjrk; acc(i) = startjrk * (time - tt1 - tt2) + startacc; vel(i) = startjrk * (time**2 - tt1**2 - tt2**2)/ 2 + startacc * time + startvel; pos(i) = startjrk * (time**3 - tt1**3 - tt2**3)/ 6 + startacc * time**2/2 + startvel * time + startpos; else tt1 = time -time1; tt2 = time -time2; tt3 = time -time3; jrk(i) = 0; acc(i) = 0; vel(i) = endvel; pos(i) = startjrk * (time**3 - tt1**3 - tt2**3 + tt3**3)/ 6 + startacc * time**2/2 + startvel * time + startpos; endifendfor]]></programlisting></para><para>For “short” motions, the interpolator might not reach theconstant acceleration phase, or, in other words, it doesn't reach themaximum velocity.</para></section><section id="trapezoidal-acceleration-to-position"><title> <parameter>TrapezoidalAccelerationToPosition</parameter>, <parameter>DoubleSCurve</parameter></title><para>This interpolator is an extension of the<link linkend="trapezoidal-acceleration-to-velocity">TrapezoidalAccelerationToVelocity</link>interpolator. It generates a motion from the current state (position,velocity, acceleration) to a desired <emphasis>position</emphasis>,which must be reached with zero velocity and acceleration. Theduration of the motion results from the maximum velocity, accelerationand jerk constraints in the interpolation algorithm, and is notrequired as input parameter.</para><para>So, the <emphasis role="strong">inputs</emphasis> are:desired end position; initial position; initial velocity; and initialacceleration. The <emphasis role="strong">properties</emphasis> are:maximum velocity, maximum acceleration, and maximum jerk. The initialacceleration should not exceed the maximum acceleration.</para><para>Roughly speaking, a<parameter>TrapezoidalAccelerationToPosition</parameter> motionconsists of two<parameter>TrapezoidalAccelerationToVelocity</parameter> motions gluedtogether by a constant velocity motion(<xref linkend="fig-trap-acc-to-position">):<itemizedlist><listitem><para>Moving from the current velocity to the specified maximum velocity.This is the first “trapezoid” in the motion.</para></listitem><listitem><para>The time-reversal of the motion from zero velocity to the specifiedmaximum velocity. This is the second “trapezoid” in themotion.</para></listitem></itemizedlist>However, both trapezoids still have to be “glued”together; and that is not always straightforward.</para><para><figure id="fig-trap-acc-to-position" float="1" pgwide="0"><title>Acceleration and jerk profiles.</title><mediaobject><imageobject><imagedata fileref="../pictures/trapacc_pos.png" format="PNG"></imageobject><imageobject><imagedata fileref="../pictures/trapacc_pos.eps" format="EPS"></imageobject></mediaobject></figure></para><para>The motion profile has the same three initial phases as<link linkend="trapezoidal-acceleration-to-velocity">TrapezoidalAccelerationToVelocity</link>,resulting in a motion towards maximum velocity, at time instant t3.Then the motion has the following four phases, determined by jerkpulses:<orderedlist numeration="lowerroman" continuation="continues"><listitem><para>Zero jerk, i.e., zero acceleration, and constant (maximum) velocity, between times t3 and t4.</para></listitem></orderedlist>Then, the last three phases are a time-reversed trapezoid of a<parameter>TrapezoidalAccelerationToVelocity</parameter> motion:<orderedlist numeration="lowerroman" continuation="continues"><listitem><para>Maximum jerk pulse, i.e., constantly changing acceleration, betweentimes t4 and t5.</para></listitem><listitem><para>Zero jerk, i.e., zero acceleration between times t5 and t6.</para></listitem><listitem><para>Maximum jerk pulse, i.e., constantly changing acceleration, betweentimes t6 and t7.</para></listitem></orderedlist>As said already, the last three phases are mirrors of the <link linkend="trap-acc-phases">first three phases</link>, except forthe fact that the t6-t7 phase moves until zero velocity andacceleration, while the t0-t1 phase starts from non-zero velocityand acceleration.</para><para>So, the resulting <emphasis>velocity</emphasis> profile looks like adouble, mirrored “S”, and the<emphasis>acceleration</emphasis> profile consists of two mirroredtrapezoids.</para><para>Mathematically speaking,the profile is the result of the integration of the jerk pulses,and the mathematics shown in<xref linkend="fig-jerk-integrations-pos"> are an extension of theformulas in <xref linkend="fig-acceleration-integrations"> and<xref linkend="fig-jerk-integrations-vel">.</para><para><figure id="fig-jerk-integrations-pos" float="1" pgwide="0"><title>Analytical expressions for the jerk, acceleration, velocity andposition curves.</title><mediaobject><imageobject><imagedata fileref="../pictures/jerk-integrations-pos.png" format="PNG"></imageobject><imageobject><imagedata fileref="../pictures/jerk-integrations-pos.eps" format="EPS"></imageobject></mediaobject></figure></para><para><figure id="fig-trapacc-pos-plot" float="1" pgwide="0"><title>Plots for the jerk, acceleration, velocity and position, for a nominalmotion.</title><mediaobject><imageobject><imagedata fileref="../pictures/trapacc_pos-plot.png" format="PNG"></imageobject><imageobject><imagedata fileref="../pictures/trapacc_pos-plot.eps" format="EPS"></imageobject></mediaobject></figure></para><para><xref linkend="fig-trapacc-pos-plot"> is produced with thefollowing (<ulink url="http://www.octave.org">Octave</ulink>) code:<programlisting><![CDATA[% initial position, velocity and acceleration:p0 = 30; v0 = -2; a0 = -1;% initial time:t0 = 0;% the profile has seven distinct phases, ending at time t7.% final position and velocity:p7 = 100;v7 = 0; % currently always zero!% (Absolute values of) maximum velocity, acceleration and jerk:vm = 7; am = 2; jm = 1;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -