2013-05-29 20:54:53 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2012-09-18 11:05:08 -03:00
|
|
|
|
|
|
|
/// @file AP_Curve.h
|
|
|
|
/// @brief used to transforms a pwm value to account for the non-linear pwm->thrust values of normal ESC+motors
|
|
|
|
|
2012-10-26 21:39:06 -03:00
|
|
|
#ifndef __AP_CURVE_H__
|
|
|
|
#define __AP_CURVE_H__
|
2012-09-18 11:05:08 -03:00
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-09-18 11:05:08 -03:00
|
|
|
|
|
|
|
/// @class AP_Curve
|
|
|
|
template <class T, uint8_t SIZE>
|
|
|
|
class AP_Curve {
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
AP_Curve();
|
|
|
|
|
|
|
|
// clear - removes all points from the curve
|
2014-02-10 04:27:38 -04:00
|
|
|
void clear();
|
2012-09-18 11:05:08 -03:00
|
|
|
|
|
|
|
// add_point - adds a point to the curve. returns TRUE if successfully added
|
2014-02-10 04:27:38 -04:00
|
|
|
bool add_point( T x, T y );
|
2012-09-18 11:05:08 -03:00
|
|
|
|
|
|
|
// get_y - returns the point on the curve at the given pwm_value (i.e. the new modified pwm_value)
|
2014-02-10 04:27:38 -04:00
|
|
|
T get_y( T x );
|
2012-09-18 11:05:08 -03:00
|
|
|
|
|
|
|
// displays the contents of the curve (for debugging)
|
2014-02-10 04:27:38 -04:00
|
|
|
void dump_curve(AP_HAL::BetterStream*);
|
2012-09-18 11:05:08 -03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
uint8_t _num_points; // number of points in the cruve
|
|
|
|
T _x[SIZE]; // x values of each point on the curve
|
|
|
|
T _y[SIZE]; // y values of each point on the curve
|
|
|
|
float _slope[SIZE]; // slope between any two points. i.e. slope[0] is the slope between points 0 and 1
|
|
|
|
bool _constrained; // if true, first and last points added will constrain the y values returned by get_y function
|
|
|
|
};
|
|
|
|
|
2012-12-16 20:55:21 -04:00
|
|
|
|
|
|
|
/* Typedefs for template instansations of AP_Curve.
|
|
|
|
* Only use the AP_Curve instances listed here!
|
|
|
|
* If you need a different one, you must first instantiate the template at the
|
2015-10-26 10:24:54 -03:00
|
|
|
* end of AP_Curve.cpp, then add a typedef here.
|
2012-12-16 20:55:21 -04:00
|
|
|
*/
|
|
|
|
|
2012-09-18 11:05:08 -03:00
|
|
|
typedef AP_Curve<int16_t,3> AP_CurveInt16_Size3;
|
|
|
|
typedef AP_Curve<int16_t,4> AP_CurveInt16_Size4;
|
|
|
|
typedef AP_Curve<int16_t,5> AP_CurveInt16_Size5;
|
|
|
|
typedef AP_Curve<uint16_t,3> AP_CurveUInt16_Size3;
|
|
|
|
typedef AP_Curve<uint16_t,4> AP_CurveUInt16_Size4;
|
|
|
|
typedef AP_Curve<uint16_t,5> AP_CurveUInt16_Size5;
|
|
|
|
|
2012-10-26 21:39:06 -03:00
|
|
|
#endif // __AP_CURVE_H__
|