simple foc 移植odriver foc的 anti-cogging(抗齿槽算法)

本文介绍了作者将ESP32与simplefoc结合,从硬件到软件实现BLDC电机驱动的反齿槽控制过程,包括电阻三采样、前馈数组生成以及代码细节。视频效果可见相关链接。
摘要由CSDN通过智能技术生成

ESP32 simple foc 移植odriver anti-cogging.

1.硬件,在淘宝买的。esp32 +simple foc(最新). 下电阻三采样。

2. 效果,见视频https://www.bilibili.com/video/BV1xg4y1X7Yr/?vd_source=4fd70d693021f289fb2d339c6c040719

3.代码添加(生成前馈数组,就与补偿齿槽效应的扭矩)


void loop() {
  static int ccc,changed_tar,dis_cc;
  static float tar = 0;

  // iterative setting FOC phase voltage
  motor.loopFOC();

  // iterative function setting the outter loop target
  motor.move();
  
  if (1)
  {

  if (fabs(motor.shaftVelocity())<0.0001 && fabs(motor.shaftAngle()-tar)<0.0003 && ccc>100 && changed_tar)
  {
    char bufcmd1[50];
    if (changed_tar == 1)
    {
      ccc = 0;
      changed_tar = 2;
    }
    else
    {   
      sprintf(bufcmd1,"stop:%f %f %f %f %f",tar*180/3.14159,motor.shaftAngle()*180/3.14159,fabs(motor.shaftAngle()-tar)*180/3.14159,motor.shaftVelocity(),motor.current_sp);
      Serial.println(bufcmd1);

      ccc = 10001;
      changed_tar = 0;
    }
  }
  
    if(ccc++>10000 && changed_tar == 0)
    {
      char bufcmd[50];
      unsigned int buf;
      changed_tar = 1;
      ccc = 0;
      tar +=0.0035;//0.2 degree
      motor.target = tar;

    }
  }
  // monitoring the state variables
//  motor.monitor();   //会影响程序执行速度,与studio交互的配置3共3处

  // user communication
  command.run();
 
}

补偿位置 ,在BLDCMotor.cpp下的。void BLDCMotor::move(float new_target)

case MotionControlType::velocity:
    	static int ffccc;
		int ttt;
      // velocity set point - sensor precision: this calculation is numerically precise.
      shaft_velocity_sp = target;
      // calculate the torque command
      if (shaft_angle<0)
      {
	  	ind = floor(fmod(-shaft_angle,2*_PI)*286.0f);
      }
      else
      {
      	ind = floor(fmod(shaft_angle,2*_PI)*286.0f);
      }
      ttt = ind;
      if (ind>=1797)ind = 1796;
      if (ind<=0)ind = 0;
      
      current_sp = anti_cogging_map[ind]*anti_cogging_coef+PID_velocity(shaft_velocity_sp - shaft_velocity); // if current/foc_current torque control
		if (ffccc++>20000){
			char buf[40];
			ffccc = 0;
			sprintf(buf,"V:%f %f %f %d %d",target,current_sp,shaft_angle,ttt,torque_controller);
			Serial.println(buf);
		}
      // if torque controlled through voltage control

基本原理

  • 就是每次步进一个很小的角度(我这里是0.2度),选择360度,然后生成一个大的数组,以后在到达的角度固定前馈进去就行了,主要是保存上面的motor.current_sp.存成一个数组就行了。

后续再补充。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值