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”]
motor.sensor_direction
[/quote]:
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!

Hey guys, following up w/a related question. I’ve got a 12n14p pmsm motor w/three Halls, and have noticed via oscilloscope that, when I back-drive the motor w/a DC motor + coupling, the back-emf crossovers don’t “quite” line up w/the Hall crossover. Turns out (according to the manufacturer) that the Halls are mounted in the center of the stator teeth. For this config, I’m almost certain they should be mounted between them.

This has created the offset in zero-crossing line-up, which ends up producing approx. 12° difference in electric angle. If I read the FOCMotor.cpp lines right, this value should be put in zero_electric_angle as the difference btwn the sensor and motor electric angles. However, this begs the question; what’s the point of then using the sensor_offset value? Does this parameter not apply when Hall sensors are used, since all three are spaced around the shaft (in the middle of three stator teeth)? I’ll follow up w/oscilloscope pics tomorrow, but any advice is appreciated. Thanks all!

Hey,

The sensor_offset exists to allow you to make the target values meaningful in your application.

The reason it exists is to allow you to make the “zero target” line up to a point you choose, which can be important in some applications like robot arms or gantries. Then the motor will report the shaft angle taking the sensor offset into account, and accept target values (in position mode) that are adjusted by the sensor offset internally. But you could also do this externally to the SimpleFOC code, so it’s just a convenience function.

It doesn’t have an impact on the electrical angle and zero electrical angle. The electrical angle is computed based on the sensor.getMechanicalAngle() with no offset applied.