calculate
Dependencies: mbed X_NUCLEO_IKS01A3 Mahony_Algorithm
CalculateData.cpp@0:313fbc3a198a, 2020-04-01 (annotated)
- Committer:
- zollecy1
- Date:
- Wed Apr 01 16:47:06 2020 +0000
- Revision:
- 0:313fbc3a198a
- Child:
- 1:48e219526d0f
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zollecy1 | 0:313fbc3a198a | 1 | /** |
zollecy1 | 0:313fbc3a198a | 2 | |**********************************************************************; |
zollecy1 | 0:313fbc3a198a | 3 | * Project : Projektarbeit Systemtechnik PES4 |
zollecy1 | 0:313fbc3a198a | 4 | * |
zollecy1 | 0:313fbc3a198a | 5 | * Program name : Beispiel |
zollecy1 | 0:313fbc3a198a | 6 | * |
zollecy1 | 0:313fbc3a198a | 7 | * Author : PES4 Team1 |
zollecy1 | 0:313fbc3a198a | 8 | * |
zollecy1 | 0:313fbc3a198a | 9 | * Team : **Team 1** |
zollecy1 | 0:313fbc3a198a | 10 | * Fabio Bernard |
zollecy1 | 0:313fbc3a198a | 11 | * Lukas Egli |
zollecy1 | 0:313fbc3a198a | 12 | * Matthias Ott |
zollecy1 | 0:313fbc3a198a | 13 | * Pascal Novacki |
zollecy1 | 0:313fbc3a198a | 14 | * Robin Wanner |
zollecy1 | 0:313fbc3a198a | 15 | * Vincent Vescoli |
zollecy1 | 0:313fbc3a198a | 16 | * Cyrill Zoller |
zollecy1 | 0:313fbc3a198a | 17 | * |
zollecy1 | 0:313fbc3a198a | 18 | * Date created : 20.02.2020 |
zollecy1 | 0:313fbc3a198a | 19 | * |
zollecy1 | 0:313fbc3a198a | 20 | * Purpose : Beispiel |
zollecy1 | 0:313fbc3a198a | 21 | * |
zollecy1 | 0:313fbc3a198a | 22 | |**********************************************************************; |
zollecy1 | 0:313fbc3a198a | 23 | **/ |
zollecy1 | 0:313fbc3a198a | 24 | |
zollecy1 | 0:313fbc3a198a | 25 | #include "CalculateData.h" |
zollecy1 | 0:313fbc3a198a | 26 | #include "mbed.h" |
zollecy1 | 0:313fbc3a198a | 27 | #include "XNucleoIKS01A3.h" |
zollecy1 | 0:313fbc3a198a | 28 | |
zollecy1 | 0:313fbc3a198a | 29 | using namespace std; |
zollecy1 | 0:313fbc3a198a | 30 | |
zollecy1 | 0:313fbc3a198a | 31 | const float CalculateData::PERIOD = 0.01f; //Periode von 10 ms |
zollecy1 | 0:313fbc3a198a | 32 | |
zollecy1 | 0:313fbc3a198a | 33 | |
zollecy1 | 0:313fbc3a198a | 34 | static XNucleoIKS01A3 *mems_expansion_board; |
zollecy1 | 0:313fbc3a198a | 35 | static LIS2MDLSensor *magnetometer; |
zollecy1 | 0:313fbc3a198a | 36 | static HTS221Sensor *hum_temp; |
zollecy1 | 0:313fbc3a198a | 37 | static LPS22HHSensor *press_temp; |
zollecy1 | 0:313fbc3a198a | 38 | static LSM6DSOSensor *acc_gyro; |
zollecy1 | 0:313fbc3a198a | 39 | static LIS2DW12Sensor *accelerometer; |
zollecy1 | 0:313fbc3a198a | 40 | static STTS751Sensor *temp; |
zollecy1 | 0:313fbc3a198a | 41 | float value1, value2; |
zollecy1 | 0:313fbc3a198a | 42 | int32_t axes[3]; |
zollecy1 | 0:313fbc3a198a | 43 | |
zollecy1 | 0:313fbc3a198a | 44 | |
zollecy1 | 0:313fbc3a198a | 45 | |
zollecy1 | 0:313fbc3a198a | 46 | CalculateData::CalculateData(PinName p0, PinName p1, PinName p2, PinName p3, |
zollecy1 | 0:313fbc3a198a | 47 | PinName p4, PinName p5, PinName p6){ |
zollecy1 | 0:313fbc3a198a | 48 | |
zollecy1 | 0:313fbc3a198a | 49 | /* Instantiate the expansion board */ |
zollecy1 | 0:313fbc3a198a | 50 | mems_expansion_board = XNucleoIKS01A3::instance(p0, p1, p2, p3, p4, p5, p6); |
zollecy1 | 0:313fbc3a198a | 51 | |
zollecy1 | 0:313fbc3a198a | 52 | /* Retrieve the composing elements of the expansion board */ |
zollecy1 | 0:313fbc3a198a | 53 | magnetometer = mems_expansion_board->magnetometer; |
zollecy1 | 0:313fbc3a198a | 54 | hum_temp = mems_expansion_board->ht_sensor; |
zollecy1 | 0:313fbc3a198a | 55 | press_temp = mems_expansion_board->pt_sensor; |
zollecy1 | 0:313fbc3a198a | 56 | acc_gyro = mems_expansion_board->acc_gyro; |
zollecy1 | 0:313fbc3a198a | 57 | accelerometer = mems_expansion_board->accelerometer; |
zollecy1 | 0:313fbc3a198a | 58 | temp = mems_expansion_board->t_sensor; |
zollecy1 | 0:313fbc3a198a | 59 | |
zollecy1 | 0:313fbc3a198a | 60 | /* Enable all sensors */ |
zollecy1 | 0:313fbc3a198a | 61 | hum_temp->enable(); |
zollecy1 | 0:313fbc3a198a | 62 | press_temp->enable(); |
zollecy1 | 0:313fbc3a198a | 63 | temp->enable(); |
zollecy1 | 0:313fbc3a198a | 64 | magnetometer->enable(); |
zollecy1 | 0:313fbc3a198a | 65 | accelerometer->enable_x(); |
zollecy1 | 0:313fbc3a198a | 66 | acc_gyro->enable_x(); |
zollecy1 | 0:313fbc3a198a | 67 | acc_gyro->enable_g(); |
zollecy1 | 0:313fbc3a198a | 68 | |
zollecy1 | 0:313fbc3a198a | 69 | /*while(1){ |
zollecy1 | 0:313fbc3a198a | 70 | printf("\r\n"); |
zollecy1 | 0:313fbc3a198a | 71 | |
zollecy1 | 0:313fbc3a198a | 72 | hum_temp->get_temperature(&value1); |
zollecy1 | 0:313fbc3a198a | 73 | hum_temp->get_humidity(&value2); |
zollecy1 | 0:313fbc3a198a | 74 | printf("HTS221: [temp] %4.2f C, [hum] %4.2f%%\r\n", value1, value2); |
zollecy1 | 0:313fbc3a198a | 75 | |
zollecy1 | 0:313fbc3a198a | 76 | press_temp->get_temperature(&value1); |
zollecy1 | 0:313fbc3a198a | 77 | press_temp->get_pressure(&value2); |
zollecy1 | 0:313fbc3a198a | 78 | printf("LPS22HH: [temp] %4.2f C, [press] %6.2f mbar\r\n", value1, value2); |
zollecy1 | 0:313fbc3a198a | 79 | |
zollecy1 | 0:313fbc3a198a | 80 | temp->get_temperature(&value1); |
zollecy1 | 0:313fbc3a198a | 81 | printf("STTS751: [temp] %4.2f C\r\n", value1); |
zollecy1 | 0:313fbc3a198a | 82 | |
zollecy1 | 0:313fbc3a198a | 83 | printf("---\r\n"); |
zollecy1 | 0:313fbc3a198a | 84 | |
zollecy1 | 0:313fbc3a198a | 85 | magnetometer->get_m_axes(axes); |
zollecy1 | 0:313fbc3a198a | 86 | printf("LIS2MDL [mag/mgauss]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 87 | |
zollecy1 | 0:313fbc3a198a | 88 | accelerometer->get_x_axes(axes); |
zollecy1 | 0:313fbc3a198a | 89 | printf("LIS2DW12 [acc/mg]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 90 | |
zollecy1 | 0:313fbc3a198a | 91 | acc_gyro->get_x_axes(axes); |
zollecy1 | 0:313fbc3a198a | 92 | printf("LSM6DSO [acc/mg]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 93 | |
zollecy1 | 0:313fbc3a198a | 94 | acc_gyro->get_g_axes(axes); |
zollecy1 | 0:313fbc3a198a | 95 | printf("LSM6DSO [gyro/mdps]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 96 | }*/ |
zollecy1 | 0:313fbc3a198a | 97 | } |
zollecy1 | 0:313fbc3a198a | 98 | |
zollecy1 | 0:313fbc3a198a | 99 | |
zollecy1 | 0:313fbc3a198a | 100 | CalculateData::~CalculateData() { |
zollecy1 | 0:313fbc3a198a | 101 | |
zollecy1 | 0:313fbc3a198a | 102 | } |
zollecy1 | 0:313fbc3a198a | 103 | |
zollecy1 | 0:313fbc3a198a | 104 | |
zollecy1 | 0:313fbc3a198a | 105 | void CalculateData::enable(){ |
zollecy1 | 0:313fbc3a198a | 106 | //Starten des periodischen Task |
zollecy1 | 0:313fbc3a198a | 107 | ticker.attach(callback(this, &CalculateData::run), PERIOD); |
zollecy1 | 0:313fbc3a198a | 108 | |
zollecy1 | 0:313fbc3a198a | 109 | |
zollecy1 | 0:313fbc3a198a | 110 | } |
zollecy1 | 0:313fbc3a198a | 111 | |
zollecy1 | 0:313fbc3a198a | 112 | void CalculateData::disable(){ |
zollecy1 | 0:313fbc3a198a | 113 | ticker.detach(); // Stoppt den periodischen Task |
zollecy1 | 0:313fbc3a198a | 114 | } |
zollecy1 | 0:313fbc3a198a | 115 | |
zollecy1 | 0:313fbc3a198a | 116 | void CalculateData::getData(){ |
zollecy1 | 0:313fbc3a198a | 117 | printf("\r\n"); |
zollecy1 | 0:313fbc3a198a | 118 | |
zollecy1 | 0:313fbc3a198a | 119 | hum_temp->get_temperature(&value1); |
zollecy1 | 0:313fbc3a198a | 120 | hum_temp->get_humidity(&value2); |
zollecy1 | 0:313fbc3a198a | 121 | printf("HTS221: [temp] %4.2f C, [hum] %4.2f%%\r\n", value1, value2); |
zollecy1 | 0:313fbc3a198a | 122 | |
zollecy1 | 0:313fbc3a198a | 123 | press_temp->get_temperature(&value1); |
zollecy1 | 0:313fbc3a198a | 124 | press_temp->get_pressure(&value2); |
zollecy1 | 0:313fbc3a198a | 125 | printf("LPS22HH: [temp] %4.2f C, [press] %6.2f mbar\r\n", value1, value2); |
zollecy1 | 0:313fbc3a198a | 126 | |
zollecy1 | 0:313fbc3a198a | 127 | temp->get_temperature(&value1); |
zollecy1 | 0:313fbc3a198a | 128 | printf("STTS751: [temp] %4.2f C\r\n", value1); |
zollecy1 | 0:313fbc3a198a | 129 | |
zollecy1 | 0:313fbc3a198a | 130 | printf("---\r\n"); |
zollecy1 | 0:313fbc3a198a | 131 | |
zollecy1 | 0:313fbc3a198a | 132 | magnetometer->get_m_axes(axes); |
zollecy1 | 0:313fbc3a198a | 133 | printf("LIS2MDL [mag/mgauss]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 134 | |
zollecy1 | 0:313fbc3a198a | 135 | accelerometer->get_x_axes(axes); |
zollecy1 | 0:313fbc3a198a | 136 | printf("LIS2DW12 [acc/mg]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 137 | |
zollecy1 | 0:313fbc3a198a | 138 | acc_gyro->get_x_axes(axes); |
zollecy1 | 0:313fbc3a198a | 139 | printf("LSM6DSO [acc/mg]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 140 | |
zollecy1 | 0:313fbc3a198a | 141 | acc_gyro->get_g_axes(axes); |
zollecy1 | 0:313fbc3a198a | 142 | printf("LSM6DSO [gyro/mdps]: %6d, %6d, %6d\r\n", axes[0], axes[1], axes[2]); |
zollecy1 | 0:313fbc3a198a | 143 | |
zollecy1 | 0:313fbc3a198a | 144 | } |
zollecy1 | 0:313fbc3a198a | 145 | |
zollecy1 | 0:313fbc3a198a | 146 | |
zollecy1 | 0:313fbc3a198a | 147 | //Periodischer Task |
zollecy1 | 0:313fbc3a198a | 148 | void CalculateData::run() { |
zollecy1 | 0:313fbc3a198a | 149 | |
zollecy1 | 0:313fbc3a198a | 150 | getData(); |
zollecy1 | 0:313fbc3a198a | 151 | |
zollecy1 | 0:313fbc3a198a | 152 | } |
zollecy1 | 0:313fbc3a198a | 153 | |
zollecy1 | 0:313fbc3a198a | 154 | |
zollecy1 | 0:313fbc3a198a | 155 | |
zollecy1 | 0:313fbc3a198a | 156 | |
zollecy1 | 0:313fbc3a198a | 157 | |
zollecy1 | 0:313fbc3a198a | 158 | |
zollecy1 | 0:313fbc3a198a | 159 | |
zollecy1 | 0:313fbc3a198a | 160 | |
zollecy1 | 0:313fbc3a198a | 161 | |
zollecy1 | 0:313fbc3a198a | 162 | |
zollecy1 | 0:313fbc3a198a | 163 |