Pixhawk PWM Output Programatically

Hi All,

I have a raspberry pi communicating over Serial with my Pixhawk. That works fine. The Pixhawk reads the received serial character and depending on the charecter should output a pwm signal to a Servo.

However the code I am using fails to move the Servos. I know the Servos are functional because I tested them with my arduino uno. I have tried multiple wiring setups including powering and grounding the servos directly to a 5v BEC as well as using the 5v rail of the Pixhawk like done here:

I have tried outputting the pwm signal with Hal.rcout to pins 1-14 and 50-61 using code like so:

include <AP_HAL/AP_HAL.h

const AP_HAL::HAL& hal = AP_HAL::get_HAL();

void setup (void)
{
hal.console->println(“Starting AP_HAL::RCOutput test”);
for (uint8_t i=0; i<14; i++) {
hal.rcout->enable_ch(i);
}
}

static uint16_t pwm = 1500;
static int8_t delta = 1;

void loop (void)
{
uint8_t i;
for (i=0; i<14; i++) {
hal.rcout->write(i, pwm);
pwm += delta;
if (delta > 0 && pwm >= 2000) {
delta = -1;
hal.console->printf(“reversing\n”);
} else if (delta < 0 && pwm <= 1000) {
delta = 1;
hal.console->printf(“reversing\n”);
}
}
hal.scheduler->delay(5);
}

AP_HAL_MAIN();

(Note on above code, I had to change the include statement for formatting, also when I tried the pins 50-75 I just changed the for loop. I also removed the R pi serial reading to make it more focused on this topic)

So I have a few questions:

  • How do I know what pin to use for the pixhawk Aux Outs?
    *I had found a diagram showing all the out pins as 50 and up, but the example code uses 1 to 11…

  • I just purchased a 3.3 to 5v level converter form sparkfun for ~2 dollars. Do I need to use this for the servo signal?
    *I didnt think I did…

  • Am I even using the right pins? The above photo shows the servo hooked up to the Aux out pins.
    *During my tests I had servos hooked up to multiple pins to see if any were working, not just the Aux pins.

  • Any other information I can provide that would be usefull? Should I post on a different board? Mods if I would be better off posting this on the rover board I will xpost.

I just want to be able to programmatically control my rovers servos with my pixhawk and it is acting much more difficult than my arduino. Any advice would be much appreciated!

im trying to do the similar thing now but the change is im connecting my esc to moyor itself and the arduino provides inputs to the pixhawk. The pixhawk should send signal to the motors according to these inputs. help me im stuck