找回密码
 立即注册
搜索
查看: 3132|回复: 1

速度环

[复制链接]

2

主题

2

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2022-12-18 14:02:54 | 显示全部楼层 |阅读模式
平衡小车之家的速度环


/**
* @function:int Velocity(int Encoder_left,int Encoder_right,int Mechanical_velocity)
* @description:速度环PI控制
* @param {int} Encoder_left 数据 :左电机编码器的值
* @param {int} Encoder_right 数据 :右电机编码器的值
* @param {int} Mechanical_velocity 数据 :目标速度 ,因为只是让小车尽快平衡并静止,这里目标速度也设为0
* @return {int} Up_balance :速度环控制PWM
*/
int velocity(int encoder_left,int encoder_right)
{  
        int Velocity,Encoder_Least; //速度环控制PWM,获取最新速度偏差
        static float Encoder,Encoder_Integral; //一阶低通滤波后的速度值,速度的积分;因为积分累加和滤波的需要,故设置为静态量,存储在全局区域类似于全局变量
    Encoder_Least =(encoder_left+encoder_right)-0;                    //===获取最新速度偏差==测量速度(左右编码器之和)-目标速度(此处为零)
                Encoder *= 0.8;                                                                //===一阶低通滤波器      
                Encoder += Encoder_Least*0.2;                                            //===一阶低通滤波器   
                Encoder_Integral +=Encoder;                                       //===积分出位移 积分时间:10ms
                if(Encoder_Integral>10000)          Encoder_Integral=10000;             //===积分限幅
                if(Encoder_Integral<-10000)        Encoder_Integral=-10000;              //===积分限幅       
                Velocity=Encoder*Velocity_Kp+Encoder_Integral*Velocity_Ki;        //===速度控制       
                if(Turn_Off(roll)==1)   Encoder_Integral=0;      //===电机关闭后清除积分
          return Velocity;
}

入口参数是单纯的读取左右编码器的值,还是单位时间内左右编码器的变化值?第一种是0到65535的那种,第二种是上一次读取的值减去这次读取的值
回复

使用道具 举报

0

主题

2

帖子

16

积分

新手上路

Rank: 1

积分
16
发表于 2023-1-11 09:49:28 | 显示全部楼层
入口参数是读取单位时间内左右编码器的变化值,是0-65535,Read_Encoder(void)函数会每次计数清零
回复

使用道具 举报

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

本版积分规则

粤ICP备20017043号|小黑屋|手机版|Archiver|轮趣科技(东莞)有限公司  

GMT+8, 2024-4-27 05:07 , Processed in 0.061296 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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