You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/sensors/HallSensor.h
+25-4Lines changed: 25 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,17 @@
9
9
10
10
classHallSensor: publicSensor{
11
11
public:
12
+
13
+
14
+
enumclassHallType : uint8_t
15
+
{
16
+
HALL_120 = 0,
17
+
HALL_60C = 0b001,
18
+
HALL_60B = 0b010,
19
+
HALL_60A = 0b100,
20
+
UNKNOWN = 0b111
21
+
};
22
+
12
23
/**
13
24
HallSensor class constructor
14
25
@param encA HallSensor A pin
@@ -17,7 +28,7 @@ class HallSensor: public Sensor{
17
28
@param pp pole pairs (e.g hoverboard motor has 15pp and small gimbals often have 7pp)
18
29
@param hall_60deg Indicate if the hall sensors are 60 degrees apart electrically (means that they can all be one or off at the same time). In 60deg mode, B needs to lead, so you may need to swap the connections until you find one that works
19
30
*/
20
-
HallSensor(int encA, int encB, int encC, int pp, bool hall_60deg = false);
31
+
HallSensor(int encA, int encB, int encC, int pp, HallType hall_type = HallType::UNKNOWN);
21
32
22
33
/** HallSensor initialise pins */
23
34
voidinit();
@@ -46,7 +57,7 @@ class HallSensor: public Sensor{
46
57
int pinB; //!< HallSensor hardware pin B
47
58
int pinC; //!< HallSensor hardware pin C
48
59
bool use_interrupt; //!< True if interrupts have been attached
49
-
bool hall_60deg; //!< Hall sensors are 60 degrees apart electrically (means that they can all be one or off at the same time)
60
+
HallType hall_type, last_print_type; //!< Connectivity of hall sensor. The type indicates the pin to be swapped. Hall120 has no swapped pin
50
61
51
62
// HallSensor configuration
52
63
Pullup pullup; //!< Configuration parameter internal or external pullups
@@ -60,14 +71,24 @@ class HallSensor: public Sensor{
60
71
/** get current angular velocity (rad/s) */
61
72
floatgetVelocity() override;
62
73
74
+
/**
75
+
* returns 0 if it does need search for absolute zero
76
+
* 0 - magnetic sensor (& encoder with index which is found)
77
+
* 1 - ecoder with index (with index not found yet)
78
+
*/
79
+
intneedsSearch() override;
80
+
81
+
63
82
// whether last step was CW (+1) or CCW (-1).
64
83
Direction direction;
65
84
Direction old_direction;
66
85
67
86
voidattachSectorCallback(void (*onSectorChange)(int a) = nullptr);
68
87
69
-
// the current 3bit state of the hall sensors
70
-
volatileint8_t hall_state;
88
+
//last unique previous states, 0 = recent, used to detect the hall type
89
+
volatileuint8_t previous_states[3];
90
+
// the current 3bit state of the hall sensors, without any line flipped
91
+
volatileint8_t hall_state_raw;
71
92
// the current sector of the sensor. Each sector is 60deg electrical
0 commit comments