mixer: minor refactoring to reduce header include dependencies

- avoid including <px4_defines.h> from the math headers
- avoid driver include <drivers/drv_mixer.h> from the mixer
This commit is contained in:
Beat Küng
2018-12-13 09:50:07 +01:00
parent 8bcf54688a
commit c659d2bcc2
20 changed files with 60 additions and 45 deletions
-25
View File
@@ -71,31 +71,6 @@
/** reset (clear) the mixer configuration */
#define MIXERIOCRESET _MIXERIOC(1)
/** simple channel scaler */
struct mixer_scaler_s {
float negative_scale;
float positive_scale;
float offset;
float min_output;
float max_output;
};
/** mixer input */
struct mixer_control_s {
uint8_t control_group; /**< group from which the input reads */
uint8_t control_index; /**< index within the control group */
struct mixer_scaler_s scaler; /**< scaling applied to the input before use */
};
/** simple mixer */
struct mixer_simple_s {
uint8_t control_count; /**< number of inputs */
struct mixer_scaler_s output_scaler; /**< scaling for the output */
struct mixer_control_s controls[0]; /**< actual size of the array is set by control_count */
};
#define MIXER_SIMPLE_SIZE(_icount) (sizeof(struct mixer_simple_s) + (_icount) * sizeof(struct mixer_control_s))
/**
* add a simple mixer in (struct mixer_simple_s *)arg
*/
+1
View File
@@ -59,6 +59,7 @@
#include <uORB/topics/parameter_update.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_mixer.h>
#include <drivers/drv_pwm_output.h>
#include "uavcan_module.hpp"
@@ -38,6 +38,7 @@
#include "ManualSmoothingXY.hpp"
#include <mathlib/mathlib.h>
#include <float.h>
#include <px4_defines.h>
using namespace matrix;
@@ -38,6 +38,7 @@
#include "StraightLine.hpp"
#include <mathlib/mathlib.h>
#include <float.h>
#include <px4_defines.h>
#define VEL_ZERO_THRESHOLD 0.001f // Threshold to compare if the target velocity is zero
#define DECELERATION_MAX 8.0f // The vehicles maximum deceleration TODO check to create param
@@ -36,6 +36,7 @@
#include <cstdio>
#include <float.h>
#include <math.h>
#include <px4_defines.h>
#include <mathlib/mathlib.h>
+1
View File
@@ -42,6 +42,7 @@
#include "battery.h"
#include <mathlib/mathlib.h>
#include <cstring>
#include <px4_defines.h>
Battery::Battery() :
ModuleParams(nullptr),
+1
View File
@@ -37,6 +37,7 @@
* Vector rotation library
*/
#include <px4_defines.h>
#include "math.h"
#include "rotation.h"
+1 -1
View File
@@ -39,7 +39,7 @@
#pragma once
#include <platforms/px4_defines.h>
#include "Limits.hpp"
namespace math
{
+8 -3
View File
@@ -39,8 +39,13 @@
#pragma once
#include <platforms/px4_defines.h>
#include <float.h>
#include <math.h>
#include <stdint.h>
#ifndef MATH_PI
#define MATH_PI 3.141592653589793238462643383280
#endif
//this should be defined in stdint.h, but seems to be missing in the ARM toolchain (5.2.0)
#ifndef UINT64_C
@@ -90,13 +95,13 @@ inline constexpr bool isInRange(const _Tp &val, const _Tp &min_val, const _Tp &m
template<typename T>
constexpr T radians(const T degrees)
{
return degrees * (static_cast<T>(M_PI) / static_cast<T>(180));
return degrees * (static_cast<T>(MATH_PI) / static_cast<T>(180));
}
template<typename T>
constexpr T degrees(const T radians)
{
return radians * (static_cast<T>(180) / static_cast<T>(M_PI));
return radians * (static_cast<T>(180) / static_cast<T>(MATH_PI));
}
/** Save way to check if float is zero */
-2
View File
@@ -40,8 +40,6 @@
#pragma once
#include <platforms/px4_defines.h>
namespace math
{
static constexpr double GOLDEN_RATIO = 1.6180339887; //(sqrt(5)+1)/2
+1
View File
@@ -39,6 +39,7 @@
#include "mixer.h"
#include <math.h>
#include <cstring>
#include <ctype.h>
+33 -13
View File
@@ -125,19 +125,41 @@
*/
#ifndef _SYSTEMLIB_MIXER_MIXER_H
#define _SYSTEMLIB_MIXER_MIXER_H value
#pragma once
#include <px4_config.h>
#include "drivers/drv_mixer.h"
#include <stdint.h>
/** simple channel scaler */
struct mixer_scaler_s {
float negative_scale;
float positive_scale;
float offset;
float min_output;
float max_output;
};
/** mixer input */
struct mixer_control_s {
uint8_t control_group; /**< group from which the input reads */
uint8_t control_index; /**< index within the control group */
struct mixer_scaler_s scaler; /**< scaling applied to the input before use */
};
/** simple mixer */
struct mixer_simple_s {
uint8_t control_count; /**< number of inputs */
struct mixer_scaler_s output_scaler; /**< scaling for the output */
struct mixer_control_s controls[0]; /**< actual size of the array is set by control_count */
};
#define MIXER_SIMPLE_SIZE(_icount) (sizeof(struct mixer_simple_s) + (_icount) * sizeof(struct mixer_control_s))
#include "mixer_load.h"
/**
* Abstract class defining a mixer mixing zero or more inputs to
* one or more outputs.
*/
class __EXPORT Mixer
class Mixer
{
public:
enum class Airmode : int32_t {
@@ -304,7 +326,7 @@ private:
* Group of mixers, built up from single mixers and processed
* in order when mixing.
*/
class __EXPORT MixerGroup : public Mixer
class MixerGroup : public Mixer
{
public:
MixerGroup(ControlCallback control_cb, uintptr_t cb_handle);
@@ -440,7 +462,7 @@ private:
*
* Used as a placeholder for output channels that are unassigned in groups.
*/
class __EXPORT NullMixer : public Mixer
class NullMixer : public Mixer
{
public:
NullMixer();
@@ -481,7 +503,7 @@ public:
*
* Collects zero or more inputs and mixes them to a single output.
*/
class __EXPORT SimpleMixer : public Mixer
class SimpleMixer : public Mixer
{
public:
/**
@@ -582,7 +604,7 @@ enum class MultirotorGeometry : MultirotorGeometryUnderlyingType;
* Collects four inputs (roll, pitch, yaw, thrust) and mixes them to
* a set of outputs based on the configured geometry.
*/
class __EXPORT MultirotorMixer : public Mixer
class MultirotorMixer : public Mixer
{
public:
/**
@@ -813,7 +835,7 @@ struct mixer_heli_s {
* Collects four inputs (roll, pitch, yaw, thrust) and mixes them to servo commands
* for swash plate tilting and throttle- and pitch curves.
*/
class __EXPORT HelicopterMixer : public Mixer
class HelicopterMixer : public Mixer
{
public:
/**
@@ -870,5 +892,3 @@ private:
HelicopterMixer(const HelicopterMixer &);
HelicopterMixer operator=(const HelicopterMixer &);
};
#endif
+2
View File
@@ -40,6 +40,8 @@
#include "mixer.h"
#include <mathlib/mathlib.h>
#include <cstdio>
#include <px4_defines.h>
#define debug(fmt, args...) do { } while(0)
//#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0)
+1
View File
@@ -41,6 +41,7 @@
#include <cfloat>
#include <cstring>
#include <cstdio>
#include <mathlib/mathlib.h>
+1
View File
@@ -38,6 +38,7 @@
*/
#include "mixer.h"
#include <stdio.h>
#define debug(fmt, args...) do { } while(0)
//#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0)
@@ -38,6 +38,7 @@
#include "terrain_estimator.h"
#include <lib/ecl/geo/geo.h>
#include <px4_defines.h>
#define DISTANCE_TIMEOUT 100000 // time in usec after which laser is considered dead
@@ -39,6 +39,7 @@
#include <float.h>
#include <mathlib/mathlib.h>
#include "Utility/ControlMath.hpp"
#include <px4_defines.h>
using namespace matrix;
@@ -54,6 +54,7 @@
#include <uORB/topics/esc_status.h>
#include <lib/mixer/mixer.h>
#include <lib/mixer/mixer_load.h>
#include <battery/battery.h>
#include <bebop_bus/BebopBus.hpp>
+3 -1
View File
@@ -32,7 +32,7 @@
****************************************************************************/
/**
* @file mixer.c
* @file mixer.cpp
*
* Mixer utility.
*/
@@ -48,7 +48,9 @@
#include <errno.h>
#include <ctype.h>
#include <drivers/drv_mixer.h>
#include <lib/mixer/mixer.h>
#include <lib/mixer/mixer_load.h>
#include <uORB/topics/actuator_controls.h>
/**
+1
View File
@@ -44,6 +44,7 @@
#include <px4_config.h>
#include <mixer/mixer.h>
#include <mixer/mixer_load.h>
#include <pwm_limit/pwm_limit.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_pwm_output.h>