2016-01-14 15:30:56 -04:00
|
|
|
#include "Sub.h"
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2016-01-14 15:30:56 -04:00
|
|
|
void Sub::init_rc_in()
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
2017-02-03 17:33:27 -04:00
|
|
|
channel_pitch = RC_Channels::rc_channel(0);
|
2017-02-03 00:18:27 -04:00
|
|
|
channel_roll = RC_Channels::rc_channel(1);
|
|
|
|
channel_throttle = RC_Channels::rc_channel(2);
|
|
|
|
channel_yaw = RC_Channels::rc_channel(3);
|
2017-04-05 13:01:09 -03:00
|
|
|
channel_forward = RC_Channels::rc_channel(4);
|
|
|
|
channel_lateral = RC_Channels::rc_channel(5);
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// set rc channel ranges
|
|
|
|
channel_roll->set_angle(ROLL_PITCH_INPUT_MAX);
|
|
|
|
channel_pitch->set_angle(ROLL_PITCH_INPUT_MAX);
|
2017-02-03 00:18:27 -04:00
|
|
|
channel_yaw->set_angle(ROLL_PITCH_INPUT_MAX);
|
|
|
|
channel_throttle->set_range(1000);
|
|
|
|
channel_forward->set_angle(ROLL_PITCH_INPUT_MAX);
|
|
|
|
channel_lateral->set_angle(ROLL_PITCH_INPUT_MAX);
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// set default dead zones
|
2017-04-05 17:25:03 -03:00
|
|
|
channel_roll->set_default_dead_zone(30);
|
|
|
|
channel_pitch->set_default_dead_zone(30);
|
|
|
|
channel_throttle->set_default_dead_zone(30);
|
|
|
|
channel_yaw->set_default_dead_zone(40);
|
|
|
|
channel_forward->set_default_dead_zone(30);
|
|
|
|
channel_lateral->set_default_dead_zone(30);
|
2015-12-30 18:57:56 -04:00
|
|
|
|
2017-02-24 19:09:43 -04:00
|
|
|
#if CONFIG_HAL_BOARD != HAL_BOARD_SITL
|
2016-10-11 17:30:41 -03:00
|
|
|
// initialize rc input to 1500 on control channels (rather than 0)
|
2017-04-05 17:21:34 -03:00
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
hal.rcin->set_override(i, 1500);
|
2016-10-11 17:30:41 -03:00
|
|
|
}
|
2017-04-16 19:22:08 -03:00
|
|
|
|
2017-10-25 22:44:54 -03:00
|
|
|
hal.rcin->set_override(7, 1500); // camera tilt channel
|
2017-10-26 15:24:15 -03:00
|
|
|
|
|
|
|
RC_Channel* chan = RC_Channels::rc_channel(8);
|
|
|
|
uint16_t min = chan->get_radio_min();
|
|
|
|
hal.rcin->set_override(8, min); // lights 1 channel
|
|
|
|
|
|
|
|
chan = RC_Channels::rc_channel(9);
|
|
|
|
min = chan->get_radio_min();
|
|
|
|
hal.rcin->set_override(9, min); // lights 2 channel
|
|
|
|
|
2017-04-16 19:22:08 -03:00
|
|
|
hal.rcin->set_override(10, 1100); // video switch
|
2017-02-24 19:09:43 -04:00
|
|
|
#endif
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|
|
|
|
|
2017-02-03 17:33:27 -04:00
|
|
|
// init_rc_out -- initialise motors and check if pilot wants to perform ESC calibration
|
2016-01-14 15:30:56 -04:00
|
|
|
void Sub::init_rc_out()
|
2015-12-30 18:57:56 -04:00
|
|
|
{
|
|
|
|
motors.set_update_rate(g.rc_speed);
|
2017-02-03 00:18:27 -04:00
|
|
|
motors.set_loop_rate(scheduler.get_loop_rate_hz());
|
2017-11-18 20:17:11 -04:00
|
|
|
motors.init((AP_Motors::motor_frame_class)g.frame_configuration.get(), AP_Motors::motor_frame_type::MOTOR_FRAME_TYPE_PLUS);
|
2017-02-28 14:24:49 -04:00
|
|
|
motors.set_throttle_range(channel_throttle->get_radio_min(), channel_throttle->get_radio_max());
|
2015-12-30 18:57:56 -04:00
|
|
|
|
|
|
|
// enable output to motors
|
2017-09-04 01:17:07 -03:00
|
|
|
if (arming.rc_calibration_checks(true)) {
|
2015-12-30 18:57:56 -04:00
|
|
|
enable_motor_output();
|
|
|
|
}
|
|
|
|
|
|
|
|
// refresh auxiliary channel to function map
|
2017-02-03 00:18:27 -04:00
|
|
|
SRV_Channels::update_aux_servo_function();
|
2015-12-30 18:57:56 -04:00
|
|
|
}
|