Beginner: Init FOC error, current sense not initialized

Hello People,

I have a problem with my FOC current sense initialisation.
The setup:
I have a BLDC Motor called Ri50 from TMotor/CubeMars. It is in a 3D Printed case and has the AS5048B (I2C) chip as a rotary encoder. This I2C connection works as far as I know flawlessly and gives good position data.

The code: (mostly copied from the examples/hardware_specific_exaples/B_G431B_ESC1.ino)

#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(7, 1.42, 96); // pole pair, phase resistance (optional), KV (optional)
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PC13, PA9, PA12, PA10, PB15);

MagneticSensorI2C sensor = MagneticSensorI2C(AS5048_I2C);

LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f/7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);

// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.motion(&motor, cmd); }

void setup() {
    // init sensor
    sensor.init();

    // link sensor to motor
    motor.linkSensor(&sensor);

    driver.voltage_power_supply = 24;

    // init driver
    driver.init();

    // link driver to motor
    motor.linkDriver(&driver);
    
    // set motion control loop to be used
    motor.controller = MotionControlType::velocity;

    motor.linkCurrentSense(&currentSense);

    // aligning voltage [V]
    motor.voltage_sensor_align = 3;
    // index search velocity [rad/s]
    motor.velocity_index_search = 3;

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

    // velocity PI controller parameters
    motor.PID_velocity.P = 0.2;
    motor.PID_velocity.I = 20;
    // default voltage_power_supply
    motor.voltage_limit = 24;
    // 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;

    // angle P controller
    motor.P_angle.P = 20;
    //  maximal velocity of the position control
    motor.velocity_limit = 4;

    // use monitoring with serial 
    Serial.begin(115200);
    // comment out if not needed
    motor.useMonitoring(Serial);
  
    // initialize motor
    motor.init();
    // align encoder and start FOC
    motor.initFOC();

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

    Serial.println(F("Motor ready."));
    Serial.println(F("Set the target angle using serial terminal:"));
    delay(1000);
}

void loop() {
    motor.loopFOC();
    motor.move();
    motor.monitor();
    command.run();
}

After a small hiccup with the “-DHAL_OPAMP_MODULE_ENABLED” flag this compiles without a problem and gives following data via USB Serial connection:

MOT: sensor_direction==CW
MOT: PP check: OK!
MOT: Zero elec. angle: 4.09
MOT: Init FOC error, current sense not initialized
MOT: Init FOC failed.
Motor ready.
Set the target angle using serial terminal:
0.0000  0.0000  0.0728  3.2984
0.0000  0.0000  -0.1169 3.2965
0.0000  0.0000  0.0168  3.2977
0.0000  0.0000  0.0466  3.2981
0.0000  0.0000  -0.0009 3.2977
0.0000  0.0000  0.0853  3.2984
0.0000  0.0000  0.0690  3.2984
0.0000  0.0000  0.0431  3.2981
0.0000  0.0000  0.0490  3.2981
0.0000  0.0000  0.0341  3.2981
0.0000  0.0000  0.0346  3.2981
0.0000  0.0000  0.0719  3.2984
...

As you can see everything seems to work except the current sense initialisation.
Do you have any Idea why this would not work ? Did I miss something or is my Code wrong ?
I would appreciate your input and hope you have a nice day :slight_smile:

You missed this I think

Thank you so much I totally missed that and also the currentSense.linkDriver(&driver) even though I went through it at least 8 times ^^.
Hope you have great day and again thank you :slight_smile: