justd0 发表于 2020-9-2 00:42

【LSM6DSOX有限状态机例程学习 五】--自由落体(Free-Fall)

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">大家可以想象下这个场景,你和你的朋友们去爬山,到了山顶发现风景不错,于是想给他们拍张照片。</span></span></p>

<p></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">你让大家站好位置,摆好姿势,透过手里黑卡</span><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">7</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">代相机的取景器发现大家姿势摆的不好。于是你将黑卡放在身后的石头上,先要上前给大家摆姿势,就在这时</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">&hellip;.</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Times New Roman&quot;">&nbsp;</span></span></p>

<p></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">你身后的</span><span lang="zh-CN" style="font-weight:bold"><span style="font-family:&quot;Microsoft YaHei&quot;">黑卡相机</span></span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">没放好,从石头上滑下去了</span><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">&hellip;</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Times New Roman&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">但是它的镜头还在外面伸着(卡片机伸缩镜头),掉地上戳到镜头必然坏掉,怎么办!?</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">嗯,没错。 跌落自由落体检测功能将能挽救镜头一命~经测试,Sony RX100(黑卡)确实有这么个功能设计。</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">所以本帖讲解下官方例程中的自由落体检测(</span><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">Free-Fall</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">)。</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">大家明白了这个应用场景了,那么结合实际的坠落情况来分析下如何进行检测。小学二年级的物理学中有讲到 在不考虑空气阻力情况下,物体自由落体运动时,自身所受到的加速度合小于g,当速度恒定是,加速度为0。那么基于这么个原理,我们就可以设置一个阈值,使连续一段时间内传感器的三个轴加速度都小于阈值区间,便可以感知自由落体,如下图红色区域内:</span></span></p>

<p></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">接下来我们来看下官方例程是如何实现的:</span></span></p>

<p></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">S0</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">:</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;"> CMD MSKIT</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">第一条指令之前有提到过,是在更细OUTS寄存器的时候屏蔽中断,目的为了S2指令静默更新寄存器。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">S1: CMD SELMB</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">这条命令为选择MaskB的值作为输入轴信息,也就是0x00,目的也是为了S2指令重置OUTS寄存器吧。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">S2: CMD OUTC</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">此时使用OUTC来讲MaskB的值传输到OUTS中,重置寄存器。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">S3: CMD SSIGN0</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">这条指令是配置无符号比较功能,也就是在对每个轴和阈值的比较时,不考虑符号。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">S4: CMD SELMA</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">这条指令选用MaskA的值作为输入轴信息,也就是X+ X- Y+ Y- Z+ Z- 都被选上了。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">S5: RNC GNTH1 TI3</span></span></p>

<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">条件判断指令,</span><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">GNTH1 </span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">输入轴数值大于阈值</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">1</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">时成立,也就是如果输入轴值小于阈值</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">1</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">且保持了</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">Timer3</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">的时间后,则跳转到</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">S6,</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">否则跳回</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">S0.</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">S6: CMD UMSKIT</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">这条指令用于接触MSKIT的屏蔽作用。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Times New Roman&quot;">S7: CMD SELMC</span></span></p>

<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">这时选择</span><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">M</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">askC</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">的值作为输入信息,也就是</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">V+ </span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">,这里的</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">V</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">是三个轴的加速度矢量和,也就是模值。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Times New Roman&quot;">S8: CMD OUTC</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">此时是有OUTC将MaskC的值写入OUTS寄存器中,并且产生外部中断。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Times New Roman&quot;">S9: CMD GNTH1 NOP</span></span></p>

<p><span style="font-size:14.0pt"><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">条件判断指令,</span><span lang="en-US" style="font-family:&quot;Times New Roman&quot;">GNTH1 </span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">输入轴数值大于阈值</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">1</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">时成立,也就是当</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">V+ </span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">,这里的</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">V</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">是三个轴的加速度矢量和,也就是模值大于阈值</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">1</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">之后返回</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">S0</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">,由于前进判断条件为空,因此程序不会执行</span><span lang="en-US" style="font-family:&quot;Microsoft YaHei&quot;">S10</span><span lang="zh-CN" style="font-family:&quot;Microsoft YaHei&quot;">指令。</span></span></p>

<p lang="en-US"><span style="font-size:14.0pt"><span style="font-family:&quot;Times New Roman&quot;">S10: CMD STOP</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">程序整体的运行流程图就如下:</span></span></p>

<p></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">&nbsp;</span></span></p>

<p><span style="font-size:14.0pt"><span style="font-family:&quot;Microsoft YaHei&quot;">分析了下例程代码之后,可以得出当传感器坠落并且保持了timer3的时长之后,传感器就会识别到坠落并产生中断,那么此时相机将镜头收回,就能够减少损失了~</span></span></p>

传媒学子 发表于 2020-9-7 14:06

<p>赞</p>

freebsder 发表于 2020-9-7 19:42

<p>约你去爬山,文章有意思。</p>
页: [1]
查看完整版本: 【LSM6DSOX有限状态机例程学习 五】--自由落体(Free-Fall)