CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduSub/radio.cpp
Views: 1798
1
#include "Sub.h"
2
3
void Sub::init_rc_in()
4
{
5
channel_pitch = RC_Channels::rc_channel(0);
6
channel_roll = RC_Channels::rc_channel(1);
7
channel_throttle = RC_Channels::rc_channel(2);
8
channel_yaw = RC_Channels::rc_channel(3);
9
channel_forward = RC_Channels::rc_channel(4);
10
channel_lateral = RC_Channels::rc_channel(5);
11
12
// set rc channel ranges
13
channel_roll->set_angle(ROLL_PITCH_INPUT_MAX);
14
channel_pitch->set_angle(ROLL_PITCH_INPUT_MAX);
15
channel_yaw->set_angle(ROLL_PITCH_INPUT_MAX);
16
channel_throttle->set_range(1000);
17
channel_forward->set_angle(ROLL_PITCH_INPUT_MAX);
18
channel_lateral->set_angle(ROLL_PITCH_INPUT_MAX);
19
20
// set default dead zones
21
channel_roll->set_default_dead_zone(30);
22
channel_pitch->set_default_dead_zone(30);
23
channel_throttle->set_default_dead_zone(30);
24
channel_yaw->set_default_dead_zone(40);
25
channel_forward->set_default_dead_zone(30);
26
channel_lateral->set_default_dead_zone(30);
27
28
#if CONFIG_HAL_BOARD != HAL_BOARD_SITL
29
// initialize rc input to 1500 on control channels (rather than 0)
30
for (int i = 0; i < 6; i++) {
31
RC_Channels::set_override(i, 1500);
32
}
33
34
RC_Channels::set_override(6, 1500); // camera pan channel
35
RC_Channels::set_override(7, 1500); // camera tilt channel
36
37
RC_Channel* chan = RC_Channels::rc_channel(8);
38
uint16_t min = chan->get_radio_min();
39
RC_Channels::set_override(8, min); // lights 1 channel
40
41
chan = RC_Channels::rc_channel(9);
42
min = chan->get_radio_min();
43
RC_Channels::set_override(9, min); // lights 2 channel
44
45
RC_Channels::set_override(10, 1100); // video switch
46
#endif
47
}
48
49
// init_rc_out -- initialise motors and check if pilot wants to perform ESC calibration
50
void Sub::init_rc_out()
51
{
52
motors.set_update_rate(g.rc_speed);
53
motors.init((AP_Motors::motor_frame_class)g.frame_configuration.get(), AP_Motors::motor_frame_type::MOTOR_FRAME_TYPE_PLUS);
54
motors.convert_pwm_min_max_param(channel_throttle->get_radio_min(), channel_throttle->get_radio_max());
55
motors.update_throttle_range();
56
57
// enable output to motors
58
if (arming.rc_calibration_checks(true)) {
59
enable_motor_output();
60
}
61
62
// refresh auxiliary channel to function map
63
SRV_Channels::update_aux_servo_function();
64
}
65
66