Hello,
I am currently trying to use User-Hooks to control a servo. I have a quadcopter and am using the pixhawk controller. However, I can't seem to find the correct command to properly write the signal sent to the servo.
I have found that the ESCs are updated in the fast_loop() in ArduCopter.pde by calling the function set_servos_4(). After following the chain of functions being called, I have come to believe that the values are actually updated in RCOutput.cpp through the function write().
Moving a step backwards in the chain, this function is called in AP_MotorsMatrix.cpp thorugh the output_armed(). The actual line used is:
hal.rcout->write(pgm_read_byte(&_motor_to_channel_map[i]), motor_out[i]);
So to write a value to my servo, I have been trying to use this same call in userhook_SuperSlowLoop() without success. I can't seem to find what the expected values for the parameters are in order to make this call "manually." Additionally, I have printed in the console the values of these every time the function is called by the default operation but I seem to be getting random characters whose values I haven't been able to interpret.
If there's another/better way to write values, I am not aware of it and I would appreciate any help if someone out there has a solution to my problem.
Cheers!
Replies
After a few weeks, I have finally been able to solve this issue. It turns out I was calling the right function but not correctly. After taking a look at how Do_Set_Servo is defined, I managed to do work it out.
So first of all, I connected AUX pin 1 to the servo's input signal, also powering the servo with 5V and GND. (Note: the Pixhawk will not be able tu supply the current demanded by the servo, so for this to work properly, an external source is needed). Then I went to my UserCode.pde file and made the following modification:
#ifdef USERHOOK_SUPERSLOWLOOP
#include "../libraries/AP_HAL_PX4/RCOutput.h"
#include <AP_HAL_PX4.h>
uint16_t pwm = 2000;
void userhook_SuperSlowLoop()
{
uint8_t _channel=9;
pwm = 3000 - pwm;
hal.rcout->enable_ch(_channel-1);
hal.rcout->write(_channel-1, pwm);
}
#endif
Now, I have the servo moving back and forth each second while the drone is in regular flight mode.