Problems with torque-control

Hey,

I’m having problems with the torque and voltage control.
I am building a 2-DOF GImbal to align a camera.
I am using:

  • GM5208-24 motors from iPower
  • as5048a encoder
  • Nucleo f446re
  • SimpleFOC mini v1.0
  • labor power supply

Yesterday I assembled my construction for the first time and had already successfully tested the individual motors and sensors in advance.

After the assembly I was able to control and align both motors but both motors showed the following behavior:

They approached the individual target angles but after a certain limit the motors block and simply start to draw more current. While this is happening, the motors do not react to further inputs.

To get to the bottom of the problem, I checked and tested the following things today:

  • Wiring
  • Sensor values, both in the program and with the sensor test examples
  • open-loop Velocity
  • open-loop position
  • closed loop velocity
  • torque control
  • Replacing the drivers

While my pitch axis now works in all modes (PINS were inserted incorrectly), I have problems with the yaw axis. Open-loop works fine in terms of speed and position. The closed-loop velocity does not work. I then tested the torque control to rule out controller problems and the motor now runs at 2V for about 27 revolutions and then stops. During the revolutions you can hear that a kind of friction occurs at two points of the rotation which slows down the motor (no mechanical friction, the motor can rotate freely if no voltage source is connected). If the target voltage is set to 0, the motor can be rotated without any noticeable force. If I set a voltage of 12v, then the motor holds its position after stopping but does not turn any further. I have already read most of the forum entries on similar topics and unfortunately have had no success in finding a solution so far. Has anyone had a similar problem?

Otherwise, many thanks to all those who have contributed to this project and made it possible for me to complete my project!

Thats the code i use for torque-control:

/**

  • Torque control example using voltage control loop.
  • Most of the low-end BLDC driver boards doesn’t have current measurement therefore SimpleFOC offers
  • you a way to control motor torque by setting the voltage to the motor instead hte current.
  • This makes the BLDC motor effectively a DC motor, and you can use it in a same way.
    */
    #include <SimpleFOC.h>

// magnetic sensor instance - SPI
#define AS5048_CS_2_PIN PD2
SPIClass SPI_3(PC12, PC11, PC10);

// Sensor-Objekt
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, AS5048_CS_2_PIN);
// magnetic sensor instance - I2C
// MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
// magnetic sensor instance - analog output
// MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);

// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(PC6, PC7, PC8, PC9);
// Stepper motor & driver instance
//StepperMotor motor = StepperMotor(50);
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);

// voltage set point variable
float target_voltage = 2;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }

void setup() {

// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);

// initialise magnetic sensor hardware
SPI_3.begin();
sensor.init(&SPI_3);
// link the motor to the sensor
motor.linkSensor(&sensor);

// power supply voltage
driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);

// aligning voltage
motor.voltage_sensor_align = 5;
// choose FOC modulation (optional)
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set motion control loop to be used
motor.controller = MotionControlType::torque;

// comment out if not needed
motor.useMonitoring(Serial);

Greetings
Thomas

Hi, I have a similar problem, the motor turns for a while in the torque-voltage mode, but after that it just locks up/blocks, the current increases and my ESP32 does not respond to commands, the monitor() also stops sending data to serial. Did you manage to find a solution?

Hi @arch welcome to SimpleFOC!

it does not sound like your problem is the same as Thomas.

@Thomas_Stingel very sorry you never got an answer to your issue back in March. I hope you have solved it.

Arch, how long is “a while”? Are we talking many minutes or just a short time?

Which ESP32 are you using?

Hi @runger, thanks for reply.

It depends on what kind of target I set in the torque-voltage mode (I used pp, resistance and KV). If <1, then it spins for a long time and gets stuck only if I stop it with my hands. If >1, then it spins for up to 10 seconds and stops. Also, ESP32 sends an error many time before it is blocked:
(15513) i2c.master: I2C hardware timeout detected
E (15513) i2c.master: s_i2c_synchronous_transaction(945): I2C transaction failed

