Peripherals: make IrSensors return a struct.

std::pair isn't trivially copyable, it seems. Which is weird.
This commit is contained in:
Erki 2021-06-22 16:21:29 +03:00
parent c9a08c26ea
commit f456464f6c

View File

@ -17,6 +17,15 @@
namespace Peripherals
{
struct IrSensorsReading
{
/// Distance as read by the sensor.
float distance;
/// @c true if the @c distance is < the wall threshold.
bool sees_object;
};
template<typename G, std::size_t N, std::size_t Average>
class IrSensors
{
@ -61,16 +70,16 @@ public:
}
}
std::array<std::pair<float, bool>, N> getDistanceData()
std::array<IrSensorsReading, N> getDistanceData()
{
std::array<std::pair<float, bool>, N> data;
std::array<IrSensorsReading, N> data;
for (std::size_t i = 0; i < N; i++)
{
const float interim = averages_[i] - offsets_[i];
data[i].first = multipliers_[i] * std::pow(interim, exponents_[i]);
data[i].second = data[i].first < wall_thresholds_[i];
data[i].distance = multipliers_[i] * std::pow(interim, exponents_[i]);
data[i].sees_object = data[i].distance < wall_thresholds_[i];
}
return data;