Skip to content

Commit e57e65d

Browse files
Merge pull request #526 from austin-bowen/dev
MagneticSensorAnalog: Fix angle calculation
2 parents e935fe7 + 232d58f commit e57e65d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/sensors/MagneticSensorAnalog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MagneticSensorAnalog::MagneticSensorAnalog(uint8_t _pinAnalog, int _min_raw_coun
99

1010
pinAnalog = _pinAnalog;
1111

12-
cpr = _max_raw_count - _min_raw_count;
12+
cpr = _max_raw_count - _min_raw_count + 1;
1313
min_raw_count = _min_raw_count;
1414
max_raw_count = _max_raw_count;
1515

@@ -33,7 +33,7 @@ void MagneticSensorAnalog::init(){
3333
float MagneticSensorAnalog::getSensorAngle(){
3434
// raw data from the sensor
3535
raw_count = getRawCount();
36-
return ( (float) (raw_count) / (float)cpr) * _2PI;
36+
return ( (float) (raw_count - min_raw_count) / (float)cpr) * _2PI;
3737
}
3838

3939
// function reading the raw counter of the magnetic sensor

0 commit comments

Comments
 (0)