Remap motor output

Is there an easy way to swap two motor outputs? Motor 1-4 outputs are routed to the corners of Kakute F7 FC. However, the order of motors is wrong and wiring becomes bit messy, requiring criss-cross of pwm wires.

Hi j_p,

I haven’t changed my motor outputs since the timer_config.cpp file changed, but for previous firmware versions is was as simple as changing the position in the array.

This is how they were set up last I modified them,

Each block, like the following, represents an output, and the blocks position in the array determines which output it is.
{
.gpio_out = GPIO_TIM3_CH3OUT,
.gpio_in = GPIO_TIM3_CH3IN,
.timer_index = 0,
.timer_channel = 3,
.ccr_offset = STM32_GTIM_CCR3_OFFSET,
.masks = GTIM_SR_CC3IF | GTIM_SR_CC3OF
},
The above is the first output. If you were to take that entire block (between { }) and move it beneath the second block, it becomes output2, and the old output2 becomes output1.

This is how it is done now. I haven’t modified it yet, but I’d suspect it to be the same.

NOT TESTED, always remove props! – Swap motor 1 for motor 2

ORIGINAL
constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
initIOTimerChannel(io_timers, {Timer::Timer5, Timer::Channel4}, {GPIO::PortA, GPIO::Pin3}),
initIOTimerChannel(io_timers, {Timer::Timer8, Timer::Channel4}, {GPIO::PortC, GPIO::Pin9}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel2}, {GPIO::PortE, GPIO::Pin11}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel1}, {GPIO::PortE, GPIO::Pin9}),
initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel4}, {GPIO::PortB, GPIO::Pin1}),
initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel3}, {GPIO::PortB, GPIO::Pin0}),
};

POST SWAP
constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
initIOTimerChannel(io_timers, {Timer::Timer8, Timer::Channel4}, {GPIO::PortC, GPIO::Pin9}),
initIOTimerChannel(io_timers, {Timer::Timer5, Timer::Channel4}, {GPIO::PortA, GPIO::Pin3}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel2}, {GPIO::PortE, GPIO::Pin11}),
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel1}, {GPIO::PortE, GPIO::Pin9}),
initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel4}, {GPIO::PortB, GPIO::Pin1}),
initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel3}, {GPIO::PortB, GPIO::Pin0}),
};

I am not a PX4 developer and cannot guarantee this will work, but I hope it helps.

Jake

1 Like

FWIW
The output mapping depends on the airframe: https://dev.px4.io/master/en/airframes/airframe_reference.html

That comes from the mixer file. The multicopter mixer definition just maps the outputs sequentially from the current output group.

So you can’t change the order here, but you could shift the start point perhaps. Not sure how useful that is.