pimoroni-pico/drivers/servo/calibration.hpp

100 wiersze
3.1 KiB
C++
Czysty Zwykły widok Historia

#pragma once
#include "pico/stdlib.h"
namespace servo {
2022-02-17 22:38:59 +00:00
enum CalibrationType {
ANGULAR = 0,
LINEAR,
CONTINUOUS
};
class Calibration {
//--------------------------------------------------
// Constants
//--------------------------------------------------
public:
static constexpr float DEFAULT_MIN_PULSE = 500.0f; // in microseconds
static constexpr float DEFAULT_MID_PULSE = 1500.0f; // in microseconds
static constexpr float DEFAULT_MAX_PULSE = 2500.0f; // in microseconds
2022-02-19 19:25:15 +00:00
private:
static constexpr float LOWER_HARD_LIMIT = 400.0f; // The minimum microsecond pulse to send
static constexpr float UPPER_HARD_LIMIT = 2600.0f; // The maximum microsecond pulse to send
//--------------------------------------------------
// Substructures
//--------------------------------------------------
public:
2022-02-17 22:38:59 +00:00
struct Point {
//--------------------------------------------------
// Constructors/Destructor
//--------------------------------------------------
2022-02-17 22:38:59 +00:00
Point();
Point(float pulse, float value);
//--------------------------------------------------
// Variables
//--------------------------------------------------
float pulse;
float value;
};
2022-02-17 22:38:59 +00:00
//--------------------------------------------------
// Constructors/Destructor
//--------------------------------------------------
2022-02-17 22:38:59 +00:00
public:
Calibration();
2022-02-17 22:38:59 +00:00
Calibration(CalibrationType default_type);
Calibration(const Calibration &other);
virtual ~Calibration();
//--------------------------------------------------
// Operators
//--------------------------------------------------
public:
Calibration& operator=(const Calibration &other);
Point& operator[](uint8_t index) const;
//--------------------------------------------------
// Methods
//--------------------------------------------------
public:
void apply_blank(uint size);
void apply_two_point(float min_pulse, float max_pulse, float min_value, float max_value);
void apply_three_point(float min_pulse, float mid_pulse, float max_pulse, float min_value, float mid_value, float max_value);
void apply_uniform(uint size, float min_pulse, float max_pulse, float min_value, float max_value);
void apply_default(CalibrationType default_type);
2022-02-17 22:38:59 +00:00
uint size() const;
Point* point_at(uint8_t index) const; // Ensure the points are assigned in ascending value order
Point* first_point() const;
Point* last_point() const;
bool has_lower_limit() const;
bool has_upper_limit() const;
void limit_to_calibration(bool lower, bool upper);
2022-02-19 19:25:15 +00:00
bool value_to_pulse(float value, float &pulse_out, float &value_out) const;
2022-02-19 20:13:18 +00:00
bool pulse_to_value(float pulse, float &value_out, float &pulse_out) const;
2022-02-17 22:38:59 +00:00
static float map_float(float in, float in_min, float in_max, float out_min, float out_max);
//--------------------------------------------------
// Variables
//--------------------------------------------------
private:
2022-02-17 22:38:59 +00:00
Point* calibration;
uint calibration_size;
bool limit_lower;
bool limit_upper;
};
}