【LSM6DSOX有限状态机例程学习 五】--自由落体(Free-Fall)
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">大家可以想象下这个场景,你和你的朋友们去爬山,到了山顶发现风景不错,于是想给他们拍张照片。</span></span></p><p></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">你让大家站好位置,摆好姿势,透过手里黑卡</span><span lang="en-US" style="font-family:"Times New Roman"">7</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">代相机的取景器发现大家姿势摆的不好。于是你将黑卡放在身后的石头上,先要上前给大家摆姿势,就在这时</span><span lang="en-US" style="font-family:"Microsoft YaHei"">….</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Times New Roman""> </span></span></p>
<p></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">你身后的</span><span lang="zh-CN" style="font-weight:bold"><span style="font-family:"Microsoft YaHei"">黑卡相机</span></span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">没放好,从石头上滑下去了</span><span lang="en-US" style="font-family:"Times New Roman"">…</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Times New Roman""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">但是它的镜头还在外面伸着(卡片机伸缩镜头),掉地上戳到镜头必然坏掉,怎么办!?</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">嗯,没错。 跌落自由落体检测功能将能挽救镜头一命~经测试,Sony RX100(黑卡)确实有这么个功能设计。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">所以本帖讲解下官方例程中的自由落体检测(</span><span lang="en-US" style="font-family:"Times New Roman"">Free-Fall</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">)。</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">大家明白了这个应用场景了,那么结合实际的坠落情况来分析下如何进行检测。小学二年级的物理学中有讲到 在不考虑空气阻力情况下,物体自由落体运动时,自身所受到的加速度合小于g,当速度恒定是,加速度为0。那么基于这么个原理,我们就可以设置一个阈值,使连续一段时间内传感器的三个轴加速度都小于阈值区间,便可以感知自由落体,如下图红色区域内:</span></span></p>
<p></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">接下来我们来看下官方例程是如何实现的:</span></span></p>
<p></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span lang="en-US" style="font-family:"Times New Roman"">S0</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">:</span><span lang="en-US" style="font-family:"Microsoft YaHei""> CMD MSKIT</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">第一条指令之前有提到过,是在更细OUTS寄存器的时候屏蔽中断,目的为了S2指令静默更新寄存器。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">S1: CMD SELMB</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">这条命令为选择MaskB的值作为输入轴信息,也就是0x00,目的也是为了S2指令重置OUTS寄存器吧。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">S2: CMD OUTC</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">此时使用OUTC来讲MaskB的值传输到OUTS中,重置寄存器。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">S3: CMD SSIGN0</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">这条指令是配置无符号比较功能,也就是在对每个轴和阈值的比较时,不考虑符号。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">S4: CMD SELMA</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">这条指令选用MaskA的值作为输入轴信息,也就是X+ X- Y+ Y- Z+ Z- 都被选上了。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">S5: RNC GNTH1 TI3</span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">条件判断指令,</span><span lang="en-US" style="font-family:"Times New Roman"">GNTH1 </span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">输入轴数值大于阈值</span><span lang="en-US" style="font-family:"Microsoft YaHei"">1</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">时成立,也就是如果输入轴值小于阈值</span><span lang="en-US" style="font-family:"Microsoft YaHei"">1</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">且保持了</span><span lang="en-US" style="font-family:"Microsoft YaHei"">Timer3</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">的时间后,则跳转到</span><span lang="en-US" style="font-family:"Microsoft YaHei"">S6,</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">否则跳回</span><span lang="en-US" style="font-family:"Microsoft YaHei"">S0.</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">S6: CMD UMSKIT</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">这条指令用于接触MSKIT的屏蔽作用。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Times New Roman"">S7: CMD SELMC</span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">这时选择</span><span lang="en-US" style="font-family:"Times New Roman"">M</span><span lang="en-US" style="font-family:"Microsoft YaHei"">askC</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">的值作为输入信息,也就是</span><span lang="en-US" style="font-family:"Microsoft YaHei"">V+ </span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">,这里的</span><span lang="en-US" style="font-family:"Microsoft YaHei"">V</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">是三个轴的加速度矢量和,也就是模值。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Times New Roman"">S8: CMD OUTC</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">此时是有OUTC将MaskC的值写入OUTS寄存器中,并且产生外部中断。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Times New Roman"">S9: CMD GNTH1 NOP</span></span></p>
<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:"Microsoft YaHei"">条件判断指令,</span><span lang="en-US" style="font-family:"Times New Roman"">GNTH1 </span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">输入轴数值大于阈值</span><span lang="en-US" style="font-family:"Microsoft YaHei"">1</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">时成立,也就是当</span><span lang="en-US" style="font-family:"Microsoft YaHei"">V+ </span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">,这里的</span><span lang="en-US" style="font-family:"Microsoft YaHei"">V</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">是三个轴的加速度矢量和,也就是模值大于阈值</span><span lang="en-US" style="font-family:"Microsoft YaHei"">1</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">之后返回</span><span lang="en-US" style="font-family:"Microsoft YaHei"">S0</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">,由于前进判断条件为空,因此程序不会执行</span><span lang="en-US" style="font-family:"Microsoft YaHei"">S10</span><span lang="zh-CN" style="font-family:"Microsoft YaHei"">指令。</span></span></p>
<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:"Times New Roman"">S10: CMD STOP</span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">程序整体的运行流程图就如下:</span></span></p>
<p></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei""> </span></span></p>
<p><span style="font-size:14.0pt"><span style="font-family:"Microsoft YaHei"">分析了下例程代码之后,可以得出当传感器坠落并且保持了timer3的时长之后,传感器就会识别到坠落并产生中断,那么此时相机将镜头收回,就能够减少损失了~</span></span></p>
<p>赞</p>
<p>约你去爬山,文章有意思。</p>
页:
[1]