[英]Smoothly make a number approach zero
I have a floating point value X which is animated. 我有一个动画的浮点值X。 When in rest it's at zero, but at times an outside source may change it to somewhere between -1 and 1.
静止时为零,但有时外部源可能会将其更改为-1和1之间的某个值。
If that happens I want it to go smoothly back to 0. I currently do something like 如果发生这种情况,我希望它平稳返回到0。我目前正在执行类似的操作
addToXspeed(-x * FACTOR); // below is out of my control function addToXspeed(bla) { xspeed += bla; x += xspeed; }
every step in the animation, but that only causes X to oscillate. 动画的每个步骤,但这只会导致X振荡。 I want it to rest on 0 however.
但我希望它保持在0。
(I've explained the problem in abstracts. The specific thing I'm trying to do is make a jumping game character balance himself upright in the air by applying rotational force) (我已经抽象地解释了这个问题。我要做的特定事情是通过施加旋转力使跳跃的游戏角色在空中直立保持平衡)
Interesting problem. 有趣的问题。 What you are asking for is the stabilization of the following discrete-time linear system:
您需要的是以下离散时间线性系统的稳定性:
| x(t+1)| = | 1 dt | | x(t)| + | 0 | u(t)
|xspeed(t+1)| | 0 1 | |xspeed(t)| | 1 |
where dt
is the sampling time and u(t)
is the quantity you addToXspeed()
. 其中
dt
是采样时间, u(t)
是addToXspeed()
的数量。 (Further, the system is subject to random disturbances on the first variable x
, which I don't show in the equation above.) Now if you "set the control input equal to a linear feedback of the state", ie (此外,系统在第一个变量
x
上受到随机干扰,我在上式中没有显示。)现在,如果“将控制输入设置为等于状态的线性反馈”,即
u(t) = [a b] | x(t)| = a*x(t) + b*xspeed(t)
|xspeed(t)|
then the "closed-loop" system becomes 然后“闭环”系统变成
| x(t+1)| = | 1 dt | | x(t)|
|xspeed(t+1)| | a b+1 | |xspeed(t)|
Now, in order to obtain "asymptotic stability" of the system, we stipulate that the eigenvalues of the closed-loop matrix are placed "inside the complex unit circle", and we do this by tuning a
and b
. 现在,为了获得系统的“渐近稳定性”,我们规定将闭环矩阵的特征值置于“复数单位圆内”,并通过调整
a
和b
。 We place the eigenvalues, say, at 0.5. 我们将特征值设置为0.5。 Therefore the characteristic polynomial of the closed-loop matrix, which is
因此,闭环矩阵的特征多项式为
(s - 1)(s - (b+1)) - a*dt = s^2 -(2+b)*s + (b+1-a*dt)
should equal 应该相等
(s - 0.5)^2 = s^2 - s + 0.25
This is easily attained if we choose 如果我们选择,这很容易实现
b = -1 a = -0.25/dt
or 要么
u(t) = a*x(t) + b*xspeed(t) = -(0.25/dt)*x(t) - xspeed(t)
addToXspeed(u(t))
which is more or less what appears in your own answer 或多或少出现在您自己的答案中
targetxspeed = -x * FACTOR;
addToXspeed(targetxspeed - xspeed);
where, if we are asked to place the eigenvalues at 0.5, we should set FACTOR = (0.25/dt)
. 其中,如果要求我们将特征值设为0.5,则应将
FACTOR = (0.25/dt)
。
x = x*FACTOR x = x *因子
This should do the trick when factor is between 0 and 1. 当因子在0到1之间时,这应该可以解决问题。
The lower the factor the quicker you'll go to 0. 系数越低,您将更快地到达0。
Why don't you define a fixed step to be decremented from x
? 为什么不定义从
x
减的固定步长?
You just have to be sure to make it small enough so that the said person doesn't seem to be traveling at small bursts at a time, but not small enough that she doesn't move at a perceived rate. 您只需要确保使其足够小,以使该人似乎不会一次小小的旅行,但又不能小到不会以感知的速度移动。
Writing the question oftens results in realising the answer. 写问题通常会导致答案的实现。
targetxspeed = -x * FACTOR; addToXspeed(targetxspeed - xspeed); // below is out of my control function addToXspeed(bla) { xspeed += bla; x += xspeed; }
So simple too 太简单了
If you want to scale it but can only add, then you have to figure out which value to add in order to get the desired scaling: 如果要缩放它但只能添加,则必须弄清楚要添加哪个值才能获得所需的缩放比例:
Let's say x = 0.543
, and we want to cause it to rapidly go towards 0, ie by dropping it by 95%. 假设
x = 0.543
,我们想使它迅速接近0,即将其降低95%。
We want to do: 我们要做的是:
scaled_x = x * (1.0 - 0.95);
This would leave x at 0.543 * 0.05, or 0.02715
. 这将使x保持在0.543 * 0.05或
0.02715
。 The difference between this value and the original is then what you need to add to get this value: 然后,此值与原始值之间的差异就是您需要添加此值才能得到的值:
delta = scaled_x - x;
This would make delta equal -0,51585
, which is what you need to add to simulate a scaling by 5%. 这将使delta等于
-0,51585
,这是模拟5%缩放所需添加的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.