Simplefoc 2.1.1 vs 2.2.3 differences question following up

Hi buddy,
this is following up thread of Simplefoc 2.1.1 vs 2.2.3 differences

I made a self-made board to program Simplefoc 2.1.1, everything is good. When I used 2.2.3 with the suggested log output, I still met something wrong, very high-power consumption of the driver board and can’t control by UART CMD. I can get below log.
(I add below line
// link current sense and driver
current_sense.linkDriver(&driver) in main.cpp with simplefoc v2.2.3 )

Here are my driver pins

Here is my lib configuration log.

Do you have some comments?

Hi,

In this debug output, your pole pair check is failing - estimated PP == 1024 - that’s much too high, you motor has 7PP? This indicates the motor did not move or did not move much, or the sensor is having a problem.

Which sensor are you using?

Could you share your platformio.ini ?

Hi Runger,

I am using AS5047P, 4 line spi interface.
Yes, of course. shown below.



As I said, using simplefoc-2-1-1, everything is good.
By the way, during my debug work with simplefoc-2-1-1, very few times I also met estimated PP != 7, and motor is not run correctly, angle output is not correct…(this is cause by I set motor.phase_resistance = 0.6; // [Ohm], actually it should be 2.6 ).

This actually all looks ok… hmmm… you’re initialising the sensor with 10 bit precision, but actually it is 14. Maybe that’s the issue?

Could you also try with the 2.3.0 version of the library? There have been some bug-fixes.

Could you also try initialising the sensor like this:

MagneticSensorSPIConfig_s myAS5047SPIConfig = {
  .spi_mode = SPI_MODE1,
  .clock_speed = 1000000,
  .bit_resolution = 14,
  .angle_register = 0x3FFF,
  .data_start_bit = 13,
  .command_rw_bit = 14,
  .command_parity_bit = 15
};
MagneticSensorSPI sensor = MagneticSensorSPI(myAS5047SPIConfig, PB15);

Hi Runger,

I tried 2.3.0, and modified AS5047P’s resolution
// magnetic sensor instance - SPI
MagneticSensorSPI sensor = MagneticSensorSPI(PB15, 14);

I still have problems with v2.3.0, sometime PP check fails, power consumption is very high.

sometime PP checks ok, but the motor is not running to the targeted angle (encoder data is also not correct), power consumption is high.

Here is the issued current and INA240A2 PIN 8 output (inline current output looks good), but total driver board power consumption is high, and motor is hot.

Below is v2.1.1 performance with current foc control.

Here is my v2.3.0 code, I am wondering, is there something motor parameter configuration which is not correct?

#include <SimpleFOC.h>
#include <Arduino.h>

// Motor instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PB4, PB5, PB0, PB12);

// magnetic sensor instance - SPI
MagneticSensorSPI sensor = MagneticSensorSPI(PB15, 14);

// current sensor
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A1);

// angle,velocity set point variable
float target_velocity = 0;
float target_angle = 0;

// instantiate the commander
Commander command = Commander(Serial);

void doTarget(char *cmd)
{ command.scalar(&target_velocity, cmd); }

void doMotor(char* cmd)
{ command.motor(&motor, cmd); }

void setup()
{

// use monitoring with serial
Serial.begin(115200);
SimpleFOCDebug::enable(&Serial);
_delay(100);
SIMPLEFOC_DEBUG("Hello world!");

// initialize encoder sensor hardware
sensor.init();
// encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&sensor);

driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
// link current sense and the driver  2.2.0 above required
current_sense.linkDriver(&driver);

// aligning voltage [V]
motor.voltage_sensor_align = 1.5;
// if you are not using aligning voltage, you can set current limitation
motor.phase_resistance = 2.6; // [Ohm]

// index search velocity [rad/s]
// motor.velocity_index_search = 3;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

// set motion control loop to be used
motor.torque_controller = TorqueControlType::voltage;
motor.controller = MotionControlType::angle;

// motor.torque_controller  = TorqueControlType::voltage;
// motor.controller = MotionControlType::torque;

// set the inital target value
// motor.target = 0.5;

// default voltage_power_supply
// internal res is 0.35 ou maximum current is 2A
// maximum volts is 0.7
// this is used for open loop
// motor.voltage_limit = 0.7;

//  maximal velocity of the position control
// motor.velocity_limit = 20;
motor.target = 13; //  

// contoller configuration
// default parameters in defaults.h

// velocity PI controller parameters
motor.PID_velocity.P = 0.01;
motor.PID_velocity.I = 0.003;
// motor.PID_velocity.D = 0.001;
// 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.01;
motor.voltage_limit = 1.5;
motor.current_limit = 0.8; // Amps 

// angle P controller
motor.P_angle.P = 23;

motor.P_angle.D = 0.01;

// comment out if not needed
motor.useMonitoring(Serial);
motor.monitor_downsample = 1; // setting sample rate, can up to 100+
motor.monitor_variables = _MON_TARGET  | _MON_CURR_Q | _MON_CURR_D | _MON_VEL | _MON_ANGLE; 
//motor.monitor_downsample = 100; // set downsampling can be even more > 100
//motor.monitor_variables = _MON_CURR_Q | _MON_CURR_D; // set monitoring of d and q currents

// initialise magnetic sensor hardware
current_sense.init();
// link the motor to the sensor
motor.linkCurrentSense(&current_sense);
// invert phase b gain
current_sense.gain_b *=-1;
// skip alignment
// current_sense.skip_align = true;

// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();

// motor.target = 13;

// 订阅电机至commander
command.add('M', doMotor,"motor");

// add target command T
// command.add('T', doTarget, "target_velocity");
Serial.println("Motor ready.");
Serial.println("Set the target using serial terminal:");
_delay(300);

}

void loop()
{
// main FOC algorithm function
// the faster you run this function the better
// Arduino UNO loop ~1kHz
// Bluepill loop ~10kHz
motor.loopFOC();

// Motion control function
// velocity, position or voltage (defined in motor.controller)
// this function can be run at much lower frequency than loopFOC() function
// You can also use motor.move() and set the motor.target in the code
// motor.move(target_velocity);
motor.move();
// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
motor.monitor();

// user communication
command.run();

// test current
//PhaseCurrent_s currents = current_sense.getPhaseCurrents();
//float current_magnitude = current_sense.getDCCurrent();

//Serial.print(currents.a * 1000); // milli Amps
//Serial.print("\t");
//Serial.print(currents.b * 1000); // milli Amps
//Serial.print("\t");
//Serial.print(currents.c * 1000); // milli Amps
//Serial.print("\t");
//Serial.println(current_magnitude * 1000); // milli Amps

}

Hello Runger,

This looks stranges, Any comments or suggestions ?

Hey, is this one also related to the broken INA chip, or is it a different issue?

Hey Runger,

The above description is with new INA chip. already replaced the broken INA chip.

Hello ? Any further comments ?

I have found a bug to do with the initialization of the phase inductance…

I’ve fixed it on the dev branch. It’s perhaps an explanation for the difference, I’m not sure…

Hi Runger,

That’s a good news : )
Feel free to let me know when you are fixed the bug, I will help to verify on my HW : )

Hi @kuqn ,

Yes, it is already on the dev branch:

To use it you would have to git clone the dev branch from GitHub, and use the cloned version in ArduinoIDE/PlatformIO. There are instructions online for doing it.

Otherwise, if you prefer to wait it will be part of the next release of SimpleFOC.