2648|3

932

帖子

3

TA的资源

纯净的硅(中级)

楼主
 

基于STM32F401RE开发板的X-NUCLEO-IKS01A3传感器测试之三3D加速度LIS2DW12传感器测... [复制链接]

 

    今天测试了3D传感器的测试,使用的是LIS2DW12_6Dorientation范例,开始我还以为这个范例是测试加速度的,经过实际操作后才知道是测试传感器放置方向的,即平放(ZH)、卧放(ZL)、正立(YL)、倒立(YH)、左侧立(XL)、右侧立(XH),共6个方向。
     依旧是添加LCD驱动程序,添加包含路径等“常规”做法,然后在Send_Orientation()函数中添加LCD的显示代码,代码如下:

static void Send_Orientation(void)
{
  uint8_t xl = 0;
  uint8_t xh = 0;
  uint8_t yl = 0;
  uint8_t yh = 0;
  uint8_t zl = 0;
  uint8_t zh = 0;

  if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_XL(IKS01A3_LIS2DW12_0, &xl) != BSP_ERROR_NONE)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation XL axis from LIS2DW12 - accelerometer.\r\n");
    printf("%s", dataOut);
    LCD_clear_line(4);
    LCD_clear_line(5);
    LCD_write_BG(0,4,(uint8_t *)"XL 轴数据错误");
	  
    return;
  }
  if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_XH(IKS01A3_LIS2DW12_0, &xh) != BSP_ERROR_NONE)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation XH axis from LIS2DW12 - accelerometer.\r\n");
    printf("%s", dataOut);
      LCD_clear_line(4);
      LCD_clear_line(5);
	  LCD_write_BG(0,4,(uint8_t *)"XH 轴数据错误");
    return;
  }
  if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_YL(IKS01A3_LIS2DW12_0, &yl) != BSP_ERROR_NONE)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation YL axis from LIS2DW12 - accelerometer.\r\n");
    printf("%s", dataOut);
      LCD_clear_line(4);
      LCD_clear_line(5);
	  LCD_write_BG(0,4,(uint8_t *)"YL 轴数据错误");
    return;
  }
  if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_YH(IKS01A3_LIS2DW12_0, &yh) != BSP_ERROR_NONE)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation YH axis from LIS2DW12 - accelerometer.\r\n");
    printf("%s", dataOut);
      LCD_clear_line(4);
      LCD_clear_line(5);
      LCD_write_BG(0,4,(uint8_t *)"YH 轴数据错误");
    return;
  }
  if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_ZL(IKS01A3_LIS2DW12_0, &zl) != BSP_ERROR_NONE)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation ZL axis from LIS2DW12 - accelerometer.\r\n");
    printf("%s", dataOut);
      LCD_clear_line(4);
      LCD_clear_line(5);
      LCD_write_BG(0,4,(uint8_t *)"ZL 轴数据错误");
    return;
  }
  if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_ZH(IKS01A3_LIS2DW12_0, &zh) != BSP_ERROR_NONE)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation ZH axis from LIS2DW12 - accelerometer.\r\n");
    printf("%s", dataOut);
      LCD_clear_line(4);
      LCD_clear_line(5);
      LCD_write_BG(0,4,(uint8_t *)"ZH 轴数据错误");
    return;
  }

  if (xl == 1U && yl == 0U && zl == 0U && xh == 0U && yh == 0U && zh == 0U)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n  ________________  " \
                   "\r\n |                | " \
                   "\r\n |  *             | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |________________| \r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
	LCD_write_BG(0,4,(uint8_t *)"运动方向: XL");
  }

  else if (xl == 0U && yl == 1U && zl == 0U && xh == 0U && yh == 0U && zh == 0U)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n  ________________  " \
                   "\r\n |                | " \
                   "\r\n |             *  | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |________________| \r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
      LCD_write_BG(0,4,(uint8_t *)"运动方向: YL");
  }

  else if (xl == 0U && yl == 0U && zl == 0U && xh == 0U && yh == 1U && zh == 0U)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n  ________________  " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |  *             | " \
                   "\r\n |________________| \r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
	LCD_write_BG(0,4,(uint8_t *)"运动方向: YH");
  }

  else if (xl == 0U && yl == 0U && zl == 0U && xh == 1U && yh == 0U && zh == 0U)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n  ________________  " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |                | " \
                   "\r\n |             *  | " \
                   "\r\n |________________| \r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
	LCD_write_BG(0,4,(uint8_t *)"运动方向: XH");
  }

  else if (xl == 0U && yl == 0U && zl == 0U && xh == 0U && yh == 0U && zh == 1U)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n  __*_____________  " \
                   "\r\n |________________| \r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
	LCD_write_BG(0,4,(uint8_t *)"运动方向: ZH");
  }

  else if (xl == 0U && yl == 0U && zl == 1U && xh == 0U && yh == 0U && zh == 0U)
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n  ________________  " \
                   "\r\n |________________| " \
                   "\r\n    *               \r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
	LCD_write_BG(0,4,(uint8_t *)"运动方向: ZL");
  }

  else
  {
    (void)snprintf(dataOut, MAX_BUF_SIZE, "None of the 6D orientation axes is set in LIS2DW12 - accelerometer.\r\n");

      LCD_clear_line(4);
      LCD_clear_line(5);
      LCD_write_BG(0,4,(uint8_t *)"无运动");
  }
  printf("%s", dataOut);
}


    编译下载后的测试情况如下:

    1、测试时的照片:

    2、串口助手接收到的数据:

 

    3、平放(ZH)传感器:

    4、卧放(ZL)传感器:

    5、正立(YL)传感器:

    6、倒立(YH)传感器:

    7、左侧立(XL)传感器:

    8、右侧立(XH)传感器:

    注:LCD显示屏中显示的“运动方向”实际上应该为放置方向。


此内容由EEWORLD论坛网友hujj原创,如需转载或用于商业用途需征得作者同意并注明出处

最新回复

这样的确非常简单   详情 回复 发表于 2019-7-20 10:02
点赞 关注
 
 

回复
举报

1万

帖子

24

TA的资源

版主

沙发
 

是通过三个轴的参数来判断姿态吧。

点评

测试和判断都是直接用范例的代码(参见帖子中的代码),调用IKS01A3_MOTION_SENSOR_Get_6D_Orientation_XL()函数之后,直接判断xl,xh,yl,yh,zl,zh六个变量的值。  详情 回复 发表于 2019-7-20 09:34
 
 
 

回复

932

帖子

3

TA的资源

纯净的硅(中级)

板凳
 
dcexpert 发表于 2019-7-19 22:06 是通过三个轴的参数来判断姿态吧。

测试和判断都是直接用范例的代码(参见帖子中的代码),调用IKS01A3_MOTION_SENSOR_Get_6D_Orientation_XL()函数之后,直接判断xl,xh,yl,yh,zl,zh六个变量的值。

点评

这样的确非常简单  详情 回复 发表于 2019-7-20 10:02
 
 
 

回复

1万

帖子

24

TA的资源

版主

4
 
hujj 发表于 2019-7-20 09:34 测试和判断都是直接用范例的代码(参见帖子中的代码),调用IKS01A3_MOTION_SENSOR_Get_6D_Orientation_X ...

这样的确非常简单

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表