Peripherals: make IrSensors return a struct.
std::pair isn't trivially copyable, it seems. Which is weird.
This commit is contained in:
parent
c9a08c26ea
commit
f456464f6c
@ -17,6 +17,15 @@
|
|||||||
namespace Peripherals
|
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>
|
template<typename G, std::size_t N, std::size_t Average>
|
||||||
class IrSensors
|
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++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
{
|
{
|
||||||
const float interim = averages_[i] - offsets_[i];
|
const float interim = averages_[i] - offsets_[i];
|
||||||
|
|
||||||
data[i].first = multipliers_[i] * std::pow(interim, exponents_[i]);
|
data[i].distance = multipliers_[i] * std::pow(interim, exponents_[i]);
|
||||||
data[i].second = data[i].first < wall_thresholds_[i];
|
data[i].sees_object = data[i].distance < wall_thresholds_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user