极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2339|回复: 0

机器人制作开源方案 | Delta型腿机器狗实现原地动作

[复制链接]
发表于 2023-7-24 12:56:13 | 显示全部楼层 |阅读模式
本帖最后由 机器谱 于 2023-7-24 12:56 编辑

1. 功能说明
       本文示例将实现R322样机Delta型腿机器狗原地摆臂、原地圆形摆动、原地蹲起、原地踏步的功能。

原地摆臂
原地圆形摆动
原地蹲起
原地踏步

2. 电子硬件
本实验中采用了以下硬件:

主控板
Basra主控板(兼容Arduino Uno)‍
扩展板
Bigfish2.1扩展板‍
SH-SR舵机扩展板
传感器
近红外传感器
六轴陀螺仪
电池
7.4v锂电池、11.1V动力电池
其它
电压显示器

电路连接说明:Delta型腿机器狗的电路连接方式可参考上文【R322】Delta型腿机器狗-全动作展示【https://www.robotway.com/h-col-242.html】


3. 功能实现
       编程环境:Arduino 1.8.0
下面提供一个Delta型腿机器狗原地动作(原地摆臂、原地圆形摆动、原地蹲起、原地踏步)的参考例程,具体实验效果可参考演示视频。
① 原地摆臂例程(parallel_dog_liftLeg.ino):
  1. /*------------------------------------------------------------------------------------

  2.   版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.

  3.            Distributed under MIT license.See file LICENSE for detail or copy at

  4.            https://opensource.org/licenses/MIT

  5.            by 机器谱 2023-06-26 https://www.robotway.com/

  6.   ------------------------------*/

  7. /*****

  8.   Copyright 2017 Robot TIme

  9.   摆臂例程

  10. *****/


  11. #include "Tlc5940.h"

  12. #include "tlc_servos.h"

  13. #include <math.h>


  14. #include "types.h"

  15. #include "config.h"


  16. // 相关函数声明

  17. /***** 红外相关函数 *****/

  18. void IRInit(); //红外初始化

  19. void enableIR(); //红外使能

  20. void disableIR(); //关闭红外

  21. void updateIR(); //红外避障更新动作

  22. /***** 平衡相关函数 *****/

  23. void switchAdjustStat(uint stat); //切换平衡调节模式 不调节/原地调节/行进间调节

  24. void readGyroSerial(); //读取陀螺仪串口消息

  25. void adjustAct(); //平衡调节动作

  26. /****** 腿部动作相关函数 *****/

  27. void setTurnLeftFlag(bool flag); //修改左转状态标志位

  28. void setTurnRightFlag(bool flag); //修改右转状态标志位

  29. void leg1(); //更新1号腿(左前)位置

  30. void leg2(); //更新2号腿(左后)位置

  31. void leg3(); //更新3号腿(右前)位置

  32. void leg4(); //更新4号腿(右后)位置

  33. bool calc(Point3d p, bool leg1, bool leg2, bool leg3, bool leg4); //逆解计算函数

  34. /***** 整机动作相关函数 *****/

  35. void dogReset(Point3d initPos, uint waitTime); //复位动作

  36. void dogInit(); //初始化动作

  37. void upDown(float x, float y, float z1, float z2, uint times); //蹲起动作

  38. void drawCircle(float ox, float oy, float z, float r, uint times); //原地圆形摆动动作

  39. void stepping(float x, float y, float z1, float z2, uint times); // 原地踏步动作

  40. void liftShoulder(uint height, uint times); //原地摆臂动作


  41. //动作周期计数器

  42. int cycleCount;

  43. //复位计数器

  44. void resetCycleCount()

  45. {

  46.   cycleCount = -1;

  47. }

  48. void updateCycleCount()

  49. {

  50.   cycleCount++;

  51. }


  52. //当前运动状态

  53. dogMode currentMode;

  54. //切换运动状态

  55. void setMode(dogMode mode)

  56. {

  57.   if (mode == currentMode) return;

  58.   if (mode == DOG_MODE_TURN_LEFT)

  59.   {

  60.     setTurnLeftFlag(true);

  61.     setTurnRightFlag(false);

  62.   } else if (mode == DOG_MODE_TURN_RIGHT)

  63.   {

  64.     setTurnLeftFlag(false);

  65.     setTurnRightFlag(true);

  66.   } else {

  67.     setTurnLeftFlag(false);

  68.     setTurnRightFlag(false);

  69.   }


  70.   if (mode == DOG_MODE_BACK) //后退时关闭红外传感器

  71.   {

  72.     disableIR();

  73.   } else if (mode == DOG_MODE_STOP) //静止后开始原地姿态调节

  74.   {

  75.     switchAdjustStat(ADJUST_STAT_LEG);

  76.     dogReset({0, 0, Leg_Init_Z_Pos}, 200);

  77.   }

  78.   currentMode = mode;

  79. }


  80. void updateMode()

  81. {

  82.   if (cycleCount == MOTION_TIMES + 1) setMode(DOG_MODE_BACK);

  83.   if (cycleCount == 3 * MOTION_TIMES) setMode(DOG_MODE_LEFT);

  84.   if (cycleCount == 4 * MOTION_TIMES) setMode(DOG_MODE_RIGHT);

  85.   if (cycleCount == 5 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_FRONT);

  86.   if (cycleCount == 6 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_BACK);

  87.   if (cycleCount == 7 * MOTION_TIMES) setMode(DOG_MODE_LEFT_BACK);

  88.   if (cycleCount == 8 * MOTION_TIMES) setMode(DOG_MODE_LEFT_FRONT);

  89.   if (cycleCount == 9 * MOTION_TIMES) setMode(DOG_MODE_TURN_LEFT);

  90.   if (cycleCount == 10 * MOTION_TIMES) setMode(DOG_MODE_TURN_RIGHT);

  91.   if (cycleCount == 11 * MOTION_TIMES) setMode(DOG_MODE_STOP);

  92. }


  93. void setup()

  94. {

  95.   //陀螺仪连接串口,波特率115200

  96.   Serial.begin(115200);


  97.   //舵机驱动板初始化

  98.   Tlc.init(0);

  99.   tlc_initServos();   // Note: this will drop the PWM freqency down to 50Hz.


  100.   //红外传感器初始化

  101.   IRInit();


  102.   //大狗身体初始化

  103.   dogInit();


  104.   //原地摆臂动作10次后停止

  105.   liftShoulder(40, 10);

  106.   while(1);

  107. }


  108. void loop()

  109. {

  110. }
