RC_Channel Detailed Reference¶
Header¶
File: libraries/RC_Channel/RC_Channel.h
#include <RC_Channel.h>
Class Documentation¶
Warning
doxygenclass: Cannot find class “RC_Channel” in doxygen xml output for project “ArduPilot” from directory: /home/runner/work/APMapi/APMapi/docs/../build/output-xml
Detailed Description¶
RC_Channel handles RC (Radio Control) input and output channels. It provides functions for reading pilot input from RC receivers and converting them to normalized values for use in flight control.
Key Features:
PWM input reading from RC receivers
Normalized output (-1 to 1 or 0 to 1)
Dead zone handling
Stick mixing
Override support (GCS/manual control)
Channel limiting and scaling
Inheritance¶
RC_Channel is part of the RC_Channel class hierarchy:
RC_Channel - Base channel - RC_Channel_Video - Video channel - RC_Channel_aux - Auxiliary channel
Public Member Functions¶
Input Reading¶
-
int16_t RC_Channel::get_radio_in() const¶
Get raw PWM input value from receiver.
- Returns:
PWM value (typically 1000-2000)
-
void RC_Channel::set_radio_in(int16_t val)¶
Set radio input value (typically called by driver).
- Parameters:
val – PWM value
-
int16_t RC_Channel::get_radio_min() const¶
Get configured minimum PWM value.
- Returns:
Minimum PWM value
-
int16_t RC_Channel::get_radio_max() const¶
Get configured maximum PWM value.
- Returns:
Maximum PWM value
-
bool RC_Channel::update(void)¶
Update channel values. Should be called each loop.
- Returns:
true if update successful
Normalized Input¶
-
float RC_Channel::norm_input() const¶
Get normalized input value (-1 to 1 for roll/pitch/yaw, 0 to 1 for throttle).
- Returns:
Normalized value
-
float RC_Channel::norm_input_dz() const¶
Get normalized input with dead zone applied.
- Returns:
Normalized value with dead zone
-
bool RC_Channel::in_min_dz() const¶
Check if input is in minimum dead zone.
- Returns:
true if in dead zone at minimum
-
uint8_t RC_Channel::percent_input() const¶
Get input as percentage (0-100%).
- Returns:
Percentage
Control Input¶
-
int16_t RC_Channel::get_control_in() const¶
Get control input value (after scaling/dead zone).
- Returns:
Control value
-
void RC_Channel::set_control_in(int16_t val)¶
Set control input value.
- Parameters:
val – Control value
-
float RC_Channel::get_control_in_zero_dz(void) const¶
Get control input with dead zone at center.
- Returns:
Control value
Configuration¶
-
void RC_Channel::set_range(uint16_t high)¶
Set output range.
- Parameters:
high – Maximum output value
-
void RC_Channel::set_angle(uint16_t angle)¶
Set angle mode (output in degrees instead of PWM).
- Parameters:
angle – Maximum angle in degrees
-
void RC_Channel::set_default_dead_zone(int16_t dzone)¶
Set default dead zone.
- Parameters:
dzone – Dead zone size
-
uint16_t RC_Channel::get_dead_zone(void) const¶
Get configured dead zone.
- Returns:
Dead zone size
-
bool RC_Channel::get_reverse(void) const¶
Get reverse flag.
- Returns:
true if channel is reversed
Override (GCS Control)¶
-
void RC_Channel::set_override(const uint16_t v, const uint32_t timestamp_ms)¶
Set override value from GCS.
- Parameters:
v – Override PWM value
timestamp_ms – Timestamp of override
-
void RC_Channel::clear_override()¶
Clear override, return to RC input.
-
bool RC_Channel::has_override() const¶
Check if override is active.
- Returns:
true if override is active
Stick Mixing¶
-
float RC_Channel::stick_mixing(const float servo_in)¶
Apply stick mixing.
- Parameters:
servo_in – Servo input value
- Returns:
Mixed value
Usage Example¶
#include <RC_Channel.h>
// Get RC channel pointers
RC_Channel *rc_ch1 = RC_Channel::rc_channel(0); // Channel 1
RC_Channel *rc_ch2 = RC_Channel::rc_channel(1); // Channel 2
RC_Channel *rc_ch3 = RC_Channel::rc_channel(2); // Channel 3 (throttle)
RC_Channel *rc_ch4 = RC_Channel::rc_channel(3); // Channel 4 (yaw)
void setup() {
// Configure channels
rc_ch1->set_range(1000); // Set output range
rc_ch3->set_angle(1000); // Throttle as 0-1000
}
void loop() {
// Update RC channels
rc_ch1->update();
rc_ch2->update();
rc_ch3->update();
rc_ch4->update();
// Read normalized input (-1 to 1 or 0 to 1)
float roll = rc_ch1->norm_input(); // -1 to 1
float pitch = rc_ch2->norm_input(); // -1 to 1
float throttle = rc_ch3->norm_input(); // 0 to 1
float yaw = rc_ch4->norm_input(); // -1 to 1
// Or read raw PWM values
int16_t roll_pwm = rc_ch1->get_radio_in(); // typically 1000-2000
// Check for override (GCS control)
if (rc_ch1->has_override()) {
// GCS is controlling this channel
}
// Read control input (after dead zone)
int16_t control = rc_ch1->get_control_in();
}
See Also¶
Control Libraries - Overview of control libraries
Communication Libraries - RC input protocols
RC_Channel_aux - Auxiliary channel handling
SRV_Channel - Servo output channels
AP_RCProtocol - RC input protocols (PPM, SBUS, CRSF, etc.)