Description
hello there,
I'll briefly explain the problem and how you can fix it.
[Problem]
If more than one HallSensor is used, all modes that use getVelocity()
from HallSensor go crazy.
You can check it if the test from the examples/utils/sensor_test/hall_sensors folder is used and at least two HallSensors are initialized. If you turn the motors in the opposite direction of rotation (from the sensors point of view), you will very often get a value of zero in the sensor.getVelocity() Print.
[Reason]
in a line of the HallSensor.cpp file the variable old_direction
is created as static
. This passes the same value to all HallSensor instances.
[FIX]
You can fix the problem easily by deleting line 56
Arduino-FOC/src/sensors/HallSensor.cpp
Lines 55 to 57 in f9e9a2d
static Direction old_direction;
from the function void HallSensor::updateState()
in the src/sensors/HallSensor.cpp file.
After this adding the following line in HallSensor.h to the class HallSensor in file src/sensors/HallSensor.h:
Direction old_direction;
add it to line 65 for example
Arduino-FOC/src/sensors/HallSensor.h
Lines 63 to 65 in f9e9a2d
now the variable old_direction
is used for its own instance.