@@ -44,7 +44,7 @@ float MagneticSensorAnalog::getAngle(){
44
44
// if overflow happened track it as full rotation
45
45
if (abs (delta) > (0.8 *cpr) ) full_rotation_offset += delta > 0 ? -_2PI : _2PI;
46
46
47
- float angle = natural_direction * (full_rotation_offset + ( (float ) (raw_count - min_raw_count ) / (float )cpr) * _2PI);
47
+ float angle = natural_direction * (full_rotation_offset + ( (float ) (raw_count - zero_offset ) / (float )cpr) * _2PI);
48
48
49
49
// calculate velocity here
50
50
long now = _micros ();
@@ -72,7 +72,7 @@ float MagneticSensorAnalog::getVelocity(){
72
72
float MagneticSensorAnalog::initRelativeZero (){
73
73
74
74
float angle_offset = -getAngle ();
75
- zero_offset = 0 ;
75
+ zero_offset = getRawCount () ;
76
76
77
77
// angle tracking variables
78
78
full_rotation_offset = 0 ;
@@ -82,13 +82,14 @@ float MagneticSensorAnalog::initRelativeZero(){
82
82
// return the angle [rad] difference
83
83
float MagneticSensorAnalog::initAbsoluteZero (){
84
84
float rotation = -(int )zero_offset;
85
- // init absolute zero
86
- zero_offset = 0 ;
85
+
86
+ // don't reset zero offset, making adjustments in sensor
87
+ // zero_offset = 0;
87
88
88
89
// angle tracking variables
89
90
full_rotation_offset = 0 ;
90
- // return offset in radians
91
- return rotation / ( float )cpr * _2PI ;
91
+
92
+ return 0 ;
92
93
}
93
94
// returns 0 if it has no absolute 0 measurement
94
95
// 0 - incremental encoder without index
0 commit comments