Skip to content
Open

x #40

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ArduCopter/AP_Arming_Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ bool AP_Arming_Copter::arm_checks(AP_Arming::Method method)
#if FRAME_CONFIG == HELI_FRAME
if ((copter.flightmode->has_manual_throttle() || copter.flightmode->mode_number() == Mode::Number::DRIFT) && copter.motors->get_takeoff_collective()) {
#else
if ((copter.flightmode->has_manual_throttle() || copter.flightmode->mode_number() == Mode::Number::DRIFT) && copter.channel_throttle->get_control_in() > 0) {
if ((copter.flightmode->has_manual_throttle() || copter.flightmode->mode_number() == Mode::Number::DRIFT) && copter.channel_throttle->norm_input_dz() > 0) {
#endif
check_failed(Check::RC, true, "%s too high", rc_item);
return false;
Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/Attitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ float Copter::get_pilot_desired_climb_rate_ms()
return 0.0f;
}

float throttle_control = copter.channel_throttle->get_control_in();
float throttle_control = copter.channel_throttle->norm_input_dz() * 1000.0f;

#if TOY_MODE_ENABLED
if (g2.toy_mode.enabled()) {
Expand Down
12 changes: 6 additions & 6 deletions ArduCopter/Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,17 +873,17 @@ void Copter::update_simple_mode(void)

if (simple_mode == SimpleMode::SIMPLE) {
// rotate roll, pitch input by -initial simple heading (i.e. north facing)
rollx = channel_roll->get_control_in()*simple_cos_yaw - channel_pitch->get_control_in()*simple_sin_yaw;
pitchx = channel_roll->get_control_in()*simple_sin_yaw + channel_pitch->get_control_in()*simple_cos_yaw;
rollx = channel_roll->norm_input_dz()*simple_cos_yaw - channel_pitch->norm_input_dz()*simple_sin_yaw;
pitchx = channel_roll->norm_input_dz()*simple_sin_yaw + channel_pitch->norm_input_dz()*simple_cos_yaw;
}else{
// rotate roll, pitch input by -super simple heading (reverse of heading to home)
rollx = channel_roll->get_control_in()*super_simple_cos_yaw - channel_pitch->get_control_in()*super_simple_sin_yaw;
pitchx = channel_roll->get_control_in()*super_simple_sin_yaw + channel_pitch->get_control_in()*super_simple_cos_yaw;
rollx = channel_roll->norm_input_dz()*super_simple_cos_yaw - channel_pitch->norm_input_dz()*super_simple_sin_yaw;
pitchx = channel_roll->norm_input_dz()*super_simple_sin_yaw + channel_pitch->norm_input_dz()*super_simple_cos_yaw;
}

// rotate roll, pitch input from north facing to vehicle's perspective
channel_roll->set_control_in(rollx*ahrs.cos_yaw() + pitchx*ahrs.sin_yaw());
channel_pitch->set_control_in(-rollx*ahrs.sin_yaw() + pitchx*ahrs.cos_yaw());
channel_roll->set_norm_in(rollx*ahrs.cos_yaw() + pitchx*ahrs.sin_yaw());
channel_pitch->set_norm_in(-rollx*ahrs.sin_yaw() + pitchx*ahrs.cos_yaw());
}

// update_super_simple_bearing - adjusts simple bearing based on location
Expand Down
6 changes: 3 additions & 3 deletions ArduCopter/RC_Channel_Copter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ bool RC_Channel_Copter::do_aux_function(const AuxFuncTrigger &trigger)
case AUX_FUNC::SAVE_TRIM:
if ((ch_flag == AuxSwitchPos::HIGH) &&
(copter.flightmode->allows_save_trim()) &&
(copter.channel_throttle->get_control_in() == 0)) {
(is_zero(copter.channel_throttle->norm_input_dz()))) {
copter.g2.rc_channels.save_trim();
}
break;
Expand All @@ -237,7 +237,7 @@ bool RC_Channel_Copter::do_aux_function(const AuxFuncTrigger &trigger)
}

// do not allow saving the first waypoint with zero throttle
if (!copter.mode_auto.mission.present() && (copter.channel_throttle->get_control_in() == 0)) {
if (!copter.mode_auto.mission.present() && (is_zero(copter.channel_throttle->norm_input_dz()))) {
break;
}

Expand All @@ -262,7 +262,7 @@ bool RC_Channel_Copter::do_aux_function(const AuxFuncTrigger &trigger)
cmd.content.location = copter.current_loc;

// if throttle is above zero, create waypoint command
if (copter.channel_throttle->get_control_in() > 0) {
if (copter.channel_throttle->norm_input_dz() > 0.0f) {
cmd.id = MAV_CMD_NAV_WAYPOINT;
} else {
// with zero throttle, create LAND command
Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/baro_ground_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Copter::update_ground_effect_detector(void)
UNUSED_RESULT(AP::ahrs().get_relative_position_D_origin_float(pos_d_m));

// if we aren't taking off yet, reset the takeoff timer, altitude and complete flag
const bool throttle_up = flightmode->has_manual_throttle() && channel_throttle->get_control_in() > 0;
const bool throttle_up = flightmode->has_manual_throttle() && channel_throttle->norm_input_dz() > 0.0f;
if (!throttle_up && ap.land_complete) {
gndeffect_state.takeoff_time_ms = tnow_ms;
gndeffect_state.takeoff_alt_m = -pos_d_m;
Expand Down
8 changes: 4 additions & 4 deletions ArduCopter/compassmot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MAV_RESULT Copter::mavlink_compassmot(const GCS_MAVLINK &gcs_chan)

// check throttle is at zero
read_radio();
if (channel_throttle->get_control_in() != 0) {
if (!is_zero(channel_throttle->norm_input_dz())) {
gcs_chan.send_text(MAV_SEVERITY_CRITICAL, "Throttle not zero");
ap.compass_mot = false;
return MAV_RESULT_TEMPORARILY_REJECTED;
Expand Down Expand Up @@ -148,7 +148,7 @@ MAV_RESULT Copter::mavlink_compassmot(const GCS_MAVLINK &gcs_chan)
// pass through throttle to motors
auto &srv = AP::srv();
srv.cork();
motors->set_throttle_passthrough_for_esc_calibration(channel_throttle->get_control_in() * 0.001f);
motors->set_throttle_passthrough_for_esc_calibration(channel_throttle->norm_input_dz());
srv.push();

// read some compass values
Expand All @@ -158,7 +158,7 @@ MAV_RESULT Copter::mavlink_compassmot(const GCS_MAVLINK &gcs_chan)
battery.read();

// calculate scaling for throttle
throttle_pct = (float)channel_throttle->get_control_in() * 0.001f;
throttle_pct = channel_throttle->norm_input_dz();
throttle_pct = constrain_float(throttle_pct,0.0f,1.0f);

// record maximum throttle
Expand Down Expand Up @@ -220,7 +220,7 @@ MAV_RESULT Copter::mavlink_compassmot(const GCS_MAVLINK &gcs_chan)
if (AP_HAL::millis() - last_send_time_ms > 500) {
last_send_time_ms = AP_HAL::millis();
mavlink_msg_compassmot_status_send(gcs_chan.get_chan(),
channel_throttle->get_control_in(),
uint16_t(channel_throttle->norm_input_dz() * 1000.0f),
current,
interference_pct[0],
motor_compensation[0].x,
Expand Down
6 changes: 3 additions & 3 deletions ArduCopter/esc_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Copter::esc_calibration_startup_check()
switch (g.esc_calibrate) {
case ESCCalibrationModes::ESCCAL_NONE:
// check if throttle is high
if (channel_throttle->get_control_in() >= ESC_CALIBRATION_HIGH_THROTTLE) {
if (channel_throttle->norm_input_dz() >= ESC_CALIBRATION_HIGH_THROTTLE * 0.001f) {
// we will enter esc_calibrate mode on next reboot
g.esc_calibrate.set_and_save(ESCCalibrationModes::ESCCAL_PASSTHROUGH_IF_THROTTLE_HIGH);
// send message to gcs
Expand All @@ -48,7 +48,7 @@ void Copter::esc_calibration_startup_check()
break;
case ESCCalibrationModes::ESCCAL_PASSTHROUGH_IF_THROTTLE_HIGH:
// check if throttle is high
if (channel_throttle->get_control_in() >= ESC_CALIBRATION_HIGH_THROTTLE) {
if (channel_throttle->norm_input_dz() >= ESC_CALIBRATION_HIGH_THROTTLE * 0.001f) {
// pass through pilot throttle to escs
esc_calibration_passthrough();
}
Expand Down Expand Up @@ -97,7 +97,7 @@ void Copter::esc_calibration_passthrough()
// pass through to motors
auto &srv = AP::srv();
srv.cork();
motors->set_throttle_passthrough_for_esc_calibration(channel_throttle->get_control_in() * 0.001f);
motors->set_throttle_passthrough_for_esc_calibration(channel_throttle->norm_input_dz());
srv.push();
}
#endif // FRAME_CONFIG != HELI_FRAME
Expand Down
6 changes: 3 additions & 3 deletions ArduCopter/heli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool Copter::should_use_landing_swash() const
void Copter::heli_update_landing_swash()
{
motors->set_collective_for_landing(should_use_landing_swash());
update_collective_low_flag(channel_throttle->get_control_in());
update_collective_low_flag(int16_t(channel_throttle->norm_input_dz() * 1000.0f));
}

// convert motor interlock switch's position to desired rotor speed expressed as a value from 0 to 1
Expand All @@ -148,8 +148,8 @@ float Copter::get_pilot_desired_rotor_speed() const
{
RC_Channel *rc_ptr = rc().find_channel_for_option(RC_Channel::AUX_FUNC::MOTOR_INTERLOCK);
if (rc_ptr != nullptr) {
rc_ptr->set_range(1000);
return (float)rc_ptr->get_control_in() * 0.001f;
rc_ptr->set_range();
return rc_ptr->norm_input_dz();
}
return 0.0f;
}
Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/land_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void Copter::update_throttle_mix()

if (flightmode->has_manual_throttle()) {
// manual throttle
if (channel_throttle->get_control_in() <= 0 && air_mode != AirMode::AIRMODE_ENABLED) {
if (channel_throttle->norm_input_dz() <= 0.0f && air_mode != AirMode::AIRMODE_ENABLED) {
attitude_control->set_throttle_mix_min();
} else {
attitude_control->set_throttle_mix_man();
Expand Down
3 changes: 2 additions & 1 deletion ArduCopter/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,8 @@ float Mode::get_pilot_desired_throttle() const
mid_stick = 500;
}

int16_t throttle_control = channel_throttle->get_control_in();
// norm_input_dz() on a RANGE channel: 0 at bottom with deadzone, 1 at top; does not use trim
int16_t throttle_control = int16_t(channel_throttle->norm_input_dz() * 1000.0f);
// ensure reasonable throttle values
throttle_control = constrain_int16(throttle_control,0,1000);

Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/mode_acro_heli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void ModeAcro_Heli::run()
}

// get pilot's desired throttle
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(channel_throttle->get_control_in());
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(int16_t(channel_throttle->norm_input_dz() * 1000.0f));

// output pilot's throttle without angle boost
attitude_control->set_throttle_out(pilot_throttle_scaled, false, g.throttle_filt);
Expand Down
5 changes: 2 additions & 3 deletions ArduCopter/mode_drift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ void ModeDrift::run()
vel_right_ms = constrain_float(vel_right_ms, -DRIFT_SPEEDLIMIT_MS, DRIFT_SPEEDLIMIT_MS);
vel_forward_ms = constrain_float(vel_forward_ms, -DRIFT_SPEEDLIMIT_MS, DRIFT_SPEEDLIMIT_MS);

// roll_input from yaw stick (convert centidegrees -> radians before LP)
// (channel_yaw->get_control_in() returns centidegrees)
const float yaw_stick_rad = cd_to_rad((float)channel_yaw->get_control_in());
// roll_input from yaw stick (convert to radians before LP)
const float yaw_stick_rad = cd_to_rad(channel_yaw->norm_input_dz() * 4500.0f);
roll_input_rad = roll_input_rad * 0.96f + yaw_stick_rad * 0.04f;

// convert user input into desired roll velocity term (m/s equivalent)
Expand Down
8 changes: 4 additions & 4 deletions ArduCopter/mode_flip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ bool ModeFlip::init(bool ignore_checks)
roll_dir = pitch_dir = 0;

// choose direction based on pilot's roll and pitch sticks
if (channel_pitch->get_control_in() > 300) {
if (channel_pitch->norm_input_dz() > 300.0f/4500.0f) {
pitch_dir = FLIP_PITCH_BACK;
} else if (channel_pitch->get_control_in() < -300) {
} else if (channel_pitch->norm_input_dz() < -300.0f/4500.0f) {
pitch_dir = FLIP_PITCH_FORWARD;
} else if (channel_roll->get_control_in() >= 0) {
} else if (channel_roll->norm_input_dz() >= 0.0f) {
roll_dir = FLIP_ROLL_RIGHT;
} else {
roll_dir = FLIP_ROLL_LEFT;
Expand Down Expand Up @@ -219,7 +219,7 @@ void ModeFlip::abandon_flip()

bool ModeFlip::input_is_high_magnitude(RC_Channel &input) const
{
return abs(input.get_control_in()) >= 4000;
return fabsf(channel_roll->norm_input_dz()) >= 4000.0f/4500.0f;
}

#endif
6 changes: 3 additions & 3 deletions ArduCopter/mode_flowhold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ void ModeFlowHold::run()
Vector2f bf_angles_rad;

// calculate alt-hold angles
int16_t roll_in = copter.channel_roll->get_control_in();
int16_t pitch_in = copter.channel_pitch->get_control_in();
const float roll_in = copter.channel_roll->norm_input_dz();
const float pitch_in = copter.channel_pitch->norm_input_dz();
const float angle_max_rad = copter.attitude_control->lean_angle_max_rad();

float target_roll_rad, target_pitch_rad;
Expand All @@ -337,7 +337,7 @@ void ModeFlowHold::run()
// don't use for first 3s when we are just taking off
Vector2f flow_angles;

flowhold_flow_to_angle(flow_angles, (roll_in != 0) || (pitch_in != 0));
flowhold_flow_to_angle(flow_angles, !is_zero(roll_in) || !is_zero(pitch_in));
flow_angles.x = constrain_float(flow_angles.x, -angle_max_rad/2, angle_max_rad/2);
flow_angles.y = constrain_float(flow_angles.y, -angle_max_rad/2, angle_max_rad/2);
bf_angles_rad += flow_angles;
Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/mode_stabilize_heli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void ModeStabilize_Heli::run()
float target_yaw_rate_rads = get_pilot_desired_yaw_rate_rads();

// get pilot's desired throttle
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(channel_throttle->get_control_in());
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(int16_t(channel_throttle->norm_input_dz() * 1000.0f));

// Tradheli should not reset roll, pitch, yaw targets when motors are not runup while flying, because
// we may be in autorotation flight. This is so that the servos move in a realistic fashion while disarmed
Expand Down
2 changes: 1 addition & 1 deletion ArduCopter/mode_systemid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void ModeSystemId::run()

// get pilot's desired throttle
#if FRAME_CONFIG == HELI_FRAME
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(channel_throttle->get_control_in());
pilot_throttle_scaled = copter.input_manager.get_pilot_desired_collective(int16_t(channel_throttle->norm_input_dz() * 1000.0f));
#else
pilot_throttle_scaled = get_pilot_desired_throttle();
#endif
Expand Down
4 changes: 2 additions & 2 deletions ArduCopter/motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void Copter::auto_disarm_check()
thr_low = ap.throttle_zero;
} else {
float deadband_top = get_throttle_mid() + g.throttle_deadzone;
thr_low = channel_throttle->get_control_in() <= deadband_top;
thr_low = channel_throttle->norm_input_dz() * 1000.0f <= deadband_top;
}

if (!thr_low || !ap.land_complete) {
Expand Down Expand Up @@ -137,7 +137,7 @@ void Copter::lost_vehicle_check()
}

// ensure throttle is down, motors not armed, pitch and roll rc at max. Note: rc1=roll rc2=pitch
if (ap.throttle_zero && !motors->armed() && (channel_roll->get_control_in() > 4000) && (channel_pitch->get_control_in() > 4000)) {
if (ap.throttle_zero && !motors->armed() && (channel_roll->norm_input_dz() > 4000.0f/4500.0f) && (channel_pitch->norm_input_dz() > 4000.0f/4500.0f)) {
if (soundalarm_counter >= LOST_VEHICLE_DELAY) {
if (AP_Notify::flags.vehicle_lost == false) {
AP_Notify::flags.vehicle_lost = true;
Expand Down
25 changes: 17 additions & 8 deletions ArduCopter/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void Copter::init_rc_in()
channel_yaw = &rc().get_yaw_channel();

// set rc channel ranges
channel_roll->set_angle(ROLL_PITCH_YAW_INPUT_MAX);
channel_pitch->set_angle(ROLL_PITCH_YAW_INPUT_MAX);
channel_yaw->set_angle(ROLL_PITCH_YAW_INPUT_MAX);
channel_throttle->set_range(1000);
channel_roll->set_angle();
channel_pitch->set_angle();
channel_yaw->set_angle();
channel_throttle->set_range();

#if AP_RC_TRANSMITTER_TUNING_ENABLED
rc_tuning = rc().find_channel_for_option(RC_Channel::AUX_FUNC::TRANSMITTER_TUNING);
Expand Down Expand Up @@ -97,13 +97,13 @@ void Copter::read_radio()
ap.new_radio_frame = true;

set_throttle_and_failsafe(channel_throttle->get_radio_in());
set_throttle_zero_flag(channel_throttle->get_control_in());
set_throttle_zero_flag(int16_t(channel_throttle->norm_input_dz() * 1000.0f));

// pass pilot input through to motors (used to allow wiggling servos while disarmed on heli, single, coax copters)
radio_passthrough_to_motors();

const float dt = (tnow_ms - last_radio_update_ms)*1.0e-3f;
rc_throttle_control_in_filter.apply(channel_throttle->get_control_in(), dt);
rc_throttle_control_in_filter.apply(channel_throttle->norm_input_dz() * 1000.0f, dt);
last_radio_update_ms = tnow_ms;
return;
}
Expand Down Expand Up @@ -201,7 +201,7 @@ void Copter::radio_passthrough_to_motors()
{
motors->set_radio_passthrough(channel_roll->norm_input(),
channel_pitch->norm_input(),
channel_throttle->get_control_in_zero_dz()*0.001f,
channel_throttle->norm_input(),
channel_yaw->norm_input());
}

Expand All @@ -215,5 +215,14 @@ int16_t Copter::get_throttle_mid(void)
return g2.toy_mode.get_throttle_mid();
}
#endif
return channel_throttle->get_control_mid();
// Use the geometric mid-point of the PWM range (matches original get_control_mid() behaviour).
// radio_trim is intentionally not used — it affects feel but not stick centre.
const int16_t r_min = channel_throttle->get_radio_min();
const int16_t r_max = channel_throttle->get_radio_max();
const int16_t r_mid = (r_min + r_max) / 2;
const int16_t dead_zone_top = r_min + int16_t(channel_throttle->get_dead_zone());
if (dead_zone_top >= r_max || r_mid <= dead_zone_top) {
return 500;
}
return int16_t(1000.0f * float(r_mid - dead_zone_top) / float(r_max - dead_zone_top));
}
10 changes: 5 additions & 5 deletions ArduCopter/toy_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ void ToyMode::update()

// we use 150 for throttle_at_min to cope with varying stick throws
bool throttle_at_min =
copter.channel_throttle->get_control_in() < 150;
copter.channel_throttle->norm_input_dz() < 0.15f;

// throttle threshold for throttle arming
bool throttle_near_max =
copter.channel_throttle->get_control_in() > 700;
copter.channel_throttle->norm_input_dz() > 0.7f;

/*
disarm if throttle is low for 1 second when landed
Expand Down Expand Up @@ -799,9 +799,9 @@ void ToyMode::action_arm(void)
// don't arm if sticks aren't in deadzone, to prevent pot problems
// on TX causing flight control issues
bool sticks_centered =
copter.channel_roll->get_control_in() == 0 &&
copter.channel_pitch->get_control_in() == 0 &&
copter.channel_yaw->get_control_in() == 0;
is_zero(copter.channel_roll->norm_input_dz()) &&
is_zero(copter.channel_pitch->norm_input_dz()) &&
is_zero(copter.channel_yaw->norm_input_dz());

if (!sticks_centered) {
gcs().send_text(MAV_SEVERITY_ERROR, "Tmode: sticks not centered");
Expand Down
Loading
Loading