86浏览
查看: 86|回复: 0

[项目] 【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台

[复制链接]
本帖最后由 驴友花雕 于 2025-5-21 17:35 编辑

Arduino是一个开放源码的电子原型平台,它可以让你用简单的硬件和软件来创建各种互动的项目。Arduino的核心是一个微控制器板,它可以通过一系列的引脚来连接各种传感器、执行器、显示器等外部设备。Arduino的编程是基于C/C++语言的,你可以使用Arduino IDE(集成开发环境)来编写、编译和上传代码到Arduino板上。Arduino还有一个丰富的库和社区,你可以利用它们来扩展Arduino的功能和学习Arduino的知识。

Arduino的特点是:
1、开放源码:Arduino的硬件和软件都是开放源码的,你可以自由地修改、复制和分享它们。
2、易用:Arduino的硬件和软件都是为初学者和非专业人士设计的,你可以轻松地上手和使用它们。
3、便宜:Arduino的硬件和软件都是非常经济的,你可以用很低的成本来实现你的想法。
4、多样:Arduino有多种型号和版本,你可以根据你的需要和喜好来选择合适的Arduino板。
5、创新:Arduino可以让你用电子的方式来表达你的创意和想象,你可以用Arduino来制作各种有趣和有用的项目,如机器人、智能家居、艺术装置等。


【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图1

在本教程中,我们将学习如何构建 Arduino Gimbal 或使用伺服电机的自稳定平台。本教程实际上是上一个关于 MPU6050 教程的教程的扩展。

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图2

目录

1、概述
DIY Arduino Gimbal - 自稳平台 STL 文件
2、装配
3、Arduino Gimbal 电路图
Arduino 代码
4、DIY Arduino Gimbal - 自稳定平台 Code


一、概述
我使用 3D 建模软件设计了万向节。它由 3 个用于 3 轴控制的 MG996R 伺服电机和一个放置MPU6050传感器、Arduino 和电池的底座组成。

Arduino Gimbal 3D 模型

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图3


您可以在 Thangs 上找到并下载此 3D 模型,并在浏览器中进行探索。

DIY Arduino Gimbal - 自稳平台 STL 文件(见项目下载)



使用我的 Creality CR-10 3D 打印机,我 3D 打印了所有部件,它们都非常完美。

DIY Gimbal 3D 打印部件

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图4


二、装配
组装万向节非常简单。我从安装 Yaw 伺服开始。我使用 M3 螺栓和螺母将其固定到底座上。
Arduino 云台伺服电机安装

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图5

接下来,使用相同的方法固定 Roll 伺服器。这些部件经过专门设计,可轻松安装 MG996R 伺服系统。

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图6

为了将零件相互连接,我使用了圆角,它是伺服器的附件。

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图8


首先,我们需要用两个螺栓将圆角固定到底座上,然后用另一个螺栓将其连接到前一个伺服器上。

组装 Arduino 云台

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图7

我重复了这个过程来组装其余的组件,即 Pitch 伺服器和顶部平台。

Arduino 自稳定平台

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图10

接下来,我将伺服线穿过支架开口,以保持它们井井有条。然后我插入 MPU6050 传感器并用螺栓和螺母将其固定在底座上。

带有 MPU6050 传感器的 Arduino 自稳定平台

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图9

为了给项目供电,我使用了 2 节锂离子电池,并将其放在这个电池座中。我使用两个螺栓和螺母将电池座固定到底座上。

锂离子电池座

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图11

2 节锂离子电池将产生大约 7.4V 的电压,但我们需要 5V 来为 Arduino 和伺服系统供电。

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图13

这就是为什么我使用了一个降压转换器,它可以将 7.4V 转换为 5V。



三、Arduino Gimbal 电路图

现在剩下的就是把所有东西都连接在一起。这是这个项目的电路图以及需要如何连接所有内容。

DIY Arduino Gimbal - 自稳定平台

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图12

您可以自行获取此 Arduino 教程所需的组件:

