1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-20 14:55:18 +03:00

Allow max motors to be set in target.h

This commit is contained in:
Martin Budden 2016-05-21 10:33:03 +01:00
parent 5ec4cf715a
commit 941b72b36f
5 changed files with 73 additions and 29 deletions

View file

@ -19,15 +19,23 @@
#include "gpio.h"
#include "timer.h"
#if defined(USE_QUAD_MIXER_ONLY)
#define MAX_PWM_MOTORS 4
#define MAX_PWM_SERVOS 1
#define MAX_MOTORS 4
#define MAX_SERVOS 1
#elif defined(TARGET_MOTOR_COUNT)
#define MAX_PWM_MOTORS TARGET_MOTOR_COUNT
#define MAX_PWM_SERVOS 8
#define MAX_MOTORS TARGET_MOTOR_COUNT
#define MAX_SERVOS 8
#else
#define MAX_PWM_MOTORS 12
#define MAX_PWM_SERVOS 8
#define MAX_MOTORS 12
#define MAX_SERVOS 8
#define MAX_PWM_OUTPUT_PORTS MAX_PWM_MOTORS // must be set to the largest of either MAX_MOTORS or MAX_SERVOS
#if MAX_PWM_OUTPUT_PORTS < MAX_MOTORS || MAX_PWM_OUTPUT_PORTS < MAX_SERVOS
#error Invalid motor/servo/port configuration
#endif

View file

