-
-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
motioncontroller: Store history and add functions for analysis
These are functions for converting acceleration due to gravity to angles in degrees, and some statistical analysis including the mean and variance.
- Loading branch information
1 parent
e0af08d
commit 3683f88
Showing
5 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "utility/Math.h" | ||
|
||
#include <lvgl/src/lv_misc/lv_math.h> | ||
|
||
using namespace Pinetime::Utility; | ||
|
||
#ifndef PINETIME_IS_RECOVERY | ||
|
||
int16_t Pinetime::Utility::Asin(int16_t arg) { | ||
int16_t a = arg < 0 ? -arg : arg; | ||
|
||
int16_t angle = 45; | ||
int16_t low = 0; | ||
int16_t high = 90; | ||
while (low <= high) { | ||
int16_t sinAngle = _lv_trigo_sin(angle); | ||
int16_t sinAngleSub = _lv_trigo_sin(angle - 1); | ||
int16_t sinAngleAdd = _lv_trigo_sin(angle + 1); | ||
|
||
if (a >= sinAngleSub && a <= sinAngleAdd) { | ||
if (a <= (sinAngleSub + sinAngle) / 2) { | ||
angle--; | ||
} else if (a > (sinAngle + sinAngleAdd) / 2) { | ||
angle++; | ||
} | ||
break; | ||
} | ||
|
||
if (a < sinAngle) { | ||
high = angle - 1; | ||
} | ||
|
||
else { | ||
low = angle + 1; | ||
} | ||
|
||
angle = (low + high) / 2; | ||
} | ||
|
||
return arg < 0 ? -angle : angle; | ||
} | ||
|
||
#else | ||
|
||
int16_t Pinetime::Utility::Asin(int16_t /*arg*/) { | ||
return 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace Pinetime { | ||
namespace Utility { | ||
// returns the arcsin of `arg`. asin(-32767) = -90, asin(32767) = 90 | ||
int16_t Asin(int16_t arg); | ||
} | ||
} |