Query on implementation of sport mode

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.

You really need Leonard to comment on this as it’s his code. I have trouble understanding that part myself, though I understand most of the rest of the dynamics code (and wrote some of it). But that part… I can’t follow.

Thanks, hopefully he might notice this post. Basically I’ve built a quad from kit frame and some other parts and am coding a controller on an arduino Mega 2560. I know it would be easiest just to use your software as it is, but for me the process of bolting the sensor/dynamics/control code together is the fun learning part. However I know it would be madness to start from scratch, so I thought I’d scour the existing open source material to learn how its done. Sport mode looked like it would give something flyable by a noob, hence my interest in this section.

Hi Twistor,

To stop the copter from leveling in Sport Mode you need to reduce Acro_Balance_Roll and Pitch to zero. This then remove the auto level.

For filming using Yaw to “drive” around I like to set roll to 0.25 and pitch to 0.

Hope this goes some way to explaining what is happening.

Let me know if you have any more questions.

Thanks, yes, makes perfect sense. I wasn’t considering the case of g.acro_balance_roll = 0.