找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2888|回复: 6
打印 上一主题 下一主题
收起左侧

绝对值多圈编码器,其中齿轮以格雷码的方式编码,但是现在齿轮安装精度跟不上

[复制链接]
回帖奖励 400 黑币 回复本帖可获得 100 黑币奖励! 每人限 1 次
跳转到指定楼层
楼主
ID:319354 发表于 2019-7-22 10:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这种齿轮很常见,齿轮比4比1,齿轮通过光学漫反射检测位置信号,是现在市面上最常见的方案
参考资料: 资料.7z (236 Bytes, 下载次数: 30)
希望能得到有效的建议,现在问题是齿轮安装的时候没有对照机械零点(市场上应该都是这样,都是通过软件来弥补),导致其变化不是线性的,计算出来的圈数会跳变,本人的实现代码如下,或许描述的不是太准确,希望懂的大佬能够帮助我一下,已经研究几个月了各种方法都试过了,如果有算法更好,感激不尽

  1. /*******************************************************************************
  2.   * 文件名     : light_coding.c
  3.   * 作者       : ylh
  4.   * 库版本     : V3.5.0
  5.   * 文件版本   : V1.0.0
  6.   * 日期       : 2019年04月16日
  7.   * 摘要       : 齿轮
  8. ********************************************************************************/
  9. #include "light_coding.h"
  10. uint8_t light_cod[6] = {0};
  11. uint8_t result_turn[6] = {0};
  12. void LightCoding_GPIO_Init()
  13. {
  14. GPIO_InitTypeDef GPIO_InitStructure;
  15. // EXTI_InitTypeDef EXTI_InitStructure;
  16.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE); //使能端口和复用IO时钟
  17. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//
  18. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO,ENABLE);//
  19. GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
  20. GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_4;
  21. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
  22. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  23.   GPIO_Init(GPIOB, &GPIO_InitStructure);//
  24. GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_15;
  25. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
  26. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  27.   GPIO_Init(GPIOA, &GPIO_InitStructure);//
  28. GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_15;
  29. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
  30. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  31.   GPIO_Init(GPIOC, &GPIO_InitStructure);//
  32. GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_14;
  33. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
  34. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  35.   GPIO_Init(GPIOC, &GPIO_InitStructure);//
  36. GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_13;
  37. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
  38. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  39.   GPIO_Init(GPIOC, &GPIO_InitStructure);//
  40. GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_12;
  41. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
  42. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  43.   GPIO_Init(GPIOA, &GPIO_InitStructure);//
  44. }
  45. void NVIC_Configuration_LightCoding(void)
  46. {
  47. NVIC_InitTypeDef NVIC_InitStructure;

  48. NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
  49.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;  //从优先级为0
  50.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  51.   NVIC_Init(&NVIC_InitStructure);
  52. Light_Coding(0x01);
  53. }
  54. //读光编0x01~0x06;
  55. uint8_t Light_Coding(uint8_t type)
  56. {
  57. uint8_t result = 0;
  58. LED0(type&0x01);
  59. delay_ms(30);
  60. LED1((type&0x02)>>1);
  61. delay_ms(30);
  62. LED2((type&0x04)>>2);
  63. delay_ms(30);
  64. result = (result)|KEY3;
  65. delay_ms(30);
  66. result = (result<<1)|KEY4;
  67. delay_ms(30);
  68. result = (result<<1)|KEY5;
  69. delay_ms(30);
  70. return result;
  71. }
  72. //圈数转换
  73. void computation(void)
  74. {
  75. int i = 0;
  76. for(i=0;i<6;i++){
  77.   switch(light_cod[i])
  78.   {
  79. //   case 0x00:
  80. //    result_turn[i] = 0.5;
  81. //    break;
  82.    case 0x04:
  83.     result_turn[i] = 3;
  84.     break;
  85. //   case 0x06:
  86. //    result_turn[i] = 1.5;
  87. //    break;
  88.    case 0x07:
  89.     result_turn[i] = 0;
  90.     break;
  91. //   case 0x05:
  92. //    result_turn[i] = 2.5;
  93. //    break;
  94.    case 0x01:
  95.     result_turn[i] = 1;
  96.     break;
  97. //   case 0x03:
  98. //    result_turn[i] = 3.5;
  99. //    break;
  100.    case 0x02:
  101.     result_turn[i] = 2;
  102.     break;
  103.   }
  104.   delay_ms(10);
  105. }
  106. }
  107. //计算齿轮总圈数
  108. int32_t computation_NUMOFTURN(void)
  109. {
  110.   int count = 0;
  111.   int32_t NUM_TURN_WG = 0;
  112.   while(count<6){
  113.    light_cod[count] = Light_Coding(count+0x01);
  114.    count++;
  115.   }
  116.   computation();
  117.   NUM_TURN_WG =
  118.           result_turn[5]*1024+
  119.           result_turn[4]*256+
  120.           result_turn[3]*64+
  121.           result_turn[2]*16+
  122.           result_turn[1]*4+
  123.           result_turn[0];
  124.   Light_Coding(0x01);
  125.   return NUM_TURN_WG;
  126. }
  127. ```
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:588702 发表于 2019-7-23 15:01 | 只看该作者
顶起来
回复

使用道具 举报

板凳
ID:589001 发表于 2019-7-23 17:29 来自手机 | 只看该作者
很好,谢谢楼主
回复

使用道具 举报

地板
ID:282095 发表于 2019-7-24 09:16 | 只看该作者
rolan是简单的光学测量软件
回复

使用道具 举报

5#
ID:589469 发表于 2019-7-24 13:07 | 只看该作者
没有人来解答吗,想跟着学习一下
回复

使用道具 举报

6#
ID:542954 发表于 2019-8-8 10:34 | 只看该作者
码住学习
回复

使用道具 举报

7#
ID:598763 发表于 2019-8-10 13:51 | 只看该作者
谁来解答一下,我也想知道
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表