How to control servo (via code - not RC)

Hey all,

I was wondering if anyone knows how i could control one of the pwm outputs (MAIN 5 for example) using the px4 code.
This is for a quadrotor, and it automatically needs to push out a pwm output autonomously.

Thanks,

The easier way should be to add an output in your mixer file. A quadrotor mixer usually configs the first 4 pwm outputs, so if you want to use the 5th one, you need to add an extra line setting up a simple mixer https://dev.px4.io/en/airframes/adding_a_new_frame.html#mixer-file.

In your code, you must then publish into actuators_control topic the servo output that you want.

The same works for aux ports, nonetheless, you must config the auxiliar mixer file.

1 Like

Thanks. That worked really well.

1 Like

Firstly, Thanks a lot for both of for creating this question on right channel and Secondly, for guiding along the right path.

With this said, I am trying to operate(code based) a servo at AUX1 & AUX2 ports of my Hexrotor_x, I did try to setup mixer file for AUX ports in the microSD card ‘etc/mixers/epmg.aux.mix’
and tried publishing group_mix=3 , controls[6] & controls[7] direct PWM of 2000us, I see this publishing on mavros/actuator_control topic but when I check mavros/rc/out I still don’t see this 2000 output!!
Wondering what could be the issue?

Can You please guide me…

Enable pass through mixer on servo outputs 1-3

AUX1 channel (select RC channel with RC_MAP_AUX1 param)

M: 1
S: 3 5 10000 10000 0 -10000 10000

AUX2 channel (select RC channel with RC_MAP_AUX2 param)

M: 1
S: 3 6 10000 10000 0 -10000 10000

AUX3 channel (select RC channel with RC_MAP_AUX3 param)

M: 1
S: 3 7 10000 10000 0 -10000 10000

what if im using dynamic allocation?