2022-09-27 11:06:11 +02:00
|
|
|
#include "SusConverter.h"
|
2022-10-06 15:38:23 +02:00
|
|
|
|
2023-02-23 13:37:12 +01:00
|
|
|
#include <math.h>
|
2023-02-24 18:10:43 +01:00
|
|
|
|
2023-06-19 16:33:04 +02:00
|
|
|
uint64_t SusConverter::checkSunSensorData(const uint16_t susChannel[6]) {
|
2023-06-16 21:16:39 +02:00
|
|
|
if (susChannel[0] <= SUS_CHANNEL_VALUE_LOW || susChannel[0] > SUS_CHANNEL_VALUE_HIGH ||
|
2022-10-10 16:02:57 +02:00
|
|
|
susChannel[0] > susChannel[GNDREF]) {
|
2023-06-19 16:33:04 +02:00
|
|
|
return 0;
|
2022-10-06 15:38:23 +02:00
|
|
|
}
|
2023-06-16 21:16:39 +02:00
|
|
|
if (susChannel[1] <= SUS_CHANNEL_VALUE_LOW || susChannel[1] > SUS_CHANNEL_VALUE_HIGH ||
|
2022-10-10 16:02:57 +02:00
|
|
|
susChannel[1] > susChannel[GNDREF]) {
|
2023-06-19 16:33:04 +02:00
|
|
|
return 0;
|
2022-10-06 15:38:23 +02:00
|
|
|
};
|
2023-06-16 21:16:39 +02:00
|
|
|
if (susChannel[2] <= SUS_CHANNEL_VALUE_LOW || susChannel[2] > SUS_CHANNEL_VALUE_HIGH ||
|
2022-10-10 16:02:57 +02:00
|
|
|
susChannel[2] > susChannel[GNDREF]) {
|
2023-06-19 16:33:04 +02:00
|
|
|
return 0;
|
2022-10-06 15:38:23 +02:00
|
|
|
};
|
2023-06-16 21:16:39 +02:00
|
|
|
if (susChannel[3] <= SUS_CHANNEL_VALUE_LOW || susChannel[3] > SUS_CHANNEL_VALUE_HIGH ||
|
2022-10-10 16:02:57 +02:00
|
|
|
susChannel[3] > susChannel[GNDREF]) {
|
2023-06-19 16:33:04 +02:00
|
|
|
return 0;
|
2022-09-23 09:56:32 +02:00
|
|
|
};
|
|
|
|
|
2023-06-19 16:33:04 +02:00
|
|
|
uint64_t susChannelValueSum =
|
2022-10-10 16:02:57 +02:00
|
|
|
4 * susChannel[GNDREF] - (susChannel[0] + susChannel[1] + susChannel[2] + susChannel[3]);
|
2023-06-19 16:33:04 +02:00
|
|
|
if (susChannelValueSum < SUS_ALBEDO_CHECK) {
|
|
|
|
return 0;
|
2022-09-23 09:56:32 +02:00
|
|
|
};
|
2023-06-19 16:33:04 +02:00
|
|
|
return susChannelValueSum;
|
2022-09-23 09:56:32 +02:00
|
|
|
}
|
|
|
|
|
2023-06-19 16:33:04 +02:00
|
|
|
bool SusConverter::checkValidity(bool* susValid, const uint64_t brightness[12],
|
|
|
|
const float threshold) {
|
|
|
|
uint8_t maxBrightness = 0;
|
|
|
|
VectorOperations<uint64_t>::maxValue(brightness, 12, &maxBrightness);
|
|
|
|
if (brightness[maxBrightness] == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (uint8_t idx = 0; idx < 12; idx++) {
|
|
|
|
if ((idx != maxBrightness) and (brightness[idx] < threshold * brightness[maxBrightness])) {
|
|
|
|
susValid[idx] = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
susValid[idx] = true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SusConverter::calculateSunVector(float* sunVectorSensorFrame, const uint16_t susChannel[6]) {
|
2022-09-23 09:56:32 +02:00
|
|
|
// Substract measurement values from GNDREF zero current threshold
|
2023-06-16 21:16:39 +02:00
|
|
|
float ch0 = susChannel[GNDREF] - susChannel[0];
|
|
|
|
float ch1 = susChannel[GNDREF] - susChannel[1];
|
|
|
|
float ch2 = susChannel[GNDREF] - susChannel[2];
|
|
|
|
float ch3 = susChannel[GNDREF] - susChannel[3];
|
2022-09-23 09:56:32 +02:00
|
|
|
|
|
|
|
// Calculation of x and y
|
2023-06-19 16:33:04 +02:00
|
|
|
float xout = ((D - S) / 2) * (ch2 - ch3 - ch0 + ch1) / (ch0 + ch1 + ch2 + ch3); //[mm]
|
|
|
|
float yout = ((D - S) / 2) * (ch2 + ch3 - ch0 - ch1) / (ch0 + ch1 + ch2 + ch3); //[mm]
|
2022-09-23 09:56:32 +02:00
|
|
|
|
|
|
|
// Calculation of the angles
|
2023-06-19 16:33:04 +02:00
|
|
|
sunVectorSensorFrame[0] = -xout;
|
|
|
|
sunVectorSensorFrame[1] = -yout;
|
|
|
|
sunVectorSensorFrame[2] = H;
|
2023-06-16 21:16:39 +02:00
|
|
|
VectorOperations<float>::normalize(sunVectorSensorFrame, sunVectorSensorFrame, 3);
|
2022-09-23 09:56:32 +02:00
|
|
|
}
|