复制代码
② 原地圆形摆动例程(parallel_dog_drawCircle.ino):
  1. /*------------------------------------------------------------------------------------

  2.   版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.

  3.            Distributed under MIT license.See file LICENSE for detail or copy at

  4.            https://opensource.org/licenses/MIT

  5.            by 机器谱 2023-06-26 https://www.robotway.com/

  6.   ------------------------------*/

  7. /*****

  8.   Copyright 2017 Robot TIme

  9.   原地圆形摆动例程

  10. *****/


  11. #include "Tlc5940.h"

  12. #include "tlc_servos.h"

  13. #include <math.h>


  14. #include "types.h"

  15. #include "config.h"


  16. // 相关函数声明

  17. /***** 红外相关函数 *****/

  18. void IRInit(); //红外初始化

  19. void enableIR(); //红外使能

  20. void disableIR(); //关闭红外

  21. void updateIR(); //红外避障更新动作

  22. /***** 平衡相关函数 *****/

  23. void switchAdjustStat(uint stat); //切换平衡调节模式 不调节/原地调节/行进间调节

  24. void readGyroSerial(); //读取陀螺仪串口消息

  25. void adjustAct(); //平衡调节动作

  26. /****** 腿部动作相关函数 *****/

  27. void setTurnLeftFlag(bool flag); //修改左转状态标志位

  28. void setTurnRightFlag(bool flag); //修改右转状态标志位

  29. void leg1(); //更新1号腿(左前)位置

  30. void leg2(); //更新2号腿(左后)位置

  31. void leg3(); //更新3号腿(右前)位置

  32. void leg4(); //更新4号腿(右后)位置

  33. bool calc(Point3d p, bool leg1, bool leg2, bool leg3, bool leg4); //逆解计算函数

  34. /***** 整机动作相关函数 *****/

  35. void dogReset(Point3d initPos, uint waitTime); //复位动作

  36. void dogInit(); //初始化动作

  37. void upDown(float x, float y, float z1, float z2, uint times); //蹲起动作

  38. void drawCircle(float ox, float oy, float z, float r, uint times); //原地圆形摆动动作

  39. void stepping(float x, float y, float z1, float z2, uint times); // 原地踏步动作

  40. void liftShoulder(uint height, uint times); //原地摆臂动作


  41. //动作周期计数器

  42. int cycleCount;

  43. //复位计数器

  44. void resetCycleCount()

  45. {

  46.   cycleCount = -1;

  47. }

  48. void updateCycleCount()

  49. {

  50.   cycleCount++;

  51. }


  52. //当前运动状态

  53. dogMode currentMode;

  54. //切换运动状态

  55. void setMode(dogMode mode)

  56. {

  57.   if (mode == currentMode) return;

  58.   if (mode == DOG_MODE_TURN_LEFT)

  59.   {

  60.     setTurnLeftFlag(true);

  61.     setTurnRightFlag(false);

  62.   } else if (mode == DOG_MODE_TURN_RIGHT)

  63.   {

  64.     setTurnLeftFlag(false);

  65.     setTurnRightFlag(true);

  66.   } else {

  67.     setTurnLeftFlag(false);

  68.     setTurnRightFlag(false);

  69.   }


  70.   if (mode == DOG_MODE_BACK) //后退时关闭红外传感器

  71.   {

  72.     disableIR();

  73.   } else if (mode == DOG_MODE_STOP) //静止后开始原地姿态调节

  74.   {

  75.     switchAdjustStat(ADJUST_STAT_LEG);

  76.     dogReset({0, 0, Leg_Init_Z_Pos}, 200);

  77.   }

  78.   currentMode = mode;

  79. }


  80. void updateMode()

  81. {

  82.   if (cycleCount == MOTION_TIMES + 1) setMode(DOG_MODE_BACK);

  83.   if (cycleCount == 3 * MOTION_TIMES) setMode(DOG_MODE_LEFT);

  84.   if (cycleCount == 4 * MOTION_TIMES) setMode(DOG_MODE_RIGHT);

  85.   if (cycleCount == 5 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_FRONT);

  86.   if (cycleCount == 6 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_BACK);

  87.   if (cycleCount == 7 * MOTION_TIMES) setMode(DOG_MODE_LEFT_BACK);

  88.   if (cycleCount == 8 * MOTION_TIMES) setMode(DOG_MODE_LEFT_FRONT);

  89.   if (cycleCount == 9 * MOTION_TIMES) setMode(DOG_MODE_TURN_LEFT);

  90.   if (cycleCount == 10 * MOTION_TIMES) setMode(DOG_MODE_TURN_RIGHT);

  91.   if (cycleCount == 11 * MOTION_TIMES) setMode(DOG_MODE_STOP);

  92. }


  93. void setup()

  94. {

  95.   //陀螺仪连接串口,波特率115200

  96.   Serial.begin(115200);


  97.   //舵机驱动板初始化

  98.   Tlc.init(0);

  99.   tlc_initServos();   // Note: this will drop the PWM freqency down to 50Hz.


  100.   //红外传感器初始化

  101.   IRInit();


  102.   //大狗身体初始化

  103.   dogInit();


  104.   //原地做圆形摆动10周后停止

  105.   drawCircle(0, 0, -120, 60, 10);

  106.   while(1);

  107. }


  108. void loop()

  109. {

  110. }
