Is Simple FOC an alternative to BGMC2 from RoverTec

Hey, nice!

What is taking 2s? Is it the initialisation of the motor for the initFOC() calibration?

If so, you can reduce the time by passing the electrical angle and direction to the initFOC() method, then it does not have to calibrate…

Hi Richard,
I already have
“motor.initFOC(0.05, Direction::CCW);”
implemented in my code. Is there anything else I can do?
Should I post my complete code?

It can’t hurt, if you don’t mind us taking a look :slight_smile:

#include <SimpleFOC.h>
#include <encoders/MT6701/MagneticSensorMT6701SSI.h>

// motor data
const int pole_pairs = 7;
const int pwmA = 4;
const int pwmB = 5;
const int pwmC = 6;
const int enable = 20;

// sensor data
const int clk = 18;
const int miso = 16;
const int nCS = 17;

// potentiometer
const int poti = 28;
float z = PI/10*2; // zero speed = 3rpm i=1:2
// float i = 1630; // 3rpm + poti(0-3)rpm
float i = 978; // 3rpm + poti(0-5)rpm
float velocity_ = 0;  // motor
float target_velocity = 0; // poti
unsigned long startTime = millis();

// motor instance
BLDCMotor motor = BLDCMotor(pole_pairs);
// driver instance
BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, enable);
// magnetic sensor instance
MagneticSensorMT6701SSI MT6701(nCS);

//wakeup
const int powerpin = 3;
unsigned long previousmillispower = 0;
unsigned long sethigh = 9950;
unsigned long previousmillistime = 0;
unsigned long setlow = 10000;

void setup() {
  
//  Serial.begin(115200);
//  motor.useMonitoring(Serial);
  
  pinMode(poti,INPUT);
  pinMode(powerpin,OUTPUT);
  digitalWrite(powerpin,HIGH);
  
  MT6701.init();
  motor.linkSensor(&MT6701);

  driver.pwm_frequency = 100000;
  driver.voltage_power_supply = 12.0;
  driver.voltage_limit = 12.0f;
  driver.init();
  motor.linkDriver(&driver);

  motor.controller = MotionControlType::velocity;
  motor.voltage_limit = 12.0f;     //default 12
  motor.PID_velocity.P = 1.0;      //default 0.5     neu 1.0 
  motor.PID_velocity.I = 25;        //default 90     neu 25, niedriger Drehung hängt je nach Kraft hinterher, höher läuft "smoother" schwingt aber ein
  motor.PID_velocity.D = 0.00001;  //default 0.00185 neu 0.00001 macht keinen Sinn höhere Werte zu nehmen
  motor.PID_velocity.output_ramp = 1000;
  motor.LPF_velocity.Tf = 0.03;   //default 0.0425   neu 0.03 je niedriger, desto konstanter die Drehzahl
    
  motor.init();
  motor.initFOC(0.05, Direction::CCW); //default X.XX, Direction::CCW
//  motor.initFOC(); //for check offset and direction
  
  _delay(50);
}

void loop() {
  
  float target_velocity = z + analogRead(poti)/i;
    if((millis() - startTime) > 25) {
      if (target_velocity != velocity_)
      {
        if (target_velocity > velocity_)
        {
          velocity_ = velocity_ + 0.025;
        }
        if (target_velocity < velocity_)
        {
          velocity_ = velocity_ - 0.025;
        }
      }
        startTime = millis();
    }

   if((millis() - previousmillispower) == sethigh)
      {
        digitalWrite(powerpin,HIGH);
      }
   if((millis() - previousmillistime) == setlow)
      {
         digitalWrite(powerpin,LOW);
         previousmillispower = millis();
         previousmillistime = millis();
      }
  
  motor.loopFOC();
  motor.move(velocity_);


}

Hey Thomas,

Your code looks fine. But the SimpleFOC code contains 2s of delays:

2x 500ms is in motor.init()
2x 500ms is in motor.initFOC()

From my point of view, with your setup and when you are passing in the calibration values, you can remove (comment out) all these delays.

We should add a way to make this easier to do, but at the moment you would have to modify the library code in BLDCMotor.cpp.

1 Like

Interesting thread for sure. Haven’t read it all of course, but I do think that the lepton 3.0 would solve most of these issues. We seem to spend a lot of time searching for and trying out boards that other people make/have made. I think it’s high time to level up and finally get one designed that gives us what 80 percent or so of people on here need, which is very much doable with a cross between the b-g431b-esc1 board and the lepton 2.0 I think. Something that will last, and when work gets done on it, it stays done. If parts go out of stock then it can always be adapted.

1 Like

Why is that?
Is there a version of a “mini” driver that would work with a 2S LiPo?