Skip to content

Commit a052214

Browse files
committed
FEAT enabled Analog sensor absolute positioning
1 parent 5a03bab commit a052214

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/MagneticSensorAnalog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ float MagneticSensorAnalog::getVelocity(){
7272
float MagneticSensorAnalog::initRelativeZero(){
7373

7474
float angle_offset = -getAngle();
75-
zero_offset = getRawCount();
75+
zero_offset = natural_direction * getRawCount();
7676

7777
// angle tracking variables
7878
full_rotation_offset = 0;
@@ -81,14 +81,14 @@ float MagneticSensorAnalog::initRelativeZero(){
8181
// set absolute zero angle as zero angle
8282
// return the angle [rad] difference
8383
float MagneticSensorAnalog::initAbsoluteZero(){
84-
85-
// don't reset zero offset, making adjustments in sensor
86-
// zero_offset = 0;
84+
float rotation = -(int)zero_offset;
85+
// init absolute zero
86+
zero_offset = 0;
8787

8888
// angle tracking variables
8989
full_rotation_offset = 0;
90-
91-
return 0;
90+
// return offset in radians
91+
return rotation / (float)cpr * _2PI;
9292
}
9393
// returns 0 if it has no absolute 0 measurement
9494
// 0 - incremental encoder without index

0 commit comments

Comments
 (0)