复制代码

③ 原地蹲起例程(parallel_dog_updown.ino):
  1. /*------------------------------------------------------------------------------------

  2.   版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.

  3.            Distributed under MIT license.See file LICENSE for detail or copy at

  4.            https://opensource.org/licenses/MIT

  5.            by 机器谱 2023-06-26 https://www.robotway.com/

  6.   ------------------------------*/

  7. /*****

  8.   Copyright 2017 Robot TIme

  9.   原地蹲起例程

  10. *****/

  11. #include "Tlc5940.h"

  12. #include "tlc_servos.h"

  13. #include <math.h>

  14. #include "types.h"

  15. #include "config.h"

  16. // 相关函数声明

  17. /***** 红外相关函数 *****/

  18. void IRInit(); //红外初始化

  19. void enableIR(); //红外使能

  20. void disableIR(); //关闭红外

  21. void updateIR(); //红外避障更新动作

  22. /***** 平衡相关函数 *****/

  23. void switchAdjustStat(uint stat); //切换平衡调节模式 不调节/原地调节/行进间调节

  24. void readGyroSerial(); //读取陀螺仪串口消息

  25. void adjustAct(); //平衡调节动作

  26. /****** 腿部动作相关函数 *****/

  27. void setTurnLeftFlag(bool flag); //修改左转状态标志位

  28. void setTurnRightFlag(bool flag); //修改右转状态标志位

  29. void leg1(); //更新1号腿(左前)位置

  30. void leg2(); //更新2号腿(左后)位置

  31. void leg3(); //更新3号腿(右前)位置

  32. void leg4(); //更新4号腿(右后)位置

  33. bool calc(Point3d p, bool leg1, bool leg2, bool leg3, bool leg4); //逆解计算函数

  34. /***** 整机动作相关函数 *****/

  35. void dogReset(Point3d initPos, uint waitTime); //复位动作

  36. void dogInit(); //初始化动作

  37. void upDown(float x, float y, float z1, float z2, uint times); //蹲起动作

  38. void drawCircle(float ox, float oy, float z, float r, uint times); //原地圆形摆动动作

  39. void stepping(float x, float y, float z1, float z2, uint times); // 原地踏步动作

  40. void liftShoulder(uint height, uint times); //原地摆臂动作

  41. //动作周期计数器

  42. int cycleCount;

  43. //复位计数器

  44. void resetCycleCount()

  45. {

  46.   cycleCount = -1;

  47. }

  48. void updateCycleCount()

  49. {

  50.   cycleCount++;

  51. }

  52. //当前运动状态

  53. dogMode currentMode;

  54. //切换运动状态

  55. void setMode(dogMode mode)

  56. {

  57.   if (mode == currentMode) return;

  58.   if (mode == DOG_MODE_TURN_LEFT)

  59.   {

  60.     setTurnLeftFlag(true);

  61.     setTurnRightFlag(false);

  62.   } else if (mode == DOG_MODE_TURN_RIGHT)

  63.   {

  64.     setTurnLeftFlag(false);

  65.     setTurnRightFlag(true);

  66.   } else {

  67.     setTurnLeftFlag(false);

  68.     setTurnRightFlag(false);

  69.   }

  70.   if (mode == DOG_MODE_BACK) //后退时关闭红外传感器

  71.   {

  72.     disableIR();

  73.   } else if (mode == DOG_MODE_STOP) //静止后开始原地姿态调节

  74.   {

  75.     switchAdjustStat(ADJUST_STAT_LEG);

  76.     dogReset({0, 0, Leg_Init_Z_Pos}, 200);

  77.   }

  78.   currentMode = mode;

  79. }

  80. void updateMode()

  81. {

  82.   if (cycleCount == MOTION_TIMES + 1) setMode(DOG_MODE_BACK);

  83.   if (cycleCount == 3 * MOTION_TIMES) setMode(DOG_MODE_LEFT);

  84.   if (cycleCount == 4 * MOTION_TIMES) setMode(DOG_MODE_RIGHT);

  85.   if (cycleCount == 5 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_FRONT);

  86.   if (cycleCount == 6 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_BACK);

  87.   if (cycleCount == 7 * MOTION_TIMES) setMode(DOG_MODE_LEFT_BACK);

  88.   if (cycleCount == 8 * MOTION_TIMES) setMode(DOG_MODE_LEFT_FRONT);

  89.   if (cycleCount == 9 * MOTION_TIMES) setMode(DOG_MODE_TURN_LEFT);

  90.   if (cycleCount == 10 * MOTION_TIMES) setMode(DOG_MODE_TURN_RIGHT);

  91.   if (cycleCount == 11 * MOTION_TIMES) setMode(DOG_MODE_STOP);

  92. }

  93. void setup()

  94. {

  95.   //陀螺仪连接串口,波特率115200

  96.   Serial.begin(115200);

  97.   //舵机驱动板初始化

  98.   Tlc.init(0);

  99.   tlc_initServos();   // Note: this will drop the PWM freqency down to 50Hz.

  100.   //红外传感器初始化

  101.   IRInit();

  102.   //大狗身体初始化

  103.   dogInit();

  104.   //原地蹲起10次后停止

  105.   upDown(0, 0, -160, -90, 10);

  106.   while(1);

  107. }

  108. void loop()

  109. {

  110. }
