Mercurial > public > ostc4
comparison Discovery/Src/data_central.c @ 539:d784f281833a
Added inertia simulation for compass heading:
In previous version calculated compass values were directly used for visualization of the compass. This causes a fast changing (jumping) of values. With the inertia introduction the compass behalfs more like an analog compass. The final value is reached slowly and the displayed values are more stable.
For configuration a new menu item has been added to the compass menu allowing to switch inertia off (default), small and large inertia simulation
author | Ideenmodellierer |
---|---|
date | Sat, 10 Oct 2020 16:59:18 +0200 |
parents | 95928ef3986f |
children | 1b995079c045 |
comparison
equal
deleted
inserted
replaced
538:b1eee27cd02b | 539:d784f281833a |
---|---|
59 ****************************************************************************** | 59 ****************************************************************************** |
60 */ | 60 */ |
61 | 61 |
62 /* Includes ------------------------------------------------------------------*/ | 62 /* Includes ------------------------------------------------------------------*/ |
63 #include <string.h> | 63 #include <string.h> |
64 #include <math.h> | |
64 #include "data_central.h" | 65 #include "data_central.h" |
65 #include "calc_crush.h" | 66 #include "calc_crush.h" |
66 #include "decom.h" | 67 #include "decom.h" |
67 #include "stm32f4xx_hal.h" | 68 #include "stm32f4xx_hal.h" |
68 #include "settings.h" | 69 #include "settings.h" |
100 .is_data_from_RTE_CPU = 0, | 101 .is_data_from_RTE_CPU = 0, |
101 }; | 102 }; |
102 | 103 |
103 const SDiveState *stateUsed = &stateReal; | 104 const SDiveState *stateUsed = &stateReal; |
104 SDiveState *stateUsedWrite = &stateReal; | 105 SDiveState *stateUsedWrite = &stateReal; |
106 | |
107 | |
108 #define COMPASS_FRACTION (4.0f) /* delay till value changes to new actual */ | |
109 | |
110 static float compass_compensated = 0; | |
105 | 111 |
106 void set_stateUsedToReal(void) | 112 void set_stateUsedToReal(void) |
107 { | 113 { |
108 stateUsed = stateUsedWrite = &stateReal; | 114 stateUsed = stateUsedWrite = &stateReal; |
109 } | 115 } |
768 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) | 774 else if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.1f)) |
769 return true; | 775 return true; |
770 else | 776 else |
771 return false; | 777 return false; |
772 } | 778 } |
779 | |
780 void compass_Inertia(float newHeading) | |
781 { | |
782 float newTarget = newHeading; | |
783 | |
784 if(settingsGetPointer()->compassInertia == 0) | |
785 { | |
786 compass_compensated = newHeading; | |
787 } | |
788 else | |
789 { | |
790 if((compass_compensated > 270.0) && (newHeading < 90.0)) /* transition passing 0 clockwise */ | |
791 { | |
792 newTarget = newHeading + 360.0; | |
793 } | |
794 | |
795 if((compass_compensated < 90.0) && (newHeading > 270.0)) /* transition passing 0 counter clockwise */ | |
796 { | |
797 newTarget = newHeading - 360.0; | |
798 } | |
799 | |
800 compass_compensated = compass_compensated + ((newTarget - compass_compensated) / (COMPASS_FRACTION * (settingsGetPointer()->compassInertia))); | |
801 if(compass_compensated < 0.0) | |
802 { | |
803 compass_compensated += 360.0; | |
804 } | |
805 if(compass_compensated >= 360.0) | |
806 { | |
807 compass_compensated -= 360.0; | |
808 } | |
809 } | |
810 } | |
811 | |
812 float compass_getCompensated() | |
813 { | |
814 return compass_compensated; | |
815 } | |
816 |