微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机(8bit)的16路舵机调速分析与实现

单片机(8bit)的16路舵机调速分析与实现

时间:11-18 来源:互联网 点击:

  1. gle[g_readyBufferIndex][ROBOT_RIGHT_SHOULDER_VERTICAL];
  2. g_diffAngle[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_SHOULDER_HORIZEN]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_SHOULDER_HORIZEN];
  3. g_diffAngle[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_ELBOW]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_ELBOW];
  4. g_diffAngle[PIN_GROUP_1][ROBOT_PIN_INDEX_LEFT_HIP_VERTICAL]=g_angle[g_readyBufferIndex][ROBOT_LEFT_HIP_VERTICAL];
  5. g_diffAngle[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_HIP_VERTICAL]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_HIP_VERTICAL];
  6. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_HIP_HORIZEN]=g_angle[g_readyBufferIndex][ROBOT_LEFT_HIP_HORIZEN];
  7. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_KNEE]=g_angle[g_readyBufferIndex][ROBOT_LEFT_KNEE];
  8. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_ANKLE]=g_angle[g_readyBufferIndex][ROBOT_LEFT_ANKLE];
  9. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_FOOT]=g_angle[g_readyBufferIndex][ROBOT_LEFT_FOOT];
  10. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_HIP_HORIZEN]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_HIP_HORIZEN];
  11. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_KNEE]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_KNEE];
  12. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_ANKLE]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_ANKLE];
  13. g_diffAngle[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_FOOT]=g_angle[g_readyBufferIndex][ROBOT_RIGHT_FOOT];
  14. //复位舵机管脚索引
  15. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_LEFT_SHOULDER_VERTICAL]=ROBOT_PIN_MASK_LEFT_SHOULDER_VERTICAL;
  16. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_LEFT_SHOULDER_HORIZEN]=ROBOT_PIN_MASK_LEFT_SHOULDER_HORIZEN;
  17. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_LEFT_ELBOW]=ROBOT_PIN_MASK_LEFT_ELBOW;
  18. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_SHOULDER_VERTICAL]=ROBOT_PIN_MASK_RIGHT_SHOULDER_VERTICAL;
  19. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_SHOULDER_HORIZEN]=ROBOT_PIN_MASK_RIGHT_SHOULDER_HORIZEN;
  20. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_ELBOW]=ROBOT_PIN_MASK_RIGHT_ELBOW;
  21. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_LEFT_HIP_VERTICAL]=ROBOT_PIN_MASK_LEFT_HIP_VERTICAL;
  22. g_diffAngleMask[PIN_GROUP_1][ROBOT_PIN_INDEX_RIGHT_HIP_VERTICAL]=ROBOT_PIN_MASK_RIGHT_HIP_VERTICAL;
  23. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_HIP_HORIZEN]=ROBOT_PIN_MASK_LEFT_HIP_HORIZEN;
  24. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_KNEE]=ROBOT_PIN_MASK_LEFT_KNEE;
  25. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_ANKLE]=ROBOT_PIN_MASK_LEFT_ANKLE;
  26. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_LEFT_FOOT]=ROBOT_PIN_MASK_LEFT_FOOT;
  27. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_HIP_HORIZEN]=ROBOT_PIN_MASK_RIGHT_HIP_HORIZEN;
  28. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_KNEE]=ROBOT_PIN_MASK_RIGHT_KNEE;
  29. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_ANKLE]=ROBOT_PIN_MASK_RIGHT_ANKLE;
  30. g_diffAngleMask[PIN_GROUP_2][ROBOT_PIN_INDEX_RIGHT_FOOT]=ROBOT_PIN_MASK_RIGHT_FOOT;
  31. }
  32. #definePWM_STEERING_ENGINE(group)\
  33. {\
  34. counter=STEERING_ENGINE_INIT_DELAY;\
  35. for(i=0;i<8;++i)\
  36. counter+=g_diffAngle[PIN_GROUP_##group][i];\
  37. \
  38. for(i=0;i<30;++i)\
  39. {\
  40. GROUP_##group##_CONTROL_PIN=0xFF;\
  41. Delay10us(STEERING_ENGINE_INIT_DELAY);\
  42. \
  43. for(j=0;j<8;++j)\
  44. {\
  45. Delay10us(g_diffAngle[PIN_GROUP_##group][j]);\
  46. GROUP_##group##_CONTROL_PIN&=~(g_diffAngleMask[PIN_GROUP_##group][j]);\
  47. }\
  48. \
  49. Delay10us(STEERING_ENGINE_CYCLE-counter);\
  50. }\
  51. }
  52. voidmain()
  53. {
  54. UCHAR8i;
  55. UCHAR8j;
  56. UINT16counter;
  57. InitSerialPort();
  58. P1=0xFF;
  59. //初始化舵机角度
  60. for(i=0;i
  61. {
  62. g_angle[0][i]=45;
  63. g_angle[1][i]=45;
  64. }
  65. for(i=0;i
  66. for(j=0;j<8;++j)
  67. g_diffAngle[i][j]=0;
  68. FillDiffAngle();
  69. InitPwmPollint();
  70. while(1)
  71. {
  72. #ifdefDEBUG_PROTOCOL
  73. if(g_fillingBufferIndex)
  74. {
  75. P11=0;
  76. P10=1;
  77. }
  78. else
  79. {
  80. P11=1;
  81. P10=0;
  82. }
  83. if(g_swapBuffer)
  84. P12=0;
  85. else
  86. P12=1;
  87. #endif
  88. if(g_swapBuffer)
  89. {
  90. FillDiffAngle();
  91. g_swapBuffer=FALSE;
  92. InitPwmPollint();
  93. }

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top