Help with ArduCopter code! (Make a 180° rotation)

Hi everyone,
I’m new in ardupilot, and I’m trying to understand how to edit the code.
I would like it to make a 180° rotation on his yaw in a specific moment.
I used this command but it doesn’t work, what am I doing wrong?
attitude_control.input_euler_angle_roll_pitch_yaw( 0.0f, 0.0f,18000.0f, false, get_smoothing_gain());
Thank you!

Alex,
That will basically work but it will make it point south. Instead you probably want to get the current yaw and add 180. Of course, if you did that in every loop then it would just keep turning and turning.
The way to get the current heading is to use ahrs.yaw_sensor or ahrs.yaw.

1 Like

Ok!
The fact is that I put this line in the init function of a new flightmode to test if the command works, but the copter stays in position and doesn’t do anything…
I tried to switch into my flight mode starting from different angles, but it doesn’t do anything (nor pointing to south)
Maybe the function can’t be called in a init function? :confused:
Thank you!

@rmackay9
This should work or there is some limit to the max target angle?

bool Copter::alex_init(bool ignore_checks)
{
    rotation_180();

    return true;
}

void Copter::rotation_180()		
	{		
		

	float target_angle = constrain_float(ToDeg(attitude_control.max_angle_step_bf_yaw()*0.75f)*100.0f, 500, 18000);
	float start_angle = ahrs.yaw_sensor;
	attitude_control.input_euler_angle_roll_pitch_yaw( 0.0f, 0.0f, wrap_180_cd(target_angle + start_angle), false, get_smoothing_gain());
       

	}