Skip to content

Commit

Permalink
update documents
Browse files Browse the repository at this point in the history
  • Loading branch information
shota3527 committed Jul 25, 2023
1 parent 3cf482c commit 05449aa
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 31 deletions.
136 changes: 136 additions & 0 deletions docs/MixerProfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# MixerProfile
A MixerProfile is a set of motor mixer,servomixer,platform type configuration settings.

Currently Two profiles are supported expect f411 and f722. The default profile is profile `1`.

Switching between profiles requires reboot to take affect by default. But When the conditions are met, It allows inflight profile switching to allow things like vtol build.

# Setup for vtol
- Need to keep motor/servo pwm mapping consistent among profiles
- FW and MC have different way to map the pwm mapping, we need to change `timerHardware`` for to make it have same mapping.
- A vtol specific fc target is required. There might more official vtol fc target in the future
- Set mixer_profile, pid_profile separately, and set RC mode to switch them
## FC target
To keep motor/servo pwm mapping consistent and enable hot switching. Here is MATEKF405TE_SD board (folder name `MATEKF405TE`) used for vtol as a example.

The target name for vtol build is MATEKF405TE_SD_VTOL, target folder name is MATEKF405TE.
when it is done, build your target and flash it to your fc,.

### CMakeLists.txt
```c
target_stm32f405xg(MATEKF405TE)
target_stm32f405xg(MATEKF405TE_SD)
target_stm32f405xg(MATEKF405TE_SD_VTOL) //new target added
```
### target.c
It is **important** to map all the serial output to `TIM_USE_VTOL_MOTOR` or `TIM_USE_VTOL_SERVO` to ensure same mapping among MC mapping and FW mapping.
```c
timerHardware_t timerHardware[] = {
#ifdef MATEKF405TE_SD_VTOL // Vtol target specific mapping start from there
DEF_TIM(TIM8, CH4, PC9, TIM_USE_VTOL_MOTOR, 0, 0), // S1 for motor
DEF_TIM(TIM8, CH3, PC8, TIM_USE_VTOL_MOTOR, 0, 0), // S2 for motor
DEF_TIM(TIM1, CH3N, PB15, TIM_USE_VTOL_MOTOR, 0, 0), // S3 for motor
DEF_TIM(TIM1, CH1, PA8, TIM_USE_VTOL_MOTOR, 0, 1), // S4 for motor
DEF_TIM(TIM2, CH4, PB11, TIM_USE_VTOL_SERVO, 0, 0), // S5 for servo
DEF_TIM(TIM2, CH3, PB10, TIM_USE_VTOL_SERVO, 0, 0), // S6 for servo
DEF_TIM(TIM2, CH2, PB3, TIM_USE_VTOL_SERVO, 0, 0), // S7 for servo
DEF_TIM(TIM2, CH1, PA15, TIM_USE_VTOL_SERVO, 0, 0), // S8 for servo
DEF_TIM(TIM12, CH1, PB14, TIM_USE_VTOL_SERVO, 0, 0), // S9 for servo
DEF_TIM(TIM13, CH1, PA6, TIM_USE_VTOL_SERVO, 0, 0), // S10 for servo
DEF_TIM(TIM4, CH1, PB6, TIM_USE_VTOL_MOTOR, 0, 0), // S11 for motor
#else // Vtol target specific mapping end there
//Non votl target start from here
.........omitted
#endif
DEF_TIM(TIM3, CH4, PB1, TIM_USE_LED, 0, 0), // 2812LED D(1,2,5)
DEF_TIM(TIM11, CH1, PB9, TIM_USE_BEEPER, 0, 0), // BEEPER PWM
DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), //RX2
DEF_TIM(TIM5, CH3, PA2, TIM_USE_ANY, 0, 0), //TX2 softserial1_Tx
};
```
### target.h

Then define `ENABLE_MIXER_PROFILE_MCFW_HOTSWAP` to enable mixer_profile hot switching once you have set the pwm mapping
```c
#ifdef MATEKF405TE_SD_VTOL
#define ENABLE_MIXER_PROFILE_MCFW_HOTSWAP //Enable hot swap
#define MATEKF405TE_SD //Define the original target name keep its original configuration such as USBD_PRODUCT_STRING
#endif
```

## Configuration
### Profile switch
Setup the FW mode and MC mode separately in two different mixer profile,

I will use FW mode as mixer_profile 1, and MC as mixer_profile 2 as example.
At current state, inav-configurator do not support mixer_profile, some of the settings have to be done in cli

`set mixer_pid_profile_linking = ON` to enable pid_profile auto handling. It will change the pid_profile index according to mixer_profile index on fc boot and mixer_profile hot switching(recommended)
```
mixer_profile 1 #switch to mixer_profile by cli
set platform_type = AIRPLANE
set model_preview_type = 26
set motorstop_on_low = ON # motor stop feature have been moved to here
set mixer_pid_profile_linking = ON # enable pid_profile auto handling(recommended).
save
```
Then finish the airplane setting on mixer_profile 1

```
mixer_profile 2
set platform_type = TRICOPTER
set model_preview_type = 1
set mixer_pid_profile_linking = ON # also enable pid_profile auto handling
save
```
Then finish the multirotor setting on mixer_profile 2
You can use `MAX` servo input to set a fixed input for the tilting servo. speed setting for `MAX` input is available in cli.

**Double check all settings in cli by `diff all` command**, make sure you have correct settings. And see what will change with mixer_profile. For example servo output min/max range will not change

### Mixer Transition input
Normally 'transition input' will be useful in MC mode to gain airspeed.
Servo mixer and motor mixer can accept transition mode as input.
It will move accordingly when transition mode is activated.
The use of Transition mode is recommended to enable further features/developments like failsafe support. Map motor to servo output, or servo with logic condition is not recommended
#### servo
38 is the input source for transition input, use this to tilt motor to gain airspeed
example:
Add servo 1 output by +45 in speed of 150 when transition mode is activate for tilted motor setup
```
# rule no; servo index; input source; rate; speed; activate logic function number
smix 6 1 38 45 150 -1
```

#### motor
the default mmix throttle value is 0.0, It will not show in diff command when throttle value is 0.0(unused), which motor will stop.
- 0.0<throttle<=1.0 : normal mapping
- -1.0<throttle<=0.0 : motor stop, default value 0
- -2.0<throttle<-1.0 : spin regardless of the radio\`s throttle position at speed `abs(throttle)-1` when Mixer Transition is activated

example:
It will spin motor number 5(count from 1) at 20% in transition mode to gain speed for 4 rotor 1 pusher setup
```
# motor number; throttle; roll; pitch; yaw
mmix 4 -1.200 0.000 0.000 0.000
```

### RC mode settings
It currently support take a rc input to activate modes or switch profiles
Mixer_profile 1 will be used as default, mixer_profile 2 will be used when `MIXER PROFILE 2` box is activated, Once successfully set, You can see profiles/model preview/etc will switch accordingly when you change inav-configurator tabs, it will make the setting easier.

Set `MIXER TRANSITION` accordingly when you want to use `MIXER TRANSITION` input for motors and servos, Here is sample of
![Alt text](Screenshots/mixer_profile.png)
| 1000~1300 | 1300~1700 | 1700~2000 |
| :-- | :-- | :-- |
| FW(profile1) with transition off | MC(profile2) with transition on | MC(profile2) with transition off |

It is also possible to set it as 4 state switch by adding FW(profile1) with transition on
## Happy flying
Test every thing on bench first, Try it some where you can recover your model in case of failsafe.
Failsafe behavior is unknown at current stage.
Binary file added docs/Screenshots/mixer_profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/drivers/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ typedef enum {
TIM_USE_MC_CHNFW = (1 << 4), // Deprecated and not used after removal of CHANNEL_FORWARDING feature
TIM_USE_FW_MOTOR = (1 << 5),
TIM_USE_FW_SERVO = (1 << 6),
TIM_USE_VTOL_SERVO = (TIM_USE_FW_SERVO | TIM_USE_MC_SERVO),
TIM_USE_VTOL_MOTOR = (TIM_USE_FW_MOTOR | TIM_USE_MC_MOTOR),
TIM_USE_LED = (1 << 24),
TIM_USE_BEEPER = (1 << 25),
} timerUsageFlag_e;
Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/fc_msp_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
{ .boxId = BOXSOARING, .boxName = "SOARING", .permanentId = 56 },
{ .boxId = BOXCHANGEMISSION, .boxName = "MISSION CHANGE", .permanentId = 59 },
{ .boxId = BOXBEEPERMUTE, .boxName = "BEEPER MUTE", .permanentId = 60 },
{ .boxId = BOXMIXERPROFILE, .boxName = "MIXER RPROFILE 2", .permanentId = 61 },
{ .boxId = BOXMIXERPROFILE, .boxName = "MIXER PROFILE 2", .permanentId = 61 },
{ .boxId = BOXMIXERTRANSITION, .boxName = "MIXER TRANSITION", .permanentId = 62 },
{ .boxId = CHECKBOX_ITEM_COUNT, .boxName = NULL, .permanentId = 0xFF }
};
Expand Down
13 changes: 12 additions & 1 deletion src/main/flight/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,25 @@ int getThrottleIdleValue(void)

static void computeMotorCount(void)
{
static bool firstRun = true;
if (!firstRun) {
return;
}
motorCount = 0;
for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
bool isMotorUsed = false;
for(int j = 0; j< MAX_MIXER_PROFILE_COUNT; j++){
if (mixerMotorMixersByIndex(j)[i]->throttle != 0.0f) {
isMotorUsed = true;
}
}
// check if done
if (primaryMotorMixer(i)->throttle == 0.0f) {
if (!isMotorUsed) {
break;
}
motorCount++;
}
firstRun = false;
}

bool ifMotorstopFeatureEnabled(void){
Expand Down
36 changes: 18 additions & 18 deletions src/main/flight/mixer_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ void mixerConfigInit(void){
}
}

static int computeMotorCountByMixerProfileIndex(int index)
{
int motorCount = 0;
const motorMixer_t* temp_motormixers=mixerMotorMixersByIndex(index)[0];
for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
// check if done
if (temp_motormixers[i].throttle == 0.0f) {
break;
}
motorCount++;
}
return motorCount;
}
// static int computeMotorCountByMixerProfileIndex(int index)
// {
// int motorCount = 0;
// const motorMixer_t* temp_motormixers=mixerMotorMixersByIndex(index)[0];
// for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
// // check if done
// if (temp_motormixers[i].throttle == 0.0f) {
// break;
// }
// motorCount++;
// }
// return motorCount;
// }

// static int computeServoCountByMixerProfileIndex(int index)
// {
Expand Down Expand Up @@ -159,13 +159,13 @@ bool checkMixerProfileHotSwitchAvalibility(void)
allow_hot_switch = 0;
return false;
}
//not necessary when map motor/servos of all mixer profiles on the first boot
//do not allow switching if motor or servos counts are different
// if ((computeMotorCountByMixerProfileIndex(0) != computeMotorCountByMixerProfileIndex(1)) || (computeServoCountByMixerProfileIndex(0) != computeServoCountByMixerProfileIndex(1)))
if ((computeMotorCountByMixerProfileIndex(0) != computeMotorCountByMixerProfileIndex(1)))
{
allow_hot_switch = 0;
return false;
}
// {
// allow_hot_switch = 0;
// return false;
// }
allow_hot_switch = 1;
return true;
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/target/MATEKF405TE/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
timerHardware_t timerHardware[] = {
#ifdef MATEKF405TE_SD_VTOL
//With INAV firmware, DSHOT can not work on S3, S5,S7 because of DMA clash, pls use ONESHOT or MULTISHOT and calibrate ESC PWM range.<-copied from matek website
DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 D(2,7,7) UP217
DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2 D(2,2,0) UP217
DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S3 D(2,6,0) UP256
DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S4 D(2,1,6) UP256
DEF_TIM(TIM8, CH4, PC9, TIM_USE_VTOL_MOTOR, 0, 0), // S1 D(2,7,7) UP217
DEF_TIM(TIM8, CH3, PC8, TIM_USE_VTOL_MOTOR, 0, 0), // S2 D(2,2,0) UP217
DEF_TIM(TIM1, CH3N, PB15, TIM_USE_VTOL_MOTOR, 0, 0), // S3 D(2,6,0) UP256
DEF_TIM(TIM1, CH1, PA8, TIM_USE_VTOL_MOTOR, 0, 1), // S4 D(2,1,6) UP256

DEF_TIM(TIM2, CH4, PB11, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S5 D(1,7,3) UP173
DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6 D(1,1,3) UP173
DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S7 D(1,6,3) UP173
DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S8 D(1,5,3) UP173
DEF_TIM(TIM2, CH4, PB11, TIM_USE_VTOL_SERVO, 0, 0), // S5 D(1,7,3) UP173
DEF_TIM(TIM2, CH3, PB10, TIM_USE_VTOL_SERVO, 0, 0), // S6 D(1,1,3) UP173
DEF_TIM(TIM2, CH2, PB3, TIM_USE_VTOL_SERVO, 0, 0), // S7 D(1,6,3) UP173
DEF_TIM(TIM2, CH1, PA15, TIM_USE_VTOL_SERVO, 0, 0), // S8 D(1,5,3) UP173

DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S9 DMA NONE
DEF_TIM(TIM13, CH1, PA6, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S10 DMA NONE
DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S11 D(1,0,2)
DEF_TIM(TIM12, CH1, PB14, TIM_USE_VTOL_SERVO, 0, 0), // S9 DMA NONE
DEF_TIM(TIM13, CH1, PA6, TIM_USE_VTOL_SERVO, 0, 0), // S10 DMA NONE
DEF_TIM(TIM4, CH1, PB6, TIM_USE_VTOL_MOTOR, 0, 0), // S11 D(1,0,2)
#else
DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 D(2,7,7) UP217
DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2 D(2,2,0) UP217
Expand Down

0 comments on commit 05449aa

Please sign in to comment.