资源简介
如何在家自己动手做一个arduino平衡车?简单的源代码分享,优酷有我的视频!
代码片段和文件信息
#include “BalanceCar.h“
//////////////////速度PI////////////////////
double BalanceCar::speedpiout(double kpsdouble kisdouble kdsint fint bdouble p0)
{
float speeds = (pulseleft + pulseright) * 1.0; //车速 脉冲值
pulseright = pulseleft = 0;
speeds_filterold *= 0.7; //一阶互补滤波
float speeds_filter = speeds_filterold + speeds * 0.3;
speeds_filterold = speeds_filter;
positions += speeds_filter;
positions += f; //全进控制量融合
positions += b; //全进控制量融合
positions = constrain(positions -25502550); //抗积分饱和
double output = kis * (p0 - positions) + kps * (p0 - speeds_filter); //速度环控制 PI
if(flag1==1)
{
positions=0;
}
return output;
}
//////////////////速度PI////////////////////
float BalanceCar::turnspin(int turnleftflagint turnrightflagint spinleftflagint spinrightflagdouble kpturndouble kdturnfloat Gyroz)
{
int spinonce = 0;
float turnspeed = 0;
float rotationratio = 0;
float turnout_put = 0;
if (turnleftflag == 1 || turnrightflag == 1 || spinleftflag == 1 || spinrightflag == 1)
{
if (spinonce == 0) //旋转前判断当前车速,增强小车适应性。
{
turnspeed = ( pulseright + pulseleft); //小车当前车速 脉冲表示
spinonce++;
}
if (turnspeed < 0) //小车当前速度绝对值
{
turnspeed = -turnspeed;
}
if(turnleftflag==1||turnrightflag==1)
{
turnmax=7; //5->7
turnmin=-7;
}
if(spinleftflag==1||spinrightflag==1)
{
turnmax=10;
turnmin=-10;
}
rotationratio = 55 / turnspeed; //根据小车速度设定值
if (rotationratio < 0.5)rotationratio = 0.5;
if (rotationratio > 5)rotationratio = 5;
}
else
{
rotationratio = 0.5;
spinonce = 0;
turnspeed = 0;
}
if (turnleftflag == 1 || spinleftflag == 1)//根据方向参数叠加
{
turnout += rotationratio;
}
else if (turnrightflag == 1 || spinrightflag == 1)//根据方向参数叠加
{
turnout -= rotationratio;
}
else turnout = 0;
if (turnout > turnmax) turnout = turnmax;//幅值最大值设置
if (turnout < turnmin) turnout = turnmin;//幅值最小值设置
turnout_put = -turnout * kpturn - Gyroz * kdturn;//旋转PD算法控制 融合速度和Z轴旋转定位。
return turnout_put;
}
void BalanceCar::pwma(double speedoutputfloat rotationoutputfloat anglefloat angle6int turnleftflagint turnrightflagint spinleftflagint spinrightflag
int fint bfloat accelzint Pin1int Pin2int Pin3int Pin4int PinPWMAint PinPWMB)
{
pwm1 = -angleoutput - speedoutput + rotationoutput; //Left电机PWM输出值
pwm2 = -angleoutput - speedoutput - rotationoutput; //Right电机PWM输出值
//幅度值限制
if (pwm1 > 255) pwm1 = 255;
if (pwm1 < -255) pwm1 = -255;
if (pwm2 > 255) pwm2
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 33405 2018-02-09 06:09 Self Balancing Robot Circuit and Code- Tapendra Mandal\Circuit\Self Balancing Robot Circuit Diagram.pdf
文件 10788 2018-02-09 06:15 Self Balancing Robot Circuit and Code- Tapendra Mandal\Code\Self_Balancing_Robot\Self_Balancing_Robot.ino
文件 4129 2017-06-02 12:12 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\BalanceCar\BalanceCar.cpp
文件 1100 2017-06-02 12:13 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\BalanceCar\BalanceCar.h
文件 6515 2012-02-13 09:16 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\Flexitimer2\FlexiTimer2.cpp
文件 518 2012-02-13 09:16 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\Flexitimer2\FlexiTimer2.h
文件 56402 2017-03-09 21:50 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\I2Cdev\I2Cdev.cpp
文件 12084 2017-03-09 21:50 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\I2Cdev\I2Cdev.h
文件 2042 2017-06-02 12:14 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\KalmanFilter\KalmanFilter.cpp
文件 862 2017-06-02 12:14 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\KalmanFilter\KalmanFilter.h
文件 4883 2017-03-09 21:49 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050\helper_3dmath.h
文件 38714 2017-03-09 21:49 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050\JJ_MPU6050_DMP_6Axis.h
文件 124718 2017-03-09 21:49 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050\MPU6050.cpp
文件 40751 2017-03-09 21:49 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050\MPU6050.h
文件 39077 2017-03-09 21:49 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050\MPU6050_6Axis_MotionApps20.h
文件 46665 2017-03-09 21:49 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050\MPU6050_9Axis_MotionApps41.h
目录 0 2018-02-09 06:16 Self Balancing Robot Circuit and Code- Tapendra Mandal\Code\Self_Balancing_Robot
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\BalanceCar
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\Flexitimer2
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\I2Cdev
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\KalmanFilter
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries\MPU6050
目录 0 2018-02-09 06:10 Self Balancing Robot Circuit and Code- Tapendra Mandal\Circuit
目录 0 2018-02-09 06:16 Self Balancing Robot Circuit and Code- Tapendra Mandal\Code
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal\Libraries
目录 0 2018-02-09 06:17 Self Balancing Robot Circuit and Code- Tapendra Mandal
----------- --------- ---------- ----- ----
422653 26
- 上一篇:微信小程序 播放器的设计
- 下一篇:winsock聊天室程序
相关资源
- Arduino 格力空调红外编码库,当时做的
- Arduino-电子秤加数字显示
- Arduino通过RC522实现开门
- arduino烧录esp8266程序
- arduino通过红外遥控结合蜂鸣器的定时
- arduino mpu6050 dmp库文件
- arduino温湿度采集头文件.rar
- Arduino 步进电机接线方法含有代码
- 四位数码管+DS3231做电子时钟源码.in
- arduino控制57步进电机
- 使用Processing+Arduino写的类似雷达扫描
- arduino上阿里云所需要用到的四个库文
- 基于Arduino的DHT11库文件
- Arduino-DHT11温湿度传感器库文件
- ESP8266(arduino)连接阿里云物联网平台
- TCS3200颜色传感器Arduino优化代码快速识
- avrdude-GUI 1.0.5
- arduino程序,用两个红外线传感器来判
- PID巡线,arduino
- ArduinoUSBKeyboard库文件
- arduino DS3231库
- Arduino串口转发源代码
- arduino+rc522读写卡
- arduino_code.rar
- arduino和ds1302的基于lcd12864闹钟,按键
- Arduino-TMC2130Stepper.zip
- Arduino-smartcar_shield.zip
- 基于arduino的温度检测和显示
- TFmini_Plus I²C版在Arduino上的例程及参考
- pid算法-arduino
评论
共有 条评论