ChrisRowland
Member
I'm trying to set up an autopilot that will cause a vessel to be pointed in a specified direction.
So far I'm trying to specify a direction as a vector in the local horizon system which I can use to get vessel pitch, yaw and eventually bank errors. I don't want to use GetPitch() and GetYaw() because these don't work when the pitch is 90 deg.
It looks as if HorizonInvRot will give me what I want. I specify the direction I want to point in the local horizon coordinates and HorizonInvRotate gives me a vector defining that direction in my vessel coordinates. As my vessel rotates the direction changes and I can use that to get the pitch and yaw errors.
This is fine for yaw, at least when the vessel has a pitch of zero, but doesn't seem to give me any pitch information. If I pitch my vessel up by 10 degrees I would expect that from my vessel a horizontal direction would be at a pitch angle of -10 deg, but it doesn't. It stays with a pitch of zero.
Here's a code fragment:
If I set target to 0 0 1 I expect that the direction is pointing to the East horizon and if my vessel is pointing in that direction the error vector is -1 0 0, z and x give me an angle about the y axis. But this doesn't work for pitch. pitching up or down doesn't really change anything. I actually see x and y changing with roll.
What I am taking away from this is that I don't understand how these rotate transforms work. I had expected that HorizonInvRotate would cause a direction to change relative to my vessel direction as the vessel changes direction. While it does it doesn't do so in a way that makes sense to me.
What I'd appreciate is some pointers to how I should implement this. Is there a solution involving HorizInvRot or is there a better way?
Thanks,
Chris
So far I'm trying to specify a direction as a vector in the local horizon system which I can use to get vessel pitch, yaw and eventually bank errors. I don't want to use GetPitch() and GetYaw() because these don't work when the pitch is 90 deg.
It looks as if HorizonInvRot will give me what I want. I specify the direction I want to point in the local horizon coordinates and HorizonInvRotate gives me a vector defining that direction in my vessel coordinates. As my vessel rotates the direction changes and I can use that to get the pitch and yaw errors.
This is fine for yaw, at least when the vessel has a pitch of zero, but doesn't seem to give me any pitch information. If I pitch my vessel up by 10 degrees I would expect that from my vessel a horizontal direction would be at a pitch angle of -10 deg, but it doesn't. It stays with a pitch of zero.
Here's a code fragment:
C++:
// for now only for rotation wrt the local horizon frame
vessel->HorizonInvRot(target, error);
yawErr = atan2(error.z, -error.x);
pitchErr = atan2(error.y, error.z);
What I am taking away from this is that I don't understand how these rotate transforms work. I had expected that HorizonInvRotate would cause a direction to change relative to my vessel direction as the vessel changes direction. While it does it doesn't do so in a way that makes sense to me.
What I'd appreciate is some pointers to how I should implement this. Is there a solution involving HorizInvRot or is there a better way?
Thanks,
Chris