First post here, so I hope I get this right.
I downloaded the latest version as of today (24th March) from GitHub, so I assume it’s version 3.1 (not sure where to look in the code for the version number to check). I was looking at control_sport.pde, and came across this section (lines 30-55):
[code]
// get pilot’s desired roll and pitch rates
// calculate rate requests
target_roll_rate = g.rc_1.control_in * g.acro_rp_p;
target_pitch_rate = g.rc_2.control_in * g.acro_rp_p;
int32_t roll_angle = wrap_180_cd(ahrs.roll_sensor);
target_roll_rate = -constrain_int32(roll_angle, -ACRO_LEVEL_MAX_ANGLE, ACRO_LEVEL_MAX_ANGLE) * g.acro_balance_roll;
// Calculate trainer mode earth frame rate command for pitch
int32_t pitch_angle = wrap_180_cd(ahrs.pitch_sensor);
target_pitch_rate = -constrain_int32(pitch_angle, -ACRO_LEVEL_MAX_ANGLE, ACRO_LEVEL_MAX_ANGLE) * g.acro_balance_pitch;
if (roll_angle > aparm.angle_max){
target_roll_rate -= g.acro_rp_p*(roll_angle-aparm.angle_max);
}else if (roll_angle < -aparm.angle_max) {
target_roll_rate -= g.acro_rp_p*(roll_angle+aparm.angle_max);
}
if (pitch_angle > aparm.angle_max){
target_pitch_rate -= g.acro_rp_p*(pitch_angle-aparm.angle_max);
}else if (pitch_angle < -aparm.angle_max) {
target_pitch_rate -= g.acro_rp_p*(pitch_angle+aparm.angle_max);
}[/code]
As I understand it, we first get the desired roll and pitch rates from the pilot commands, but then what I don’t get is that in the next lines, we immediately replace them by angles read from sensors.
I believe in sport mode, we interpret the stick input as a rate, so I don’t understand the lines
[code] target_roll_rate = -constrain_int32(roll_angle, -ACRO_LEVEL_MAX_ANGLE, ACRO_LEVEL_MAX_ANGLE) * g.acro_balance_roll;
target_pitch_rate = -constrain_int32(pitch_angle, -ACRO_LEVEL_MAX_ANGLE, ACRO_LEVEL_MAX_ANGLE) * g.acro_balance_pitch;[/code]
Any insight gratefully received.