Trying SimpleFocMini running on ESP32 with smaller gimbal motors @ 12V unable to get up and running


First post so bare with me :slight_smile:
Building a smaller pan/tilt rig for a 250gr SonyHX90 using a 2 BLDC motor gimbal setup.

3D printed all parts, assembled and connected everything up…

Running SimpleFoc library 2.3.0 on ESP32 with the SimpleFocMini driver, AS5600 via I2C and a cheap smaller china gimbal motor.

Probably attacking this the wrong way. Looked at a few youtube videos. Advise was to start with velocity mode and then angular.

Found a angle example sketch.

Not 100% about my motor spec but looking at a few pages it looks like 12V max 12N14P configuration.

Defined a few pins

#define TILT_ENABLE 18  // Blue
#define TILT_IN1    17  // White
#define TILT_IN2    16  // Grey
#define TILT_IN3    19  // Purple
#define TILT_PP     7   // PolePair from 12N14P

Configured polepair, driver and sensor

// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(7);

// encoder instance
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

Readings from my sensor seems fine running a minmal sketch and turning the motor.

velocity PID tuning and filter settings

  // velocity PI controller parameters
  motor.PID_velocity.P = 0.3f; // was 0.2f
  motor.PID_velocity.I = 8; // was 20
  motor.PID_velocity.D = 0;
  // default voltage_power_supply
  motor.voltage_limit = 12;
  // jerk control using voltage voltage ramp
  // default value is 300 volts per sec  ~ 0.3V per millisecond
  motor.PID_velocity.output_ramp = 1000;

  // velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.001f; // was 0.01f

I cannot get to a smooth rotation using velocity control.
Downloaded SimpleFOCStudio

But it failed to start due to missing QT materials on my Fedora setup so had to start it using

Struggle to get the SimpleFOCStudio creating graphs consistently. Most of the time I just get errors via serial

unknown cmd err
unknown cmd err
unknown cmd err
unknown cmd err
unknown cmd err 

List devices return the M:motor

Some properties are updated. Like if the driver is enabled or not. But as you can see the legend is not working on the graph. Not really knowledgable in PID control theory or tuning but looks to me that P is too small since it takes time to reach the net set target value.

I have the following in my sketch for the angle part

  // angle P controller
  motor.P_angle.P = 1.0f; // was 20
  motor.P_angle.I = 0.0f; // was 20
  //  maximal velocity of the position control
  motor.velocity_limit = 6;

It’s a bit of copy & paste but not sure why the motor.velocity_limit is under the angle section.
Could that also be a contributor to why it takes time to reach either target speed or angle.

Also very jerky movement. And when running angle it make a lot of noise at the fix point.
Looking at my benchsupply current is a 0.2amp max.

I think I need to get a smooth rotation using velocity first if I understand correctly.
I’ve started questioning the polepair setting and maybe even if I connected the phases correctly.

Found the calibration sketches. find … polepair… kv… But they are not working “as expected”.

MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: fail - estimated pp: 12.34
MOT: Zero elec. angle: 4.35
MOT: No current sense.
MOT: Ready.
Motor ready.
Set the target voltage : - commnad T
Calculate the motor KV : - command K
2.000   <- T2
0.39     <-K

KV value seems like a non-typical-kv value
And… Motor initialization fails with PP check: fail - estimated pp: 12.34

A lot of questions. But maybe starting focusing on one of them.
I guess nailing the motor spec, winding, polepair, KV, getting it connected correctly is a first…

Got the SimpleFOCStudio working a little better.

Here I’m changing my target from 2 → 1 → 0 → 1 → 2 → 0

I both need smooth slow pan/tilt which is of priority since this is an application requiring a bit of zooming where the action takes place but also speed at times. So maybe I’m 20% there in terms of having a first prototype up and running. Will try to do the pan motor now and hope adding it to the same ESP doesn’t alter the PID tuning done up to here. But reading a few threads leads me to believe it could be a fact. Have been going back an forth whether or not to go for a modular approach of having each axis controlled by dedicated (battery + esp32 + drv8313 + as5600). Would be interesting to understand if a 12bit → 14bit sensor would imrove the setup.

This is not the final goal. Goal is to do a 2-axis pan/tilt head for a DSLR @ 3kg roughly. So trying to evaluate SimpleFOC lib using cheaper hardware which I guess is not an entirely well thought out plan.

Hey, I think it’s a good plan, just that you were unlucky with the motors you picked…

We had a chat about it on discord :slight_smile:

The LPF setting is also an important one to look at when you have slow sensors/unsmooth velocity.

I just tried ESP32 and drv8313 now. It works normally, but my motors are not like that. Try:
motor.PID_velocity.P = 0.1;
motor.PID_velocity.I = 1;
motor.PID_velocity.D = 0;

Does it work in open loop? Usually the advice that has crystallized out on these forums is get open loop working first, and then torque mode, then I forget if velocity or angle mode should come next, I think angle mode.

There are so many things that can go wrong or add up that I think this is advisable.

These sensors benefit from the calibration routine too, there is one built in.

If the pole pair check doesn’t work the resto probably won’t.

14 pole pairs is a lot for a motor of this size. All the ones I have are 8 pole pairs or so and I have like 50.

Taking P from 1 → 0.1 when I already have a slow convergence against the set value seems strange. I will off course try any value to get my PID’s tuned. But I would like to understand the process and learn to iterate more quickly to the correct value rather than brute forcing it.

Hi @Anthony_Douglas! This is my understanding as well. I had trouble getting the SimpleFOCStudio connected and displaying and updating values so uploading the sketch in between PID tuning was slow and tedious but now I’m over that hurdle. I have a setup for the tilt motor that is somewhat working. Enough to move on to getting the pan motor integrated. I will revisit the PID tuning and optimize further at a later stage.

Also waiting for larger/better quality BLDC motors.

I think angular mode should come last. I think velocity PID is the inner PID so makes sense have that dialed in first. But not 100% on that.

Yes, angle mode builds on velocity mode. Tune the velocity PID first, and then try angle mode. Angle mode usually doesn’t need too much tuning, its easier to tune than the velocity in my experience.

Curious what motors you’re using for this? I’m looking at building a similar gimbal and would love to mimic yours and then I could help contribute feedback to you on how it goes on my side.

I’m looking at using the roll motors that are the size of the DJI 3 camera, especially the hollow one to run the camera cable through.