@ -31,6 +31,12 @@
#include "pwm_output.h"
#if (MAX_MOTORS > MAX_SERVOS)
#define MAX_PWM_OUTPUT_PORTS MAX_MOTORS
#else
#define MAX_PWM_OUTPUT_PORTS MAX_SERVOS
#endif
typedef void (*pwmWriteFuncPtr)(uint8_t index, uint16_t value); // function pointer used to write motors
typedef struct {

View file

@ -132,6 +132,7 @@ static const motorMixer_t mixerHex6H[] = {
{ 1.0f, 0.0f, 0.0f, 0.0f }, // LEFT
};
#if (MAX_SUPPORTED_MOTORS >= 6)
static const motorMixer_t mixerY6[] = {
{ 1.0f, 0.0f, 1.333333f, 1.0f }, // REAR
{ 1.0f, -1.0f, -0.666667f, -1.0f }, // RIGHT
@ -149,6 +150,7 @@ static const motorMixer_t mixerHex6P[] = {
{ 1.0f, 0.0f, -1.0f, 1.0f }, // FRONT
{ 1.0f, 0.0f, 1.0f, -1.0f }, // REAR
};
#endif
static const motorMixer_t mixerY4[] = {
{ 1.0f, 0.0f, 1.0f, -1.0f }, // REAR_TOP CW
@ -157,6 +159,7 @@ static const motorMixer_t mixerY4[] = {
{ 1.0f, 1.0f, -1.0f, 0.0f }, // FRONT_L CW
};
#if (MAX_SUPPORTED_MOTORS >= 8)
static const motorMixer_t mixerOctoFlatP[] = {
{ 1.0f, 0.707107f, -0.707107f, 1.0f }, // FRONT_L
{ 1.0f, -0.707107f, -0.707107f, 1.0f }, // FRONT_R
@ -179,17 +182,6 @@ static const motorMixer_t mixerOctoFlatX[] = {
{ 1.0f, 1.0f, 0.414178f, -1.0f }, // MIDREAR_L
};
#endif //DISABLE_UNCOMMON_MIXERS
static const motorMixer_t mixerHex6X[] = {
{ 1.0f, -0.5f, 0.866025f, 1.0f }, // REAR_R
{ 1.0f, -0.5f, -0.866025f, 1.0f }, // FRONT_R
{ 1.0f, 0.5f, 0.866025f, -1.0f }, // REAR_L
{ 1.0f, 0.5f, -0.866025f, -1.0f }, // FRONT_L
{ 1.0f, -1.0f, 0.0f, -1.0f }, // RIGHT
{ 1.0f, 1.0f, 0.0f, 1.0f }, // LEFT
};
static const motorMixer_t mixerOctoX8[] = {
{ 1.0f, -1.0f, 1.0f, -1.0f }, // REAR_R
{ 1.0f, -1.0f, -1.0f, 1.0f }, // FRONT_R
@ -200,6 +192,19 @@ static const motorMixer_t mixerOctoX8[] = {
{ 1.0f, 1.0f, 1.0f, -1.0f }, // UNDER_REAR_L
{ 1.0f, 1.0f, -1.0f, 1.0f }, // UNDER_FRONT_L
};
#endif
#endif //DISABLE_UNCOMMON_MIXERS
#if (MAX_SUPPORTED_MOTORS >= 6)
static const motorMixer_t mixerHex6X[] = {
{ 1.0f, -0.5f, 0.866025f, 1.0f }, // REAR_R
{ 1.0f, -0.5f, -0.866025f, 1.0f }, // FRONT_R
{ 1.0f, 0.5f, 0.866025f, -1.0f }, // REAR_L
{ 1.0f, 0.5f, -0.866025f, -1.0f }, // FRONT_L
{ 1.0f, -1.0f, 0.0f, -1.0f }, // RIGHT
{ 1.0f, 1.0f, 0.0f, 1.0f }, // LEFT
};
#endif
static const motorMixer_t mixerSingleProp[] = {
{ 1.0f, 0.0f, 0.0f, 0.0f },
@ -210,7 +215,7 @@ const mixer_t mixers[] = {
// motors, use servo, motor mixer
{ 0, false, NULL, true }, // entry 0
{ 3, true, mixerTricopter, true }, // MIXER_TRI
#ifndef DISABLE_UNCOMMON_MIXERS
#if !defined(DISABLE_UNCOMMON_MIXERS)
{ 4, false, mixerQuadP, true }, // MIXER_QUADP
#else
{ 0, false, NULL, false }, // MIXER_QUADP
@ -219,7 +224,7 @@ const mixer_t mixers[] = {
{ 0, false, NULL, false }, // MIXER_BICOPTER
{ 0, false, NULL, false }, // MIXER_GIMBAL -> this mixer was never implemented in CF, use feature(FEATURE_SERVO_TILT) instead
#ifndef DISABLE_UNCOMMON_MIXERS
#if !defined(DISABLE_UNCOMMON_MIXERS) && (MAX_SUPPORTED_MOTORS >= 6)
{ 6, false, mixerY6, true }, // MIXER_Y6
{ 6, false, mixerHex6P, true }, // MIXER_HEX6
#else
@ -227,34 +232,39 @@ const mixer_t mixers[] = {
{ 0, false, NULL, false }, // MIXER_HEX6
#endif
{ 1, true, mixerSingleProp, true }, // MIXER_FLYING_WING
#ifndef DISABLE_UNCOMMON_MIXERS
#if !defined(DISABLE_UNCOMMON_MIXERS)
{ 4, false, mixerY4, true }, // MIXER_Y4
#else
{ 0, false, NULL, false }, // MIXER_Y4
#endif
{ 6, false, mixerHex6X, true }, // MIXER_HEX6X
{ 8, false, mixerOctoX8, true }, // MIXER_OCTOX8
#ifndef DISABLE_UNCOMMON_MIXERS
#if !defined(DISABLE_UNCOMMON_MIXERS) && (MAX_SUPPORTED_MOTORS >= 8)
{ 8, false, mixerOctoX8, true }, // MIXER_OCTOX8
{ 8, false, mixerOctoFlatP, true }, // MIXER_OCTOFLATP
{ 8, false, mixerOctoFlatX, true }, // MIXER_OCTOFLATX
#else
{ 0, false, NULL, false }, // MIXER_OCTOX8
{ 0, false, NULL, false }, // MIXER_OCTOFLATP
{ 0, false, NULL, false }, // MIXER_OCTOFLATX
#endif
{ 1, true, mixerSingleProp, true }, // * MIXER_AIRPLANE
{ 0, true, NULL, false }, // * MIXER_HELI_120_CCPM -> disabled, never fully implemented in CF
{ 0, true, NULL, false }, // * MIXER_HELI_90_DEG -> disabled, never fully implemented in CF
#ifndef DISABLE_UNCOMMON_MIXERS
#if !defined(DISABLE_UNCOMMON_MIXERS)
{ 4, false, mixerVtail4, true }, // MIXER_VTAIL4
#if (MAX_SUPPORTED_MOTORS >= 6)
{ 6, false, mixerHex6H, true }, // MIXER_HEX6H
#else
{ 0, false, NULL, false }, // MIXER_HEX6H
#endif
#else
{ 0, false, NULL, false }, // MIXER_VTAIL4
{ 0, false, NULL, false }, // MIXER_HEX6H
#endif
{ 0, true, NULL, false }, // * MIXER_PPM_TO_SERVO -> looks like this is not implemented at all
{ 0, false, NULL, false }, // MIXER_DUALCOPTER
{ 0, false, NULL, false }, // MIXER_SINGLECOPTER
#ifndef DISABLE_UNCOMMON_MIXERS
{ 0, true, NULL, false }, // * MIXER_PPM_TO_SERVO -> looks like this is not implemented at all
{ 0, false, NULL, false }, // MIXER_DUALCOPTER
{ 0, false, NULL, false }, // MIXER_SINGLECOPTER
#if !defined(DISABLE_UNCOMMON_MIXERS)
{ 4, false, mixerAtail4, true }, // MIXER_ATAIL4
#else
{ 0, false, NULL, false }, // MIXER_ATAIL4

View file

@ -17,8 +17,19 @@
#pragma once
#if defined(USE_QUAD_MIXER_ONLY)
#define MAX_SUPPORTED_MOTORS 4
#define MAX_SUPPORTED_SERVOS 1
#elif defined(TARGET_MOTOR_COUNT)
#define MAX_SUPPORTED_MOTORS TARGET_MOTOR_COUNT
#define MAX_SUPPORTED_SERVOS 8
#else
#define MAX_SUPPORTED_MOTORS 12
#define MAX_SUPPORTED_SERVOS 8
#endif
#define YAW_JUMP_PREVENTION_LIMIT_LOW 80
#define YAW_JUMP_PREVENTION_LIMIT_HIGH 500

View file

@ -238,12 +238,14 @@ static void tailSerialReply(void)
serialEndWrite(mspSerialPort);
}
#ifdef USE_SERVOS
static void s_struct(uint8_t *cb, uint8_t siz)
{
headSerialReply(siz);
while (siz--)
serialize8(*cb++);
}
#endif
static void serializeNames(const char *s)
{
@ -680,7 +682,10 @@ static bool processOutCommand(uint8_t cmdMSP)
break;
#endif
case MSP_MOTOR:
s_struct((uint8_t *)motor, 16);
headSerialReply(16);
for (unsigned i = 0; i < 8; i++) {
serialize16(i < MAX_SUPPORTED_MOTORS ? motor[i] : 0);
}
break;
case MSP_RC:
headSerialReply(2 * rxRuntimeConfig.channelCount);
@ -1265,8 +1270,12 @@ static bool processInCommand(void)
masterConfig.batteryConfig.vbatwarningcellvoltage = read8(); // vbatlevel when buzzer starts to alert
break;
case MSP_SET_MOTOR:
for (i = 0; i < 8; i++) // FIXME should this use MAX_MOTORS or MAX_SUPPORTED_MOTORS instead of 8
motor_disarmed[i] = read16();
for (i = 0; i < 8; i++) {
const int16_t disarmed = read16();
if (i < MAX_SUPPORTED_MOTORS) {
motor_disarmed[i] = disarmed;
}
}
break;
case MSP_SET_SERVO_CONFIGURATION:
#ifdef USE_SERVOS