打印
[技术问题解答]

显示加速度和磁力传感器值实时曲线

[复制链接]
1121|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
小猫爱吃鱼|  楼主 | 2015-12-5 20:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
基于FRDM-K64F板子,我所做的工作有2个部分,如下:
1. Hello_FXOS8700Q 例程中,printf语句太多,main.cpp修改如下:
#include "mbed.h"
#include "FXOS8700Q.h"
//FXOS8700Q acc( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
//FXOS8700Q mag( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board

Serial pc(USBTX, USBRX);

MotionSensorDataUnits mag_data;
MotionSensorDataUnits acc_data;

MotionSensorDataCounts mag_raw;
MotionSensorDataCounts acc_raw;


int main() {
float faX, faY, faZ;
float fmX, fmY, fmZ;
int16_t raX, raY, raZ;
int16_t rmX, rmY, rmZ;
acc.enable();
//pc.printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
    while (true) {/*
        acc.getAxis(acc_data);
        mag.getAxis(mag_data);
        pc.printf("ACC: X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z);
        pc.printf("MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z);
        acc.getX(&faX);
        acc.getY(&faY);
        acc.getZ(&faZ);
        mag.getX(&fmX);
        mag.getY(&fmY);
        mag.getZ(&fmZ);
        pc.printf("ACC: X=%1.4f Y=%1.4f Z=%1.4f ", faX, faY, faZ);
        pc.printf("MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ);
        acc.getAxis(acc_raw);
        mag.getAxis(mag_raw);
        pc.printf("ACC: X=%d    Y=%d    Z=%d ", acc_raw.x, acc_raw.y, acc_raw.z);
        pc.printf("MAG: X=%d    Y=%d    Z=%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z);*/
        acc.getX(&raX);
        acc.getY(&raY);
        acc.getZ(&raZ);
        mag.getX(&rmX);
        mag.getY(&rmY);
        mag.getZ(&rmZ);               
pc.printf("FF ACC: X=%d   Y=%d    Z=%d MAG: X=%d  Y=%d  Z=%d EE", raX, raY, raZ,rmX, rmY, rmZ);
         
        wait(0.5);
    }
}
只保留了一句printf,用于从串口输出ACC和MAG,为了确保串口接收字符串的完整性,我用FF和EE来识别整串字符串。

相关帖子

沙发
小猫爱吃鱼|  楼主 | 2015-12-5 20:23 | 只看该作者
2.上位机用VB编写,MSCOMM串口控件。代码关键点介绍如下:
Private Sub DrawACCMAG(x As Single, y As Single, z As Single)
Dim wd As Integer
Dim maxv As Integer
maxv = 5000
If OptMag.Value Then
maxv = 3000
End If
wd = 30
'确保不会超过最大值,ACC设为-5000 5000,MAG设为-3000  3000
x = IIf(x > maxv, maxv, x) '[-maxv  maxv]
y = IIf(y > maxv, maxv, y)
z = IIf(z > maxv, maxv, z)
x = IIf(x < -maxv, -maxv, x)
y = IIf(y < -maxv, -maxv, y)
z = IIf(z < -maxv, -maxv, z)
xpos = xpos + wd
'新点位置尚未到达图框边缘,则顺序往后画线条
If xpos <= Pic2.ScaleWidth Then
    Pic2.PSet (xpos - wd, PreYpos_x), vbRed
    PreYpos_x = x + maxv
    Pic2.Line -(xpos, PreYpos_x), vbRed
    Pic2.PSet (xpos - wd, PreYpos_y), vbGreen
    PreYpos_y = y + Max
    Pic2.Line -(xpos, PreYpos_y), vbGreen
    Pic2.PSet (xpos - wd, PreYpos_z), vbBlue
    PreYpos_z = z + maxv
    Pic2.Line -(xpos, PreYpos_z), vbBlue
Else
'新点位值已到达图框边缘,则往前移动一帧,并将新点画到图框最后
Pic1.PaintPicture Pic2.Image, 0, 0, Pic1.ScaleWidth, Pic1.ScaleHeight, 0, 0, Pic1.ScaleWidth, Pic1.ScaleHeight '复制pic2
Pic2.PaintPicture Pic1.Image, 0, 0, Pic1.ScaleWidth - wd, Pic1.ScaleHeight, wd, 0, Pic1.ScaleWidth - wd, Pic1.ScaleHeight 'pic2左移30
Pic1.PaintPicture Pic3.Image, 0, 0, Pic1.ScaleWidth, Pic1.ScaleHeight, 0, 0, Pic1.ScaleWidth, Pic1.ScaleHeight ' pic1 去line
Pic1.PSet (0, PreYpos_x), vbRed
PreYpos_x = x + maxv
Pic1.Line -(wd, PreYpos_x), vbRed
Pic1.PSet (0, PreYpos_y), vbGreen
PreYpos_y = y + maxv
Pic1.Line -(wd, PreYpos_y), vbGreen
Pic1.PSet (0, PreYpos_z), vbBlue
PreYpos_z = z + maxv
Pic1.Line -(wd, PreYpos_z), vbBlue

Pic2.PaintPicture Pic1.Image, Pic2.ScaleWidth - wd, 0, wd, Pic2.ScaleHeight, 0, 0, wd, Pic1.ScaleHeight

End If
End Sub


使用特权

评论回复
板凳
小猫爱吃鱼|  楼主 | 2015-12-5 20:25 | 只看该作者
主要思路是采用PaintPicture 方法,对pic2进行剪切移动,实现实时曲线的效果(类似任务管理器中的实时曲线)
'====================================================================================
'                 文本接收

'====================================================================================
Private Sub textReceive()

Dim str As String
Dim ffpos, eepos As Integer
On Error GoTo Err
    InputSignal = MSComm1.Input
     

    Text1.Text = Text1.Text & InputSignal
     ffpos = InStr(1, Text1.Text, "FF")
     If ffpos <> 0 Then eepos = InStr(ffpos, Text1.Text, "EE")
     If ffpos > 0 And eepos > 0 Then
        MSComm1.RThreshold = 0
        str = Mid(Text1.Text, ffpos, eepos + 2)
         GetPointsFormstr str'用FF  EE截取完整字符串送给数值提取函数
         
         Text1.Text = ""
     End If
     
Err:
            
End Sub

使用特权

评论回复
地板
小猫爱吃鱼|  楼主 | 2015-12-5 20:28 | 只看该作者
果与应用截图:


之前我也一直对于FRDM-K64的串口使用迷惑,后来发现只要安装了最新的mbed驱动,插到opensda口插入USB后自己会虚拟一个串口,上位机配置成这个串口号即可收到printf语句发送的字符。和我之前对串口的理解很不一样,之前我都是用虚拟串口助手将2个串口对接,而这货居然可以自己发自己收。附上mbed最新驱动




使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

33

主题

294

帖子

2

粉丝