机器谱 发表于 2023-4-25 10:05:18

双轮平衡车实现自主平衡功能

本帖最后由 机器谱 于 2023-4-25 10:05 编辑

1. 运动功能说明
       R209样机是一款双轮小车,适合作为自平衡车的实验模型。本文示例将实现双轮小车自主平衡功能,当人为的去打破小车的平衡点时,小车会自动调节至平衡点并稳定下来。

https://28846868.s21i.faiusr.com/2/ABUIABACGAAgg8bzoQYo9qGJkgYw9Ao4ugY!600x600.jpg.webp
2. 结构说明
       该样机主要由两个 直流驱动轮模组【https://www.robotway.com/h-col-117.html】构成。
https://28846868.s21i.faiusr.com/2/ABUIABACGAAglMrzoQYo_Lm6hAcw3wo4wgk!450x450.jpg.webphttps://28846868.s21i.faiusr.com/2/ABUIABACGAAg4MHzoQYopK6n0QYwzQE4-QE.jpg.webp
3. 电子硬件
       在这个示例中,我们采用了以下硬件,请大家参考:


主控板Basra主控板(兼容Arduino Uno)‍
扩展板Bigfish2.1扩展板‍
传感器加速度传感器
电池7.4V锂电池

       电路连接:将两个直流电机分别连接在Bigfish扩展板的(D5,D6)以及(D9,D10)接口上;加速度传感器连接在Bigfish扩展板的A0端口上。

https://28846868.s21i.faiusr.com/2/ABUIABACGAAgn8zzoQYogPX0nwIwwBw4sBU!600x600.jpg.webp
4. 运动功能实现
编程环境:Arduino 1.8.19
将参考例程(self_balance_car.ino)下载到主控板,小车将实现双轮自平衡功能,运动效果可参考官网的实验演示视频。
/*------------------------------------------------------------------------------------

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

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

         https://opensource.org/licenses/MIT

         by 机器谱 2023-04-12 https://www.robotway.com/

------------------------------*/

#include <SignalFilter.h>

SignalFilter Filter;

char filtered;

int a,b,c,d;

const int analogInPin = A0;   // Analog input pin that the potentiometer is attached to

int sensorValue = 0;      // value read from the pot

int outputValue = 0;      // value output to the PWM (analog out)

void setup() {

// initialize serial communications at 9600 bps:

Serial.begin(9600);

Filter.begin();

Filter.setFilter('m');

Filter.setOrder(2);

}

void loop() {

// read the analog in value:

sensorValue = analogRead(analogInPin);         

// map it to the range of the analog out:

char outputValue = map(sensorValue, 0, 1023, 0, 255);

filtered= Filter.run(outputValue);

int a=abs(filtered);

   if((a>=91)&&(a<=100))

    {   

   analogWrite(9,0);

   analogWrite(10,0);

   analogWrite(5,0);

   analogWrite(6,0);

   delay(5);}

   

   if(a>=101)

    {

   c=a+(a-100)*5;

   d=a+20+(a-100)*5;   

   analogWrite(9,0);

   analogWrite(10,c);

   analogWrite(5,0);

   analogWrite(6,d);

   delay(5);   

   analogWrite(9,30);

   analogWrite(10,0);

   analogWrite(5,40);

   analogWrite(6,0);}

   

   if(a<=90)

    {c=a+(90-a)*3+40;

   d=a+20+(90-a)*3+40;

   analogWrite(9,c);

   analogWrite(10,0);

   analogWrite(5,d);

   analogWrite(6,0);

   delay(5);

   analogWrite(9,0);

   analogWrite(10,30);

   analogWrite(5,0);

   analogWrite(6,40);

   }   

Serial.print(a);Serial.print("/");

Serial.print(c);Serial.print("/");

Serial.println(d);

}
5. 资料下载
资料内容:
​①例程源代码
​②样机3D文件
​资料下载地址:https://www.robotway.com/h-col-207.html

想了解更多机器人开源项目资料请关注 机器谱网站 https://www.robotway.com
页: [1]
查看完整版本: 双轮平衡车实现自主平衡功能