How to obtain zero_electric_offset and sensor_direction parameters for calling initFOC() method

Hi Experts,

I am trying to write code that starts up a BLDC motor right after power comes on.

This means I need to avoid calling “motor.voltage_sensor_align” and “motor.velocity_index_search” before the motor starts.

So my question maybe is: Can one run these two methods once for a particular motor/controller setup, and then use the determined values as constants in the code.
The class definition of initFOC(): “initFOC( float zero_electric_offset = NOT_SET , Direction sensor_direction = Direction::CW) override;” seems to allow setting these values directly.
But I was not able to find a getter function for these values in the library. But it is a big library…;-).
Any advice or pointer in the right direction would be very much appreciated!

Thanks much in advance!

Hi @bm8000 ,

The value is printed to the serial console if you switch on debugging…

You can get it programmatically from

motor.zero_electric_angle and motor.sensor_direction

Awesome! This worked. Thank you very much!

1 Like

[quote=“runger, post:2, topic:2853”]
I experimented a bit with initFOC() using the determined parameters obtained via SimpleFOCDebug. I encountered a strange issue: First I ran my motor without load using initFOC() without parameters. This yielded the printout next to the top oscilloscope shot. Zero electrical angle was determined to be “4.91” and sensor direction “CW”. This seems to be very consistent. I always get 4.91 with this motor. On the oscilloscope I saw the picture to the left of the printout. I randomly selected one phase (low pass filtered to enhance human perception) and one of the hall sensors, which is o.k. since I only need to see relative changes.
After adding the measured 4.91 and CW values into the initFOC(4.91,CW), I measured the traces below the initial picture. As is obvious the phase shifted by 60 degree relative to the hall sensor signal. When “measuring” the torque of the motor with my hand, I noticed that the motor ran much weaker compared to the initial initFOC() without parameters.
I was able to restore the torque by subtracting 60 degree (1.046 rad) from the 4.91 value. this also restored the original alignment between phase and hall sensor signal.
So my big question is (as usual!..;-): What am I missing? Is there another parameter, like a phase angle offset or something? Why can I not simply insert the 4.91 value into initFOC()?

Thanks much in advance! An my apologies if this is a rookie question (it probably is!..:wink:

Hi @bm8000

Nice oscilloscope traces!

First of all you are confusing me a bit - 4.19 or 4.91 ? The debug message from initFOC() that you show seems to print 4.19 but in your post you talk about 4.91…
Does this account for the problem?

How many pole pairs does your motor have? Your motor should have multiple electrical zero points, one per pole-pair. So when it initialises it should find some different zero points sometimes, depending on the starting position when it calibrates.
Whenever you set the motor.zero_electric_angle to a value close to one of the true electrical zeros, you should get good torque. As you move the zero point away from these angles the torque/performance will get worse.

Well, this is embarrassing!!!..;-). Indeed the typo was the reason for my confusion. After I changed to 4.19 it was all good. My apologies for wasting your time!