By “lock/stall” I mean:

  1. Either the ESP does not send anything to Serial at all and does not respond to commands (only the reboot helps). The current is increasing. The motor stops in place.

  2. Either ESP restarts itself with an error:
    Guru Meditation Error: Core 1 panic’ed (StoreProhibited). Exception was unhandled.

    Core 1 register dump:
    PC : 0x400857cb PS : 0x00060033 A0 : 0x80082a58 A1 : 0x3ffbfc9c
    A2 : 0x3ffb8e5c A3 : 0x00000001 A4 : 0x3ffb928c A5 : 0x3ffb8ed0
    A6 : 0x3ffb8f5c A7 : 0x3ffbfcb8 A8 : 0x00000000 A9 : 0x00000001
    A10 : 0x00000048 A11 : 0x3ff53000 A12 : 0x00000000 A13 : 0x00000000
    A14 : 0x00000000 A15 : 0x0000abab SAR : 0x00000000 EXCCAUSE: 0x0000001d
    EXCVADDR: 0x00000000 LBEG : 0x40084df4 LEND : 0x40084dff LCOUNT : 0xffffffff

    Backtrace: 0x400857c8:0x3ffbfc9c |<-CORRUPTED

    ELF file SHA256: 728e39f94

    Rebooting…
    ets Jun 8 2016 00:22:57

    rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0030,len:4980
    load:0x40078000,len:16612
    load:0x40080400,len:3480
    entry 0x400805b4

I really haven’t been able to figure out what’s going on for a long time(because i am newbie in electronics and simple foc) maybe it’s the EMF, because these stalls occur under load.
Motor 5010 360KV 0.27 Ohm
Driver MKS dual foc 3.3 12V
Encoder I2C MT6701
In open loop it works pretty good

From your description it sounds a bit like you’re somehow exceeding the capabilities of your power supply, or perhaps getting spikes into the 3.3V line. For example with your setup you would be setting a target current in torque mode. So when you set it too high the BEMF rises as the motor turns faster. The controller reacts by adjusting the voltage up to counteract the BEMF. Eventually the capacity of the PSU is exceeded and the voltage drops, and the ESP32 experiences a brown-out. Something like that.

Or if you find you can reset the esp by sharply moving the motor or by stopping it suddenly while moving, then perhaps there are spikes coming across from the motor to the MCU…

@runger I decided to remove the ESP from the driver (see the photo with my poor setup) and everything started working much better! Maybe my driver doesn’t have reverse protection or something?

That’s interesting! It definitely sounds like something electrically dodgy is going on. Is everything the same just with cables, or did you change something about the way it gets powered also?

No, I just removed the ESP from the driver (I used it as a shield before) connected the necessary pins with wires and that’s it.

Maybe the problem was through one of the other pins then, that is now not connected?

So, this is probably some kind of magic, now the system is not working, but for a different reason. I’m trying to calibrate the sensor, but why isn’t it initializing or something?

But it was working before? Is the call to initFOC moving the motor?

Yep, it worked 30 minutes ago), but apparently something happened

The magnetic sensor test itself works, the angle is shown, one revolution is 2Pi.

I noticed an interesting thing, during the encoder test, when I was turning the motor with my hand, the PSU went into OCP protection. I don’t even know what to do about it. But then again, everything was working just now. Going to see with a scope tomorrow.

No, it doesnt

Update: open loop also doesnt work now, maybe my driver is completely broken. Here’s the video and code of what’s going on

#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(7, 0.27);
BLDCDriver3PWM driver = BLDCDriver3PWM(32,33,25,22);

float target_velocity = 2;

//Serial command setting
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }

void setup() {
  
  driver.voltage_power_supply = 12;
  driver.init();
  motor.linkDriver(&driver);
  motor.voltage_limit = 2;   // [V]
  motor.velocity_limit = 40; // [rad/s]
 
  //Open loop control mode setting
  motor.controller = MotionControlType::velocity_openloop;
  //Initialize the hardware
  motor.init();

  command.add('T', doTarget, "target velocity");

  Serial.begin(115200);
  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");
  _delay(1000);
}

void loop() {
  motor.move(target_velocity);

  command.run();
}

In that video it looks like only one of the phases is working?

I’d say for open loop you need to drop your voltage limit. With 0.27Ohm resistance 2V will still be quite a few amps. To move the motor without load just some milliamps will be enough. Try with a voltage limit of 0.1V to 0.25V.

With the motor resistance set you can also set a current limit on the motor…

Indeed, at 0.2 it turns at least, thanks, I thought it was already completely broken. (In fact, it only turns at values from 0.18 to 0.23) My fault, I always used voltage_limit 1 or 2 before, but it worked well enough at these values.