Order CurrentSense

Hello all,

during implementing, I noticed that there are different orders for initializing current sense in the documentation. In the inline current sense documentation, the order is:

void loop(){

// driver init
driver.init();
// link the driver to the current sense
current_sense.linkDriver(&driver);

// motor init
motor.init();

// init current sense
current_sense.init();
// link the current sense to the motor
motor.linkCurrentSense(&current_sense);

// start the FOC
motor.initFOC();
}

However, in the foc current mode description, the order is:

void setup() {

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

// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link driver
motor.linkDriver(&driver);

// current sense init hardware
current_sense.init();
// link the current sense to the motor
motor.linkCurrentSense(&current_sense);

// set torque mode:
motor.torque_controller = TorqueControlType::foc_current;
// set motion control loop to be used
motor.controller = MotionControlType::torque;

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


}

As you can see, in the second example, current_sense.init() is after motor.init() and current_sense.linkDriver(&driver) is not called.

Can someone explain why there is a difference? And which one is correct? Or does the order and current_sense.linkDriver(&driver) does not have any effect?

Thanks,
Alex

The first is correct, you have to link the current sense and the driver…

The second is an oder version of the code.

Thank you for finding this, we will correct it for the next release of the documentation.