机械臂手势跟踪以及声控系统设计
本帖最后由 传媒学子 于 2020-7-5 01:33 编辑<p align="center" style="text-align:center"><span style="color:#8e44ad;"><span style="font-size:10.5pt"><span style="line-height:150%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:26.0pt"><span style="line-height:150%"><span style="font-family:黑体">2020</span></span></span><span style="font-size:26.0pt"><span style="line-height:150%"><span style="font-family:黑体">年ST MEMS传感器创意设计大赛</span></span></span></span></span></span></span></p>
<p align="center" style="text-align:center"> </p>
<p align="center" style="text-align:center"><strong><span style="font-size:24px;"><span style="color:#8e44ad;"><span style="font-family:宋体">机械臂手势跟踪以及声控系统设计</span></span></span></strong></p>
<p align="center" style="text-align:center"><span style="font-family:宋体;"><span style="font-size:15.0pt">by传媒学子</span></span></p>
<p><span style="font-size:16px;"><span style="color:#c0392b;"><span style="font-family:宋体;"><strong>0.前言</strong></span></span></span></p>
<p> <span style="font-size:16px;"><span style="font-family:宋体;"><span style="color:#000000;"> 这次ST mems大赛,让我学到了很多知识,对于六轴传感器的认识变得深入;领略到了LSM6DOX中FSM和MLC的魅力,也见识到了骨传导传感器LIS25BA的灵巧。从对于FSM的迷惑,到得到论坛版主@</span><a href="https://home.eeworld.com.cn/space-uid-303079.html" target="_blank"><span style="color:#000000;">littleshrimp</span></a><span style="color:#000000;">,</span><a href="https://home.eeworld.com.cn/space-uid-707230.html" target="_blank"><span style="color:#000000;">@justd0</span></a><span style="color:#000000;">等坛友的帮助,让我得以深入学习FSM状态机,让我真正掌握各个轴的对应情况,得以顺利完成FSM以及MLC的设计。论坛管理员@nmg,以及其他管理员对于我的鼓励,也让我有了前进的动力。非常感谢大家!</span></span></span></p>
<p style="text-align: center;"><iframe allowfullscreen="true" frameborder="0" height="510" src="https://training.eeworld.com.cn/shareOpenCourseAPI?isauto=true&lessonid=26402" style="background:#eee;margin-bottom:10px;" width="750"></iframe></p>
<p style="text-align: center;">下文的结项内容和附件中的 《传媒学子_ST_MEMS大赛项目总结.pdf》(带书签)内容一致,大家可以阅览帖子,亦可查看pdf,附件中存放本次大赛各种数据和源代码。</p>
<p> </p>
<p><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><strong><a name="_Toc44800681"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">一、项目背景</span></span></span></span></a></strong> </span></span></span></span></p>
<p align="left" style="text-align:left; text-indent:24.0pt"><span style="font-size:16px;"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">现代传感技术的进步,催生机器人等行业进入新的发展时期,加之以ST为代表的MEMS传感器的技术革新,机器人行业将会迎来新的发展。</span></span></span></span></span></span></span></p>
<p align="left" style="text-align:left; text-indent:24.0pt"><span style="font-size:16px;"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">本项目结合机器人舵机控制,采用ST高性能MEMS传感器LSM6DSOX和LIS25BA骨传导传感器,实现对四轴机械臂的手势和声音(震动)控制。从而,为近端机械控制提供参考。本项目结合5G通信可以实现远程机械移动的精确控制;在本地端,借助wifi/蓝牙转串口技术可实现化学实验室密闭有毒环境下远程试验。</span></span></span></span></span></span></span></p>
<p align="left" style="text-align:left; text-indent:24.0pt"> </p>
<p><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800682"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">二、作品简介</span></span></span></span></a></span></span></span></span></strong></p>
<p><span style="font-size:12.0pt"><span style="font-family:宋体"><span style="color:black"> 本项目采用LSM6DSOX高性能传感器和LIS25BA高精度骨传导传感器,实现对四轴机械臂的控制。通过LSM6DSOX结合FMS和MLC可实现对机械臂的物品抓取和放下。而通过LIS25BA可实现对震动的识别从而控制舵机完成相应动作。由于LIS25BA需要结合麦克风才能实现真正意义的声音控制,这里仅将声音控制缩小到敲击产生的震动,以此在不影响项目意图的同时,简化整个项目的实施难度。</span></span></span></p>
<p> </p>
<p><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800683"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">三、系统框图</span></span></span></span></a></span></span></span></span></strong></p>
<p><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800684"><span lang="EN-US" style="font-size:12.0pt">3.1 </span></a><span style="font-size:12.0pt">通过LSM6DSOX传感器实现手势对机械臂的控制</span></span></span></p>
<p><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">项目分为两个部分,第一部分为LSM6DSOX实现手势控制,第二部分为LIS25BA实现声音震动控制。</span></span></span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图3.1 LSM6DSOX实现手势控制系统原理图</span></span></span></span></span></span></span></span></p>
<p><span style="font-size:12.0pt"><span style="font-family:宋体"><span style="color:black">该部分主要利用FSM和MLC识别特定手势,来控制机械臂。数据采集利用MK190V3母版,而Unico软件实现FSM配置和MLC配置。FSM配置了3个状态机:FSM1/FMS2分别识别向右、向左手势,控制机械臂向左或者向右;MLC配合FSM3识别翻转手势,控制舵机完成既定动作(向下抓取物品或者丢掉物品)。母板配合uncio发送中断,中断传送给STM32F429,STM32F429通过I2C控制驱动pca8965实现对舵机的控制。</span></span></span></p>
<p><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800685"><span lang="EN-US" style="font-size:12.0pt">3.2 </span></a><span style="font-size:12.0pt">通过LIS25BA实现声控(震动控制)</span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图3.2 LIS25BA实现声音震动控制系统原理图</span></span></span></span></span></span></span></span></p>
<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"> <span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">该部分主要利用利用MK190V3控制LIS25BA高精度骨传导传感器实现数据采集,上位机通过python实现对传感器的寄存器配置以及数据采集、算法实施和运动控制。</span></span></span></span></span></span></span></span></p>
<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">Python</span></span></span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">通过调用pyserial将配置数据写入LIS25BA,然后,通过特定算法,识别桌面震动,从而通过串口告知stm32f429,驱动I2C舵机驱动,从而实现特定动作。</span></span></span></span></span></span></span></span></p>
<p align="left" style="text-align:left"> </p>
<p align="left" style="text-align:left"><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800686"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">四、各部分功能实现</span></span></span></span></a></span></span></span></span></strong></p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">本章节将详细介绍各模块的实现原理,按照系统原理图,本章节依然分为4.1和4.2两个大节来分别介绍手势控制和声音震动控制。</span></span></span></span></span></span></p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">舵机控制模块,两种控制方式采用的是相同的控制方式。均采用STM32F429接收PC串口数据或者母板中断1和中断2来驱动舵机驱动模块,控制舵机。舵机驱动采用I2C驱动器PCA8965,采用HAL库进行开发,具体代码见附件,由于这部分不是项目重点,这里就不着重叙述。下面重点介绍如何利用ST MEMS传感器实现手势识别和声音震动识别。</span></span></span></span></span></span></p>
<p align="left" style="text-align:left"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800687"><span lang="EN-US" style="font-size:12.0pt">4.1 </span></a><span style="font-size:12.0pt">手势控制系统 (LSM6DSOX)</span></span></span></p>
<p><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"> LSM6DSOX</span></span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">内部的FSM和MLC能够大大解放外部处理器的压力,借助FSM和MLC可以实现复杂运动的检测。本项目手势控制系统采用3个状态机和MLC实现对3种不同手势运动的识别。以下测试传感器ODR=208Hz,FSM ODR=104Hz,仅开启加速度传感器。且测试时,手握USB端(USB端朝内),晃动母板。</span></span></span></span></span></span></p>
<h3 style="text-align:justify; margin-top:17px; margin-bottom:17px"><span style="font-size:16pt"><span style="line-height:173%"><span style="font-family:"Times New Roman",serif"><span style="font-weight:bold"><a name="_Toc44800688"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:173%">4.1.1 FSM1</span></span></a><span style="font-size:12.0pt"><span style="line-height:173%"><span style="font-family:宋体">实现向左手势识别</span></span></span></span></span></span></span></h3>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">实现向左手势识别,则需要首先分析向左移动时传感器的数据变化,结合数据变化,对FSM进行配置,配置如图4.1.1.1所示,运动特征和中断输出如图4.1.1.2所示。当识别到向左手势,则发出中断1.</span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.1.1 向左划动状态机配置</span></span></span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.1.2 向左划动特征和对应中断输出</span></span></span></span></span></span></span></span></p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">向左运动特征:X+轴数据先到达一个负极,然后接着有一个正极值;配置X+轴数据输出,当X+小于-1.5,则进入S1,S1检测数据是否大于1.5,然后设置T3=16个采样点;如果T3计时器时间中,X+轴数据没有大于1.5,则复位。通过调节T3定时器的数值,来调节识别间隔。</span></span></span></span></span></span></p>
<h3 style="text-align:justify; margin-top:17px; margin-bottom:17px"><span style="font-size:16pt"><span style="line-height:173%"><span style="font-family:"Times New Roman",serif"><span style="font-weight:bold"><a name="_Toc44800689"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:173%">4.1.2 FSM2</span></span></a><span style="font-size:12.0pt"><span style="line-height:173%"><span style="font-family:宋体">实现向右手势识别</span></span></span></span></span></span></span></h3>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">向右手势和向左手势正好相反,因此,状态机比较类似,这里不再详述。当识别到向右手势,则发出中断2.</span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.2.1 向右划动状态机配置</span></span></span></span></span></span></span></span></p>
<p align="center" style="text-align:center; text-indent:21.0pt"> </p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.2.2 向右划动特征和对应中断输出</span></span></span></span></span></span></span></span></p>
<h3 style="text-align:justify; margin-top:17px; margin-bottom:17px"><span style="font-size:16pt"><span style="line-height:173%"><span style="font-family:"Times New Roman",serif"><span style="font-weight:bold"><a name="_Toc44800690"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:173%">4.1.3 FSM3</span></span></a><span style="font-size:12.0pt"><span style="line-height:173%"><span style="font-family:宋体">结合</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:173%">MLC</span></span><span style="font-size:12.0pt"><span style="line-height:173%"><span style="font-family:宋体">实现翻转手势识别</span></span></span></span></span></span></span></h3>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">FSM3</span></span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">检查MLC机器学习内核的数据;MLC配置为1个决策树,up->0, down->4. 机器学习内核,通过python生成对应的决策树,训练数据均由Unico软件获取。</span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.3.1 机器学习内核up输出</span></span></span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.3.2 机器学习内核down输出</span></span></span></span></span></span></span></span></p>
<p align="center" style="text-align:center; text-indent:24.0pt"> </p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">FSM3</span></span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">结合Z轴数据变动以及定时器等指令,实现左向右翻转手势识别。FSM3对应INT1和INT2均输出,STM32F429检测到两个信号同时输出时,驱动舵机完成翻转手势对应的动作。</span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.3.3 左向右翻转手势对应的FSM配置</span></span></span></span></span></span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.1.3.4 左向右翻转手势对应的特征和中断输出</span></span></span></span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"> <span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">手势控制系统的中断与手势对应关系如下:</span></span></span></span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">向左划动 </span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">- INT1</span></span></span></span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-size: 12pt;"><span style="line-height: 125%;"><span style="font-family: 宋体;">向右划动 - </span></span></span><span lang="EN-US" style="font-family: "Times New Roman", serif; font-size: 12pt;"><span style="line-height:125%"><span style="font-family:宋体">INT2</span></span></span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">翻转手势 - </span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">INT1</span></span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">、INT2同时输出</span></span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">后续,由STM32F429检测中断1和中断2的输出,驱动舵机,执行对应的手势动作。</span></span></span></span></span></span></p>
<p style="margin-bottom:3px; text-align:justify"> </p>
<h2 align="left" style="text-align:left; margin-top:32px; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><span style="font-weight:bold"><a name="_Toc44800691"><span lang="EN-US" style="font-size:12.0pt">4.2 </span></a><span style="font-size:12.0pt">声音震动识别 (LIS25BA)</span></span></span></span></h2>
<p><span style="font-size:12pt"><span style="font-family:宋体"> 骨传导传感器没有FSM和MLC,这两个功能是lsm6dox的功能。 因此,要实现对LIS25BA的数据采集,必须结合UM2116中叙述的相关指令进行配置和数据获取。</span></span></p>
<h3 style="text-align:justify; margin-top:17px; margin-bottom:17px"><span style="font-size:16pt"><span style="line-height:173%"><span style="font-family:"Times New Roman",serif"><span style="font-weight:bold"><a name="_Toc44800692"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:173%">4.2.1 </span></span></a><span style="font-size:12.0pt"><span style="line-height:173%"><span style="font-family:宋体">程序流程图</span></span></span></span></span></span></span></h3>
<p class="imagemiddle" style="text-align: center;"></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图4.2.1.1 整体上位机流程图</span></span></span></span></span></span></span></span></p>
<p style="text-align:justify; text-indent:21.0pt"><span style="font-size:12pt"><span style="text-justify:inter-ideograph"><span style="font-family:宋体">母板一个串口,用于配置LIS25BA传感器和获取传感器数据;另一个串口连接STM32F429,然后根据震动检测的算法的最终输出来控制舵机执行相应的动作;算法实施由python实施。</span></span></span></p>
<h3 style="text-align:justify; margin-top:17px; margin-bottom:17px"><span style="font-size:16pt"><span style="line-height:173%"><span style="font-family:"Times New Roman",serif"><span style="font-weight:bold"><a name="_Toc44800693"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:173%">4.2.2 </span></span></a><span style="font-size:12.0pt"><span style="line-height:173%"><span style="font-family:宋体">寄存器配置和算法实施</span></span></span></span></span></span></span></h3>
<p style="text-align:justify; text-indent:21.0pt"><span style="font-size:12pt"><span style="text-justify:inter-ideograph"><span style="font-family:宋体">LIS25BA传感器内部寄存器配置命令如下:</span></span></span></p>
<pre>
<code class="language-python">import serial
import time
import re
def print_hex(bytes):
l =
print(" ".join(l))
ser = serial.Serial('COM3',115200,timeout=1)
ser1 = serial.Serial('COM9',115200,timeout=1)
print(ser.name)
print(ser1.name)
ser.is_open
s=ser.write(b'*setdb211v1\r\n')
ser.write(b'*Zoff\r\n')
time.sleep(1)
#配置寄存器
ser.write(b'*w253F\r\n')
ser.write(b'*w2600\r\n')
ser.write(b'*w2E60\r\n')
ser.write(b'*w2FE0\r\n')
#ser.write(b'*single\r\n')
#enter debug mode to get acc sensor data
ser.write(b'*debug\r\n')
j=0
flag=0</code></pre>
<p class="imagemiddle" style="text-align: center;"> </p>
<p style="text-align:justify; text-indent:21.0pt"><span style="font-size:12pt"><span style="text-justify:inter-ideograph"><span style="font-family:宋体">每次读取1000个byte数据,进行分析,如果检测到大于2000的Z轴震动,则认为检测到震动。同时,由于震动附近波动数据较大,会让舵机反复执行不利于系统稳定,因此检测到一次震动后,退出当前1000个数据分析循环。主要算法代码如下:</span></span></span></p>
<pre>
<code class="language-python">while 1:
s=ser.read(1000)
s = s.decode('utf-8')
#print(re.search('\r\n', s, flags=0))
print(s)
a=s.split("\r\n");
print(a);
#去掉第一行,去掉最后一行,解析出Z轴数据
i=0
pre_value=0
for x in a:
i +=1;
if (i>1)and(i< (len(a)-1)):
#print(x)
x=x.split("AZ =",2)
#print(x)
#print(abs(int(x)))
num=abs(int(x))
print(num)
if i==2:
pre_value=num
if i>2:
if abs(num-pre_value) >2000:
print("有敲击声")
if flag:
s=ser1.write(b'\x15')
flag=0
break #跳出for循环,防止触法多次
#time.sleep(1)
if flag==0:
s=ser1.write(b'\x25')
flag=1
break
#time.sleep(1)
pre_value=num
ser.close</code></pre>
<p style="text-align:justify; text-indent:21.0pt"> </p>
<p style="text-align:justify; text-indent:21.0pt"><span style="font-size:12pt"><span style="text-justify:inter-ideograph"><span style="font-family:宋体">得到的原始数据:</span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:justify; text-indent:21.0pt"><span style="font-size:12pt"><span style="text-justify:inter-ideograph"><span style="font-family:宋体">处理后的数据(仅保留Z轴绝对值):</span></span></span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p style="text-align:justify; text-indent:21.0pt"><span style="font-size:12pt"><span style="text-justify:inter-ideograph"><span style="font-family:宋体">最终,通过串口2(对应代码中ser1)来输出舵机偏移值,实现对震动的检测。</span></span></span></p>
<h1 style="margin-top:8px; margin-bottom:8px; text-align:justify"><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800694"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">五、作品源码和案例中处理的传感器数据</span></span></span></span></a></span></span></span></span></strong></h1>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><b><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">作品源码详见本帖附件。</span></span></span></b></span></span></span></p>
<h2 align="left" style="margin-top:8px; text-align:left; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800695"><span lang="EN-US" style="font-size:12.0pt">5.1</span></a><span style="font-size:12.0pt">手势识别部分</span></span></span></h2>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">FSM</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">代码和传感器数据参照第四章节,下位机程序部分代码如下:</span></span></span></span></span></span></p>
<pre>
<code class="language-objectivec">/* USER CODE BEGIN WHILE */
//uint8_t value_temp=1;
value=30;
flag=0;//默认机械臂处于down state
pca9685_set_channel_pwm_times(&handle, 2, 0, 4096*0.5*32/200);
pca9685_set_channel_pwm_times(&handle, 0, 0, 4096*0.5*value/200);
while (1)
{
/* USER CODE END WHILE */
if((HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_3) == 1)&&(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == 1))
{ //右舵机-1-20H;左边舵机20H down, up-35H
//down
if(flag==1){
pca9685_set_channel_pwm_times(&handle, 2, 0, 4096*0.5*32/200);//32
pca9685_set_channel_pwm_times(&handle, 3, 0, 4096*0.5*40/200);
delay_1ms(300);
pca9685_set_channel_pwm_times(&handle, 3, 0, 4096*0.5*32/200);
flag=0;
delay_1ms(200);
}
}
else{
//up
if(flag==0){
flag=1;
pca9685_set_channel_pwm_times(&handle, 2, 0, 4096*0.5*50/200);
pca9685_set_channel_pwm_times(&handle, 3, 0, 4096*0.5*32/200);
//delay_1ms(200);
}
else{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_3) == 1)
{
pca9685_set_channel_pwm_times(&handle, 0, 0, 4096*0.5*value/200);
value-=1;
printf(" value:%d ",value);
delay_1ms(60);
}
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == 1)
{
pca9685_set_channel_pwm_times(&handle, 0, 0, 4096*0.5*value/200);
value+=1;
printf(" value:%d ",value);
delay_1ms(60);
}
if(value<8)
{
value=53;
}
if(value>53)
{
value=8;
}
}
}
}</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">MLC</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">原始训练数据和</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">python</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">生成决策树代码见结项贴附件,部分数据见下图:</span></span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%"> </span></span></span></span></span></p>
<p align="center" style="margin-bottom:8px; text-align:center"><span style="font-size:10.5pt"><span style="background:white"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体"><span style="color:black">图5.1.1 MLC机器内核训练原始数据</span></span></span></span></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"> </span></span></span></p>
<h2 align="left" style="margin-top:8px; text-align:left; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800696"><span lang="EN-US" style="font-size:12.0pt">5.2 </span></a><span style="font-size:12.0pt">声音震动识别部分</span> </span></span></h2>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">上位机中</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">python</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">代码参照</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">4.2.2. </span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">下位机中主要代码与手势识别章节复用,如下:</span></span></span></span></span></span></p>
<pre>
<code class="language-objectivec">/*
* claw, 十六进制 20H=32闭合,28H=40开启
底盘舵机,0x08(8)->0° 0x1e(30)->90° 0x35(53)->180°
右边舵机,20H为竖直状,35H为水平状态;
左边舵机, 当左边舵机为20H时,右边舵机必须大于等于20H,
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&"\r\ninto HAL_UART_RxCpltCallback\r\n",32,0xffff); //验证进入这个函数了
HAL_UART_Transmit(&huart1,(uint8_t *)&value,1,0xffff);////把接收到的数据通过串口发送出去
HAL_UART_Receive_IT(&huart1,(uint8_t *)&value,1);////重新打开串口中断
//value 0x08~0x350.5ms -- 0; 1.0ms---45°;---- 2.5ms--180° 0x08->0° 0x1e(30)->90° 0x35(53)->180°
assert(value >= 0x08);
assert(value <= 0x35);
printf("\r\n%d %d+serv0 \r\n",value, pca9685_set_channel_pwm_times(&handle, 0, 0, 4096*0.5*value/200));
}</code></pre>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">部分处理的传感器数据:</span></span></span></span></span></span></p>
<p style="text-align:justify"></p>
<h1 style="margin-top:16px; margin-bottom:8px; text-align:justify"><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800697"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">六、视频演示</span></span></span></span></a></span></span></span></span></strong></h1>
<h2 align="left" style="margin-top:8px; text-align:left; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800698"><span lang="EN-US" style="font-size:12.0pt">6.1 </span></a><span style="font-size:12.0pt">视频简介</span></span></span></h2>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman",serif"><b><span style="font-size:12.0pt"><span style="font-family:宋体">本项目分为2个部分演示: </span></span></b></span></span></p>
<p style="text-align:justify"> </p>
<ol>
<li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="font-family:宋体">手势识别部分</span></span></span></span></li>
</ol>
<p style="text-align:justify"></p>
<p style="text-align:justify"> </p>
<ol start="2">
<li style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="font-family:宋体">声音震动控制部分</span></span></span></span></li>
</ol>
<p style="text-align:justify"></p>
<p style="margin-bottom:3px; text-align:justify"> </p>
<h2 align="left" style="margin-top:8px; text-align:left; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800699"><span lang="EN-US" style="font-size:12.0pt">6.2 </span></a><span style="font-size:12.0pt">视频链接</span></span></span></h2>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman",serif"><a href="https://training.eeworld.com.cn/course/5708/learn#lesson/26402" style="color:blue; text-decoration:underline">https://training.eeworld.com.cn/course/5708/learn#lesson/26402</a></span></span></p>
<p style="margin-bottom:3px; text-align:justify"> </p>
<h1 style="margin-top:8px; margin-bottom:8px; text-align:justify"><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800700"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">七、项目总结与分享汇总</span></span></span></span></a></span></span></span></span></strong></h1>
<h2 align="left" style="margin-top:8px; text-align:left; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800701"><span lang="EN-US" style="font-size:12.0pt">7.1 </span></a><span style="font-size:12.0pt">项目总结</span></span></span></h2>
<p style="text-align:justify"> </p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">这次大赛是我第一次接触</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">ST MEMS</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">传感器,两块传感器</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">LSM6DSOX</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">和</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">LIS25BA</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">都是业界高性能传感器。尤其是</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">LSM6DSOX</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">内部自带</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">FSM</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">有限状态机,并且布置了</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">MLC</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">机器学习内核,提供了一套完整的训练和配置</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">flow, </span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">大大简化了开发的难度。</span></span></span></span></span></span></p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">本项目,通过对两款传感器的深入学习,结合</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">MK109V3</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">评估母板,基本实现了预定的项目规划:实现了对手势的控制和声音震动的控制。由于大赛时间限制,项目完成着重从评测角度和功能实现角度,基本达到了预期的目标。</span></span></span></span></span></span></p>
<p style="text-indent:24.0pt; text-align:justify"><span style="font-size:10.5pt"><span style="line-height:125%"><span style="font-family:"Times New Roman",serif"><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">本项目利用的三个</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">LSM6DSOX</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">有限状态机结合机器学习内核,实现了</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">3</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">种基本运动手势的识别,并且三种手势合在一起可完成一套组合的物品抓取演示过程。最后,利用</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">python</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">控制串口实现对</span></span></span><span lang="EN-US" style="font-size:12.0pt"><span style="line-height:125%">LIS25BA</span></span><span style="font-size:12.0pt"><span style="line-height:125%"><span style="font-family:宋体">的基本配置和数据获取,并实现声音震动识别算法实施,从而控制舵机运动。</span></span></span></span></span></span></p>
<p style="margin-bottom:3px; text-align:justify"> </p>
<h2 align="left" style="margin-top:8px; text-align:left; margin-bottom:8px"><span style="font-size:14pt"><span style="font-family:黑体"><a name="_Toc44800702"><span lang="EN-US" style="font-size:12.0pt">7.2 </span></a><span style="font-size:12.0pt">帖子汇总</span></span></span></h2>
<ul>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1117568-1-1.html" style="color:blue; text-decoration:underline" target="_blank"><span lang="EN-US" style="font-family:宋体">为何</span>unico<span lang="EN-US" style="font-family:宋体">提示不支持</span>STEVAL-MKI197V1?--- <span lang="EN-US" style="font-family:宋体">已解决</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1118506-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>1<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">拆箱与试用传感器</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1119737-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>2<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">项目介绍以及规划</span> </a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1121039-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>3<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">六轴传感器</span>LSM6DSOX<span lang="EN-US" style="font-family:宋体">学习和应用</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1121878-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>4<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">机械臂控制</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1123074-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>5<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">有限状态机学习(</span>FSM<span lang="EN-US" style="font-family:宋体">)</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1124088-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>6<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">机器学习内核学习(</span>1<span lang="EN-US" style="font-family:宋体">)(</span>MLC<span lang="EN-US" style="font-family:宋体">)</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1125153-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>7<span lang="EN-US" style="font-family:宋体">贴</span> -- <span lang="EN-US" style="font-family:宋体">机器学习内核学习(</span>2<span lang="EN-US" style="font-family:宋体">)(</span>MLC<span lang="EN-US" style="font-family:宋体">)</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1126425-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>8<span lang="EN-US" style="font-family:宋体">贴</span> --<span lang="EN-US" style="font-family:宋体">问题讨论</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1127606-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>9<span lang="EN-US" style="font-family:宋体">贴</span> -- unico<span lang="EN-US" style="font-family:宋体">使用相关问题探讨</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/thread-1128184-1-1.html" style="color:blue; text-decoration:underline" target="_blank">ST MEMS<span lang="EN-US" style="font-family:宋体">创意大赛第</span>10<span lang="EN-US" style="font-family:宋体">贴</span> -- MLC<span lang="EN-US" style="font-family:宋体">问题探讨与求助</span></a></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="color:blue"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><span class="MsoHyperlink" style="color:blue"><span style="text-decoration:underline"><a href="https://bbs.eeworld.com.cn/thread-1128863-1-1.html" style="color:blue; text-decoration:underline" target="_blank"><span style="font-size:12.0pt">ST MEMS</span><span lang="EN-US" style="font-size:12.0pt"><span style="font-family:宋体">创意大赛第</span></span><span style="font-size:12.0pt">11</span><span lang="EN-US" style="font-size:12.0pt"><span style="font-family:宋体">贴</span></span><span style="font-size:12.0pt"> -- </span><span lang="EN-US" style="font-size:12.0pt"><span style="font-family:宋体">机械臂手势跟踪系统基本完成</span></span></a></span></span></span></span></span></span></li>
<li style="text-align:left"><span style="font-size:10.5pt"><span style="tab-stops:list 36.0pt"><span style="font-family:"Times New Roman",serif"><strong><span lang="EN-US" style="font-size:12.0pt"><a href="https://bbs.eeworld.com.cn/forum.php?mod=viewthread&tid=1129540&fromuid=363532" style="color:blue; text-decoration:underline"><span style="font-weight:normal">ST MEMS</span><span lang="EN-US" style="font-family:宋体"><span style="font-weight:normal">创意大赛第</span></span><span style="font-weight:normal">12</span><span lang="EN-US" style="font-family:宋体"><span style="font-weight:normal">贴</span></span><span style="font-weight:normal"> -- </span><span lang="EN-US" style="font-family:宋体"><span style="font-weight:normal">骨传导</span></span><span style="font-weight:normal">LIS25BA</span><span lang="EN-US" style="font-family:宋体"><span style="font-weight:normal">实现机械臂控制</span></span></a></span></strong></span></span></span></li>
</ul>
<h1 style="margin-top:8px; margin-bottom:8px; text-align:justify"><strong><span style="font-size:22pt"><span style="line-height:150%"><span style="layout-grid-mode:char"><span style="font-family:"Times New Roman",serif"><a name="_Toc44800703"><span style="color:#c0392b;"><span style="font-size:14.0pt"><span style="line-height:150%"><span style="font-family:宋体">八、致谢</span></span></span></span></a></span></span></span></span></strong></h1>
<p style="margin-bottom:3px; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman",serif"> <span style="font-size:12.0pt"><span style="font-family:宋体">首先,感谢</span></span><span lang="EN-US" style="font-size:12.0pt">EEwold</span><span style="font-size:12.0pt"><span style="font-family:宋体">论坛和</span></span><span lang="EN-US" style="font-size:12.0pt">ST</span><span style="font-size:12.0pt"><span style="font-family:宋体">公司举办这次大赛,让我能接触到高性能的</span></span><span lang="EN-US" style="font-size:12.0pt">MEMS</span><span style="font-size:12.0pt"><span style="font-family:宋体">传感器。</span></span></span></span></p>
<p style="margin-bottom:3px; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman",serif"> <span style="font-size:12.0pt"><span style="font-family:宋体">其次,也感谢论坛版主</span></span><span lang="EN-US" style="font-size:12.0pt"><a href="https://home.eeworld.com.cn/space-uid-303079.html" style="color:blue; text-decoration:underline" target="_blank"><span style="text-decoration:none"><span style="text-underline:none">littleshrimp</span></span></a></span><span style="font-size:12.0pt"><span style="font-family:宋体">,</span></span><span lang="EN-US" style="font-size:12.0pt"><a href="https://home.eeworld.com.cn/space-uid-707230.html" style="color:blue; text-decoration:underline" target="_blank"><span style="text-decoration:none"><span style="text-underline:none">justd0</span></span></a></span><span style="font-size:12.0pt"><span style="font-family:宋体">等坛友的帮助,以及论坛管理员柠檬哥等的帮助和鼓励。通过这次大赛,串起了我用</span></span><span lang="EN-US" style="font-size:12.0pt">python</span><span style="font-size:12.0pt"><span style="font-family:宋体">控制串口、以及尝试通过</span></span><span lang="EN-US" style="font-size:12.0pt">C#</span><span style="font-size:12.0pt"><span style="font-family:宋体">获取</span></span><span lang="EN-US" style="font-size:12.0pt">windows</span><span style="font-size:12.0pt"><span style="font-family:宋体">窗口数据的知识碎片,让我自己的能力得到了提升。再次感谢</span></span><span lang="EN-US" style="font-size:12.0pt">EEworld</span><span style="font-size:12.0pt"><span style="font-family:宋体">论坛和</span></span><span lang="EN-US" style="font-size:12.0pt">ST</span><span style="font-size:12.0pt"><span style="font-family:宋体">公司。</span></span></span></span></p>
赞一个,楼主 宋元浩 发表于 2020-7-5 09:56
赞一个,楼主
谢谢.. <p>能做出来,不简单,牛人!</p>
本帖最后由 传媒学子 于 2020-7-27 00:31 编辑
<p>大赛评奖虽然已经结束,无意间看到还有人关注这个帖子,为此花了一些时间,将一些上述部分内容做了优化。近期,发现一些不太好的现象和不和谐的言论,这里还是希望大家能静下心来,享受技术进步带来的乐趣,不要被社会上部分浮躁的情绪所左右。</p>
<p> </p>
<p>回归本项目:</p>
<p>我将在main.c中处理中断1/2的程序换成了EXTI3/4 中断处理,似乎更加稳定。</p>
<p>然后,又用unico将FSM和MLC的.ucf文件合成了一个文件;我的理解.ucf中就是传感器的寄存器配置文件,按照我帖子中提到的方法,可以脱离unico,利用串口写入评测板中。</p>
<p>附件是合成后的.ucf 文件,上传上来,供有缘者参考。</p>
<p> </p>
<p>改为中断接收并处理来自评测板的中断源1和中断源2,共三种情形:</p>
<p>stm32f4xx_it.c 中断配置如下:</p>
<pre>
<code class="language-objectivec">extern int result;//main.c中定义
void EXTI3_IRQHandler(void)
{
/* USER CODE BEGIN EXTI3_IRQn 0 */
/* USER CODE END EXTI3_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
/* USER CODE BEGIN EXTI3_IRQn 1 */
result=1;
/* USER CODE END EXTI3_IRQn 1 */
}
/**
* <a href="home.php?mod=space&uid=159083" target="_blank">@brief</a> This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
/* USER CODE BEGIN EXTI4_IRQn 1 */
result=2;
/* USER CODE END EXTI4_IRQn 1 */
}</code></pre>
<p> </p>
<p> </p>
<p>main.c</p>
<p>while(1)代码如下:</p>
<pre>
<code class="language-objectivec">while(1)
{
//case1 Intr1 turn left
//case2 Intr2 turn right
//case3,Intr1 and Intr2, turn around
if(result==1) //case1
{
delay_1ms(1);
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == 1)
{
result = 3;
}
else {
value -= 1;
pca9685_set_channel_pwm_times(&handle, 0, 0, 4096*0.5*value/200);
result=0;
}
}
if(result==2)//case2
{
delay_1ms(1);
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_3) == 1){
result = 3;
}
else {
value += 1;
pca9685_set_channel_pwm_times(&handle, 0, 0, 4096*0.5*value/200);
result=0;
}
}
if(result==3)
{
//down
pca9685_set_channel_pwm_times(&handle, 2, 0, 4096*0.5*32/200);//down
pca9685_set_channel_pwm_times(&handle, 3, 0, 4096*0.5*40/200);//open claw
delay_1ms(300);
pca9685_set_channel_pwm_times(&handle, 3, 0, 4096*0.5*32/200);//close claw
delay_1ms(300);
pca9685_set_channel_pwm_times(&handle, 2, 0, 4096*0.5*50/200);//up
//pca9685_set_channel_pwm_times(&handle, 3, 0, 4096*0.5*32/200);
result=0;
}
if(value<8)
{
value=53;
}
if(value>53)
{
value=8;
}
}</code></pre>
<p> </p>
<p>main.c其它代码如下:</p>
<pre>
<code class="language-objectivec">
void delay_1ms(int x) //sys_180MHz
{
int j;
while(x--){
j=180000;
while(j--);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3 | GPIO_PIN_4, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
*/
/*Configure GPIO pins : PA3 PA4 */
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
}</code></pre>
<p> </p>
<p>可惜了没参与这块活动,现在看好像很有意思的样子。</p>
页:
[1]