Skip to content

Commit 94b9e82

Browse files
committed
more adjustments to ensure electrical angle is good
1 parent fa0c1f7 commit 94b9e82

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/MagneticSensorAnalog.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ float MagneticSensorAnalog::getAngle(){
4444
// if overflow happened track it as full rotation
4545
if(abs(delta) > (0.8*cpr) ) full_rotation_offset += delta > 0 ? -_2PI : _2PI;
4646

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);
4848

4949
// calculate velocity here
5050
long now = _micros();
@@ -72,7 +72,7 @@ float MagneticSensorAnalog::getVelocity(){
7272
float MagneticSensorAnalog::initRelativeZero(){
7373

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

7777
// angle tracking variables
7878
full_rotation_offset = 0;
@@ -82,13 +82,14 @@ float MagneticSensorAnalog::initRelativeZero(){
8282
// return the angle [rad] difference
8383
float MagneticSensorAnalog::initAbsoluteZero(){
8484
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;
8788

8889
// angle tracking variables
8990
full_rotation_offset = 0;
90-
// return offset in radians
91-
return rotation / (float)cpr * _2PI;
91+
92+
return 0;
9293
}
9394
// returns 0 if it has no absolute 0 measurement
9495
// 0 - incremental encoder without index

src/MagneticSensorAnalog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MagneticSensorAnalog: public Sensor{
5959

6060
int read();
6161

62-
word zero_offset; //!< user defined zero offset
62+
int zero_offset; //!< user defined zero offset
6363
/**
6464
* Function getting current angle register value
6565
* it uses angle_register variable

0 commit comments

Comments
 (0)