Preston Ernst
/
mirror_actuator_VT
-data logging revision
Lib_Misc/Unwrapper.cpp@2:92c25cb669f4, 2021-08-24 (annotated)
- Committer:
- ernstpre
- Date:
- Tue Aug 24 08:51:13 2021 +0000
- Revision:
- 2:92c25cb669f4
- Parent:
- 0:d2e117716219
Publish Commit 24/8/21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 0:d2e117716219 | 1 | /* |
altb2 | 0:d2e117716219 | 2 | */ |
altb2 | 0:d2e117716219 | 3 | |
altb2 | 0:d2e117716219 | 4 | #include "Unwrapper.h" |
altb2 | 0:d2e117716219 | 5 | #define pi 3.141592653589793 |
altb2 | 0:d2e117716219 | 6 | using namespace std; |
altb2 | 0:d2e117716219 | 7 | |
altb2 | 0:d2e117716219 | 8 | Unwrapper::Unwrapper(double i2r) |
altb2 | 0:d2e117716219 | 9 | { |
altb2 | 0:d2e117716219 | 10 | inc2rad = i2r; |
altb2 | 0:d2e117716219 | 11 | last_value = 0; |
altb2 | 0:d2e117716219 | 12 | } |
altb2 | 0:d2e117716219 | 13 | |
altb2 | 0:d2e117716219 | 14 | Unwrapper::~Unwrapper() {} |
altb2 | 0:d2e117716219 | 15 | |
altb2 | 0:d2e117716219 | 16 | void Unwrapper::reset(void) |
altb2 | 0:d2e117716219 | 17 | { |
altb2 | 0:d2e117716219 | 18 | last_value = 0; |
altb2 | 0:d2e117716219 | 19 | } |
altb2 | 0:d2e117716219 | 20 | |
altb2 | 0:d2e117716219 | 21 | double Unwrapper::doStep(short inc) |
altb2 | 0:d2e117716219 | 22 | { |
altb2 | 0:d2e117716219 | 23 | long temp = inc; |
altb2 | 0:d2e117716219 | 24 | if((temp - last_value) > 32000) |
altb2 | 0:d2e117716219 | 25 | temp -= 0xFFFF; |
altb2 | 0:d2e117716219 | 26 | else if((temp - last_value) < -32000) |
altb2 | 0:d2e117716219 | 27 | temp += 0xFFFF; |
altb2 | 0:d2e117716219 | 28 | last_value = temp; |
altb2 | 0:d2e117716219 | 29 | return (temp*inc2rad); |
altb2 | 0:d2e117716219 | 30 | } |