MPU6050 IMU .....................................亚马逊 / Banggood / 全球速卖通
MG996R 伺服.....................................亚马逊 / Banggood / 全球速卖通
Buck Converter .................................... 降压转换器亚马逊 / Banggood / 全球速卖通
Arduino 板 .....................................亚马逊 / Banggood / 全球速卖通
试验板和跳线 ............亚马逊 / Banggood / 全球速卖通


最后,我将电子元件和电线挤入底座中,并使用底部的这个盖子覆盖它们。

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图14

这样,自平衡平台或 Arduino 万向节就完成了,并且按预期运行良好。剩下的就是看看这个程序。

DIY Arduino 云台自稳平台 带 MPU6050 传感器

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图15

四、Arduino 代码
此示例的 Arduino 代码是对 Jeff Rowberg 的 i2cdevlib 库中的 MPU6050_DMP6 示例的修改。

开源代码:
  1. /*
  2.   DIY Gimbal - MPU6050 Arduino Tutorial
  3.   by Dejan, www.HowToMechatronics.com
  4.   Code based on the MPU6050_DMP6 example from the i2cdevlib library by Jeff Rowberg:
  5.   https://github.com/jrowberg/i2cdevlib
  6. */
  7. // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
  8. // for both classes must be in the include path of your project
  9. #include "I2Cdev.h"
  10. #include "MPU6050_6Axis_MotionApps20.h"
  11. //#include "MPU6050.h" // not necessary if using MotionApps include file
  12. // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
  13. // is used in I2Cdev.h
  14. #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
  15. #include "Wire.h"
  16. #endif
  17. #include <Servo.h>
  18. // class default I2C address is 0x68
  19. // specific I2C addresses may be passed as a parameter here
  20. // AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
  21. // AD0 high = 0x69
  22. MPU6050 mpu;
  23. //MPU6050 mpu(0x69); // <-- use for AD0 high
  24. // Define the 3 servo motors
  25. Servo servo0;
  26. Servo servo1;
  27. Servo servo2;
  28. float correct;
  29. int j = 0;
  30. #define OUTPUT_READABLE_YAWPITCHROLL
  31. #define INTERRUPT_PIN 2  // use pin 2 on Arduino Uno & most boards
  32. bool blinkState = false;
  33. // MPU control/status vars
  34. bool dmpReady = false;  // set true if DMP init was successful
  35. uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
  36. uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
  37. uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
  38. uint16_t fifoCount;     // count of all bytes currently in FIFO
  39. uint8_t fifoBuffer[64]; // FIFO storage buffer
  40. // orientation/motion vars
  41. Quaternion q;           // [w, x, y, z]         quaternion container
  42. VectorInt16 aa;         // [x, y, z]            accel sensor measurements
  43. VectorInt16 aaReal;     // [x, y, z]            gravity-free accel sensor measurements
  44. VectorInt16 aaWorld;    // [x, y, z]            world-frame accel sensor measurements
  45. VectorFloat gravity;    // [x, y, z]            gravity vector
  46. float euler[3];         // [psi, theta, phi]    Euler angle container
  47. float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
  48. // packet structure for InvenSense teapot demo
  49. uint8_t teapotPacket[14] = { '
  50. [b]代码解读[/b]
  51. 1、获得值后,首先将它们从弧度转换为度数。
  52. [code]// Get Yaw, Pitch and Roll values
  53. #ifdef OUTPUT_READABLE_YAWPITCHROLL
  54.     mpu.dmpGetQuaternion(&q, fifoBuffer);
  55.     mpu.dmpGetGravity(&gravity, &q);
  56.     mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
  57.     // Yaw, Pitch, Roll values - Radians to degrees
  58.     ypr[0] = ypr[0] * 180 / M_PI;
  59.     ypr[1] = ypr[1] * 180 / M_PI;
  60.     ypr[2] = ypr[2] * 180 / M_PI;
  61.    
  62.     // Skip 300 readings (self-calibration process)
  63.     if (j <= 300) {
  64.       correct = ypr[0]; // Yaw starts at random value, so we capture last value after 300 readings
  65.       j++;
  66.     }
  67.     // After 300 readings
  68.     else {
  69.       ypr[0] = ypr[0] - correct; // Set the Yaw to 0 deg - subtract  the last random Yaw value from the currrent value to make the Yaw 0 degrees
  70.       // Map the values of the MPU6050 sensor from -90 to 90 to values suatable for the servo control from 0 to 180
  71.       int servo0Value = map(ypr[0], -90, 90, 0, 180);
  72.       int servo1Value = map(ypr[1], -90, 90, 0, 180);
  73.       int servo2Value = map(ypr[2], -90, 90, 180, 0);
  74.       
  75.       // Control the servos according to the MPU6050 orientation
  76.       servo0.write(servo0Value);
  77.       servo1.write(servo1Value);
  78.       servo2.write(servo2Value);
  79.     }
  80. #endif
复制代码


2、获得值后,首先将它们从弧度转换为度数。


  1. // Yaw, Pitch, Roll values - Radians to degrees
  2.     ypr[0] = ypr[0] * 180 / M_PI;
  3.     ypr[1] = ypr[1] * 180 / M_PI;
  4.     ypr[2] = ypr[2] * 180 / M_PI;
复制代码




3、然后我们等待或进行 300 次读数,因为在此期间传感器仍处于自校准过程中。此外,我们还捕获了 Yaw 值,该值开始时不像 Pitch 和 Roll 值那样为 0,而是始终是某个随机值。


  1. // Skip 300 readings (self-calibration process)
  2.     if (j <= 300) {
  3.       correct = ypr[0]; // Yaw starts at random value, so we capture last value after 300 readings
  4.       j++;
  5.     }
复制代码


4、在 300 个读数之后,首先我们通过减去上述捕获的随机值,将偏航设置为 0。然后我们将 Yaw、Pitch 和 Roll 的值从 – 90 度映射到 +90 度,映射到 0 到 180 之间的值,用于驱动伺服系统。


  1. // After 300 readings
  2.     else {
  3.       ypr[0] = ypr[0] - correct; // Set the Yaw to 0 deg - subtract  the last random Yaw value from the currrent value to make the Yaw 0 degrees
  4.       // Map the values of the MPU6050 sensor from -90 to 90 to values suatable for the servo control from 0 to 180
  5.       int servo0Value = map(ypr[0], -90, 90, 0, 180);
  6.       int servo1Value = map(ypr[1], -90, 90, 0, 180);
  7.       int servo2Value = map(ypr[2], -90, 90, 180, 0);
  8.       
  9.       // Control the servos according to the MPU6050 orientation
  10.       servo0.write(servo0Value);
  11.       servo1.write(servo1Value);
  12.       servo2.write(servo2Value);
  13.     }
复制代码


5、最后使用 write 函数,我们将这些值作为控制信号发送到舵机。当然,如果您只想对 X 轴和 Y 轴进行稳定,您可以禁用偏航舵机,并将此平台用作相机万向节。

请注意,这与好的相机云台相去甚远。运动并不流畅,因为这些伺服系统不是为了这样的目的。真正的相机万向节使用一种特殊类型的 BLDC 电机来实现平稳的运动。因此,仅将此项目视为教育目的。


【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图16


附录:
项目链接:https://howtomechatronics.com/pr ... abilizing-platform/
项目作者:Dejan
视频教程(13分钟):https://www.youtube.com/watch?v=UxABxSADZ6U&t=6s
MPU6050 教程:https://howtomechatronics.com/tu ... gyroscope-tutorial/
3D打印文件:https://thangs.com/designer/HowT ... ng%20platform-43942
i2cdevlib 库:https://www.i2cdevlib.com/
开源代码:https://howtomechatronics.com/do ... zing-plaftorm-code/


【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图17


实验场景图  动态图


【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图20

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图19

【Arduino 动手做】DIY Arduino 云台 | 三轴自稳定平台图18

3D打印文件和开源代码.zip

591.46 KB, 下载次数: 0

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

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail