Compare commits

..

4 Commits

Author SHA1 Message Date
Erki
15652f7347 Threads: fix actor and signal requirements
All checks were successful
continuous-integration/drone/push Build is passing
Trivially copyable and default constructible should be sufficient, as it
allows for memcpy and a T{} ctor.
2021-06-22 16:22:11 +03:00
Erki
f456464f6c Peripherals: make IrSensors return a struct.
std::pair isn't trivially copyable, it seems. Which is weird.
2021-06-22 16:21:29 +03:00
Erki
c9a08c26ea Peripherals: make IMU accelerometerRawToReading return G's. 2021-06-22 16:14:06 +03:00
Erki
5880f967d7 Threads: Fix actor.hpp includes 2021-06-22 16:12:56 +03:00
4 changed files with 21 additions and 8 deletions

View File

@ -214,7 +214,7 @@ public:
float accelerometerRawToReading(const std::int16_t bit) const float accelerometerRawToReading(const std::int16_t bit) const
{ {
return float(bit) * accel_fs_to_bit_constants_[std::uint32_t(scale_accel_)]; return (float(bit) * accel_fs_to_bit_constants_[std::uint32_t(scale_accel_)]) * 9.8f;
} }
float gyroRawToReading(const std::int16_t bit) const float gyroRawToReading(const std::int16_t bit) const

View File

@ -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;

View File

@ -8,7 +8,10 @@
#ifndef SKULLC_THREADS_ACTOR_HPP_ #ifndef SKULLC_THREADS_ACTOR_HPP_
#define SKULLC_THREADS_ACTOR_HPP_ #define SKULLC_THREADS_ACTOR_HPP_
#include <cmsis_os.h>
#include <freertos_os2.h>
#include <queue.h> #include <queue.h>
#include <type_traits> #include <type_traits>
#include "threads_primitivethread.hpp" #include "threads_primitivethread.hpp"
@ -23,7 +26,7 @@ class Actor
public: public:
using value_type = T; using value_type = T;
static_assert(std::is_trivially_constructible_v<value_type>, "T must be trivially constructible."); static_assert(std::is_default_constructible_v<value_type>, "T must be default constructible.");
static_assert(std::is_trivially_copyable_v<value_type>, "T must be trivially copyable."); static_assert(std::is_trivially_copyable_v<value_type>, "T must be trivially copyable.");
Actor(const std::uint32_t queue_size, const char* name, const osPriority_t priority, const std::uint32_t stack_size) Actor(const std::uint32_t queue_size, const char* name, const osPriority_t priority, const std::uint32_t stack_size)
@ -54,7 +57,7 @@ private:
{ {
init(); init();
value_type data; value_type data{};
while (true) while (true)
{ {

View File

@ -20,7 +20,8 @@ struct Signallable
{ {
using value_type = T; using value_type = T;
static_assert(std::is_trivially_constructible_v<value_type>, "T must be trivially constructible."); static_assert(std::is_trivially_copyable_v<value_type>, "T must be trivially copyable.");
static_assert(std::is_default_constructible_v<value_type>, "T must be default constructible.");
virtual bool emit(const T& t) = 0; virtual bool emit(const T& t) = 0;
virtual std::pair<bool, BaseType_t> emitFromIsr(const T& t) = 0; virtual std::pair<bool, BaseType_t> emitFromIsr(const T& t) = 0;