Pixhawk6c direction issue

I am using a Holybro x500 v2 with a pixhawk 6c and a M10 GPS. I am trying to do autonomous missions with the ‘Attitude time’ command.
The mission I have created is as follow: 1. DO_CHANGE_SPEED (type 0, speed 1m/s, I am not sure what this does) 2. TAKEOFF (alt 1) 3. DELAY (0.25 s) 4. ATTITUDE_TIME (time 1s, Roll 0, Pitch 0, Yaw 22, ClimbRate 0) 5. ATTITUDE_TIME (time 1s, Roll 0, Pitch -15, Yaw 22, ClimbRate 0) 6. Land
I set the Yaw to 22 because I thought the drone initially turned to 0 degrees North, but this did not work. When it took off, the drone turned to 330 degrees, so in order to get to the correct heading, I had to set Yaw to 52.
However, what I found was that while the front of the drone pointed in the correct direction (22 degrees) when I set Yaw to 52, the drone actually traveled in the direction that seemed like 52 degrees. Similarly, when I set Yaw to 22, the front of the drone pointed towards 0 Degrees North but travels in the 22 degrees direction.
Why does this happen even though I have set Roll to 0?
One thing I thought might be the issue was a bad compass calibration. The other thing I thought might be interfering was an electrical line that runs near where I was flying that I thought could be creating a magnetic field that messes up the Pixhawk’s Compass.
Please help me with this.