A strange problem when turn to next point in auto mode

Hello, everyone.
I encountered a strange problem.
When the aircraft executes auto mode, when the aircraft reaches avionics and wants to fly to the next waypoint, it will turn its nose in the opposite direction. For example, when the next waypoint is on the left side of the plane, the plane will turn left when it reaches the current waypoint, but on my plane, it will turn to the right so that when it reaches the waypoint and is ready to fly to the next waypoint, the plane will turn 360 degrees at the current waypoint and then fly to the next waypoint. So confused!Does anyone know what caused it? Thank you firstMy log is here.my_log

Do you have a tlog from this flight? It is hard to tell if you have a compass orientation issue, or if the RC4 input is over-riding the yaw controller due to RC4 deadzone being set too tight.

Oh,dear ChrisOlson,Thank you for your reply. I only have the Data Flish log file, which is attached to my question area and is now placed here my Dataflash log

From the log file analysis, the given YAW value is very consistent with the actual YAW value, and it can be concluded that the given YAW is wrong, but I don’t know what causes the given YAW value to be wrong.
In the course of flight, the flight path of the Copter is accurate, but when it reaches a Waypoint and turns to the next waypoint , its rotation direction is wrong,just like to be opposite. This problem has been bothering me for a long time.

Well, there’s a couple things I can think of that would cause it. One is if you have RC4 reversed in your RC to get the rudder servo to go the right direction with stick control. But it is backwards for the autopilot. The only channel in the RC radio that normally needs to be reversed to get things to go the right direction is the elevator channel (2). Any other reversing of servos should be done with the SERVOx_REVERSED parameters.

The above can be verified by picking the helicopter up in Stabilize flight mode and yawing it side to side by hand, observing which way the rudder servo corrects to hold a heading. If is backwards, then SERVO4_REVERSED needs to be set to 1

The other thing would be if you have a GPS unit with the mag chip installed wrong in it, or are using the wrong AHRS_ORIENTATION for the controller or wrong compass orientation. You could refer to the Wiki on how to check your mag x, y, z values to make sure they go the right direction when you pitch, roll and yaw the aircraft.

http://ardupilot.org/copter/docs/common-compass-setup-advanced.html

Oh,thank you very much for your reply.The reason coursed this problem was found by reviewing the code in the AC_WPNAV.cpp file. I think there is a bug in the function as follows.(The vesion of the code is copter3.5.7)
float AC_WPNav::get_bearing_cd(const Vector3f &origin, const Vector3f &destination) const
{
float bearing = 9000 + atan2f(-(destination.x-origin.x), destination.y-origin.y) * 5729.57795f;
if (bearing < 0) {
bearing += 36000;
}
return bearing;
}
well,in statement ‘atan2f(-(destination.x-origin.x), destination.y-origin.y)’ there the order of the actual parameters are opposite,and the calculation will be totally wrong.

I found that this bug was fixed in 3.6. So thank you very much again for your work.

I have used Arducopter 3.5.7 on 2 Helicopters and a drone for Missions. All those missions worked as planned. Nothing like what you have experienced. That means the code is OK. You better check what Chris is referring to.