BGC 3.0 with gimbal motor not working in closed-loop

Hi everyone,

First of all, thanks for the amazing library that makes BLDC motors more accessible and thanks for the extensive support.

I’m trying to troubleshoot my set-up that is not working properly. I’ve spent a few days looking at the forum and the documentation but now I ran out of ideas.

I’m using a BCG 3.0 clone board (ATMega328 with two discrete FET drivers). My motor is a gimbal BLDC motor 2805 140T (that should have 7 pole pairs). I’m also using an AS5600 connected through I2C. This is the cheapest hardware I found so I hope this post can help other people who want to start using this library with a low funds commitment.

These are my motor and driver instances:

BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9,10,11);

I’m using SimpleFOC 2.1

I’m testing the example codes and my set-up is not working when run in a closed-loop. The motor won’t move at all neither in angle or velocity configuration.
The motor first moves during the calibration executing motor.initFOC() but then becomes irresponsive inside the main loop and it may start shaking if I try to move it by hand.

I also tried the pole pairs finder code but with unreliable results, always different and oftentimes negative.

The interesting part is that works fine in open-loop.

I believe the motor has 7 pole pairs (I was using the wrong number earlier and corrected it). In open-loop it makes a full turn when I input an angle of 6.28.

I also think the magnetic sensor is working properly as the reading shows consistent angles data when the motor is turned by hand (i.e. 6.3 for a full turn, 12 for two, correct negative values etc…)

Now I have two questions:

  1. I’m wondering if the magnet is diametrically magnetized. Is it possible that the magnetic sensor shows correct data even if the magnet is wrong?

  2. I tried changing the voltage settings as suggested in other posts with no results. Is it possible the PID tuning is causing problems?

Besides these two doubts I have, I don’t know what else to try.

Can you please suggest any other tests I can try?

Thanks

Non diametric magnets almost work, i.e they can fool you into thinking they are the right type. But if you are moving 360 and they change seems linear (look at it in a graphing tool) then I’d probably ok.

I’d try it in voltage mode (which i think it’s now called torque mode) first as this doesn’t need PID tuning. Keep the values low to start.

There’s magnet viewing screens that let you “see” the magnetic field.

But I find a cheap test is if you have several magnets: the radially magnetised ones like to stick to each other side to side, in a “chain”, while the axially magnetised ones (wrong kind!) stick face to face, in a “cylinder”…

I had the BGC 3.0 board working quite well. I would start out getting only 1 motor working to begin with. You will find that the combination ATMega328P and I2C sensors is not very fast - but it will turn two motors (just barely) with some optimisations to the sensor code. Don’t expect to run a lot of other code on this MCU as well though…

As to why it is not working, could you give some more details on your code/setup? Its a bit hard to say what the problem is from the information given, but if open-loop is working, and sensor-reading is working, then you can’t be too far from closed loop control!

I use square magnets. Only need to set the correct magnetic field. It works.

I spent another good two hours or so trying different modes and parameters with no result. The motor just doesn’t move, shakes and make noise in a closed-loop configuration.

I also plotted the angle reading while the motor was moving in open-loop and it seems reasonable.

However, I still think the magnet may be wrong: if I place two of them (I only have two) side by side I can freely rotate one while I expected it to take just one position.

The code I’m using is quite straightforward and mostly coming from the examples.

BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9,10,11);
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);


void setup() {
  Serial.begin(9600);
  sensor.init();
  motor.linkSensor(&sensor);

  driver.voltage_power_supply = 12;
  driver.init();

  motor.linkDriver(&driver);

  motor.controller = MotionControlType::angle;
  

  motor.PID_velocity.P = 0.5;
  motor.PID_velocity.I = 10;
  motor.PID_velocity.output_ramp = 1000;
  motor.voltage_limit = 2;
  motor.LPF_velocity.Tf = 0.01;
  motor.P_angle.P = 20;
  motor.velocity_limit = 3;

  motor.useMonitoring(Serial);

  motor.init();
  motor.initFOC();
}

float target_position = 0; // rad/s

void loop() {
  serialReceiveUserCommand();
  motor.loopFOC();
  motor.move(target_position);
}

The output of the motor.monitor() is the following:

MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp:9.9177
MOT: Zero elec. angle: 3.42
MOT: No current sense.
MOT: Ready.

The pole pair check always fail with the estimate being a random number that variates from negative to very high values. But I’m confident the motor has 7 pole pairs.

To answer @runger I don’t expect to have great performances from this setup. It’s just a very cheap way to start, do some tests and build a custom driver asap.

Thanks @Rem666 for the heads up. I wonder if it’s worth trying place my cylindrical magnets perpendicularly with respect to the sensor.

In absence of other ideas, I’ll just order new magnets.

While waiting for the arrival of new magnets, I found some time to mount the magnets I currently have on their side.
The library now works as expected meaning this is again a case of wrong magnets…
IMG_0053
I’m so sorry to have wasted your time but I’m also thankful for the help and good hints received.

Key takeaways should someone end up in a dumb situation like mine:

  • axially magnetised magnets (the wrong ones) are difficult to identify and for some aspects will look like diametrically magnetized;
  • with wrong magnets, the motor will work in open loop mode but not in closed-loop
  • In closed-loop mode the motor will shake and won’t move.
  • The pole pairs check will fail
  • If unsure, you can try mounting the magnets sideways.
4 Likes

Hi @ridoluc,

Great that your problem is solved! I also had the same problem.

Another tip for people in the same situation to identify the magnet is by using a compass.

  • If you turn an axially magnetised magnet above it, the compass will not correcty follow your rotation.
  • With a diametrically magnetized magnet, it you turn it the compass will follow your magnet correctly.

Good luck with your project!

Hi all,
I am testing this library with a very similar setup (BGC 3.0 clone, AS5048 over SPI and a gimbal with 7 pole paires)

On the sensor side, I can get a coherent angle with the hand-made motion of the motor.
The driver is able to drive the motor smoothly in openloop. However, when I try to close the loop, I get the same behavior as the original post : the motor is turning (not smoothly) at the initFOC call, then shaking a lot, as depicted on the video here. The code is taken from the library example named “velocity_motion_control”.

For 2 days I am struggling to make it work in closed loop and I would like a bit of advice from your side.
What I’ve done :

  • flashed a bootloader on the BGC with the arduino uno. The board is considered as a Nano although some post on this forum explained it should be set as a “Arduino Pro or Pro Mini”; but this seems to be working so far
  • found the true pinout of the board (similar to this post, but with different pinout though… a very weird clone)
  • enjoyed the open-loop control

I know from this thread that this problem could arise from magnet problem but I tried many different magnets, also put them on their side. Still, closed-loop velocity control issues remain…

I would like to know if somebody faced a similar problem that was not solve through magnet reorientation ?
Any suggestion would be appreciated :slightly_smiling_face:

Hey @jeanL,

Make sure you’re not using the same pins for the SPI and the PWM generation.

Basically the issue is the pin 11 and potentially pin 10. Pin 10 for the SPI is the chip select pin which can be set to any Arduino pin really. But pin 11 has to be used for the SPI though ( at least for the simplest configuration of the SPI).

So I’d suggest you to use the pins 3,5 and 6 for the PWM generation if possible. If not try avoiding pin 11 and set the chip select to some other pin than pin 10.

Hey @Antun_Skuric
thank for the answer, and indeed I am using the constructor with pwm pins 9,10,11
I will definitely try your advice tomorrow morning when i will go to my lab.
Of course, i’ll keep you posted about the progress of my problem !

hi,
i changed the pwm pins to 3,5,6 and the result is better
The setup() function of the code is executed smoothly, that is, the driver is able to find the motor direction and motor zero electrical angle.
However, when the program enters the loop(), the motors start shaking although the target velocity is zero intially.
When changing the target velocity, the motor is spinning in the right direction, with the right amount of velocity but it is not smooth at all : there is a lot of shaking
Any idea of where this can come from ?

the loop function is only composed of the three lines of the example sketch…

one more interesting thing :
as suggested in different post on this forum, I tried the torque control mode and indeed the torque control is working very well in closed loop !! Position and Velocity control are not working in closed loop.
So I don’t get where this problem come from…
because if the openLoop, initFOC and torque control are working, my sensor should be reliable and the wiring should be right.