复制代码

④ 原地踏步例程(parallel_dog_stepping.ino):
  1. /*------------------------------------------------------------------------------------

  2.   版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.

  3.            Distributed under MIT license.See file LICENSE for detail or copy at

  4.            https://opensource.org/licenses/MIT

  5.            by 机器谱 2023-06-26 https://www.robotway.com/

  6.   ------------------------------*/

  7. /*****

  8.   Copyright 2017 Robot TIme

  9.   原地蹲起例程

  10. *****/

  11. #include "Tlc5940.h"

  12. #include "tlc_servos.h"

  13. #include <math.h>

  14. #include "types.h"

  15. #include "config.h"

  16. // 相关函数声明

  17. /***** 红外相关函数 *****/

  18. void IRInit(); //红外初始化

  19. void enableIR(); //红外使能

  20. void disableIR(); //关闭红外

  21. void updateIR(); //红外避障更新动作

  22. /***** 平衡相关函数 *****/

  23. void switchAdjustStat(uint stat); //切换平衡调节模式 不调节/原地调节/行进间调节

  24. void readGyroSerial(); //读取陀螺仪串口消息

  25. void adjustAct(); //平衡调节动作

  26. /****** 腿部动作相关函数 *****/

  27. void setTurnLeftFlag(bool flag); //修改左转状态标志位

  28. void setTurnRightFlag(bool flag); //修改右转状态标志位

  29. void leg1(); //更新1号腿(左前)位置

  30. void leg2(); //更新2号腿(左后)位置

  31. void leg3(); //更新3号腿(右前)位置

  32. void leg4(); //更新4号腿(右后)位置

  33. bool calc(Point3d p, bool leg1, bool leg2, bool leg3, bool leg4); //逆解计算函数

  34. /***** 整机动作相关函数 *****/

  35. void dogReset(Point3d initPos, uint waitTime); //复位动作

  36. void dogInit(); //初始化动作

  37. void upDown(float x, float y, float z1, float z2, uint times); //蹲起动作

  38. void drawCircle(float ox, float oy, float z, float r, uint times); //原地圆形摆动动作

  39. void stepping(float x, float y, float z1, float z2, uint times); // 原地踏步动作

  40. void liftShoulder(uint height, uint times); //原地摆臂动作

  41. //动作周期计数器

  42. int cycleCount;

  43. //复位计数器

  44. void resetCycleCount()

  45. {

  46.   cycleCount = -1;

  47. }

  48. void updateCycleCount()

  49. {

  50.   cycleCount++;

  51. }

  52. //当前运动状态

  53. dogMode currentMode;

  54. //切换运动状态

  55. void setMode(dogMode mode)

  56. {

  57.   if (mode == currentMode) return;

  58.   if (mode == DOG_MODE_TURN_LEFT)

  59.   {

  60.     setTurnLeftFlag(true);

  61.     setTurnRightFlag(false);

  62.   } else if (mode == DOG_MODE_TURN_RIGHT)

  63.   {

  64.     setTurnLeftFlag(false);

  65.     setTurnRightFlag(true);

  66.   } else {

  67.     setTurnLeftFlag(false);

  68.     setTurnRightFlag(false);

  69.   }

  70.   if (mode == DOG_MODE_BACK) //后退时关闭红外传感器

  71.   {

  72.     disableIR();

  73.   } else if (mode == DOG_MODE_STOP) //静止后开始原地姿态调节

  74.   {

  75.     switchAdjustStat(ADJUST_STAT_LEG);

  76.     dogReset({0, 0, Leg_Init_Z_Pos}, 200);

  77.   }

  78.   currentMode = mode;

  79. }

  80. void updateMode()

  81. {

  82.   if (cycleCount == MOTION_TIMES + 1) setMode(DOG_MODE_BACK);

  83.   if (cycleCount == 3 * MOTION_TIMES) setMode(DOG_MODE_LEFT);

  84.   if (cycleCount == 4 * MOTION_TIMES) setMode(DOG_MODE_RIGHT);

  85.   if (cycleCount == 5 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_FRONT);

  86.   if (cycleCount == 6 * MOTION_TIMES) setMode(DOG_MODE_RIGHT_BACK);

  87.   if (cycleCount == 7 * MOTION_TIMES) setMode(DOG_MODE_LEFT_BACK);

  88.   if (cycleCount == 8 * MOTION_TIMES) setMode(DOG_MODE_LEFT_FRONT);

  89.   if (cycleCount == 9 * MOTION_TIMES) setMode(DOG_MODE_TURN_LEFT);

  90.   if (cycleCount == 10 * MOTION_TIMES) setMode(DOG_MODE_TURN_RIGHT);

  91.   if (cycleCount == 11 * MOTION_TIMES) setMode(DOG_MODE_STOP);

  92. }

  93. void setup()

  94. {

  95.   //陀螺仪连接串口,波特率115200

  96.   Serial.begin(115200);

  97.   //舵机驱动板初始化

  98.   Tlc.init(0);

  99.   tlc_initServos();   // Note: this will drop the PWM freqency down to 50Hz.

  100.   //红外传感器初始化

  101.   IRInit();

  102.   //大狗身体初始化

  103.   dogInit();

  104.   //原地蹲起10次后停止

  105.   upDown(0, 0, -160, -90, 10);

  106.   while(1);

  107. }

  108. void loop()

  109. {

  110. }
复制代码

4. 资料下载
资料内容:原地动作-程序源代码
资料下载地址:Delta型腿机器狗-原地动作【https://www.robotway.com/h-col-242.html】

回复

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-2 04:31 , Processed in 0.042654 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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