Spaceship controls -> autopilot

Started by
17 comments, last by scippie 4 years, 10 months ago
8 hours ago, scippie said:

What I mean is that quaternions don't work in the yaw/pitch/roll sense. I know you can construct a quaternion from them, but then you could as well be using matrices and have gimbal lock problems.

I'm not sure based on the above whether you're operating under this particular misconception (if not, apologies, and please ignore this), but I'll go ahead and mention that quaternions and matrices don't differ from one another with respect to gimbal lock. You can both encounter and avoid gimbal lock with each, and for the same reasons. (Historically at least there's been a fair amount of confusion about this, so I think it's worth clarifying.)

Advertisement
55 minutes ago, Zakwayda said:

I'm not sure based on the above whether you're operating under this particular misconception (if not, apologies, and please ignore this), but I'll go ahead and mention that quaternions and matrices don't differ from one another with respect to gimbal lock. You can both encounter and avoid gimbal lock with each, and for the same reasons. (Historically at least there's been a fair amount of confusion about this, so I think it's worth clarifying.)

Ok, you are right, I have really been expressing myself completely incorrectly. Of course, quaternions and matrices are the same for rotation and can both prevent gimbal lock. What I really meant to say was working with yaw, pitch and roll with a constant reference is different and will also cause gimbal lock.

But, I really do understand it, no worries ?

2 hours ago, scippie said:

Cool! Yes please, share your code! ?

My quaternion code is here: https://github.com/daid/SeriousProton2/blob/master/include/sp2/math/quaternion.h

Vector3 is also there. Note that my "toAxisAngle()" function multiplies the axis (which is a normalized vector) with the angle (which is the amount of rotation) which is why it can only return a Vector3 instead of returning a Vector3 and a scalar (double) for a proper axis+angle.

My X+ is "forwards" and "Z+" is up. Not sure how much that matters.

Simplified code is then:


Vector3d target_position = ???;

Quaterniond target_rotation = Quaterniond::fromVectorToVector(Vector3d(1, 0, 0), target_position);
Vector3d rotation_required = getRotation3D().diff(target_rotation).toAxisAngle();

double roll = rotation_required.x;
double pitch = rotation_required.y;
double yaw = rotation_required.z;

I limit the roll/pitch/yaw each update, and recalculate the "rotation_required" each update. Due to some damping and acceleration I get a bit of overshoot. But that's due to other things my code is doing as well, I think the math here is sound otherwise.

8 minutes ago, Daid said:

My quaternion code is here...

Thanks!

Did you try pooling objects that interact with the ship collider at thrust points, the rate of SetActive of the thruster particles, bounce off the collider and cause the ship to move in the opposite direction. I have not tried this solution it may be terribly inefficient and lack stability or control. It may allow for more realistic thrust.

"When the going gets tough, get a beer"
1 hour ago, Wcoltd said:

Did you try pooling objects that interact with the ship collider at thrust points, the rate of SetActive of the thruster particles, bounce off the collider and cause the ship to move in the opposite direction. I have not tried this solution it may be terribly inefficient and lack stability or control. It may allow for more realistic thrust.

The thrust in my implementation is fine, it's controlling it on auto-pilot that is the problem.

1 hour ago, scippie said:

The thrust in my implementation is fine, it's controlling it on auto-pilot that is the problem.

So you're trying to emulate the same flight characteristics on Autopilot as when you are flying manually? Can you post the code for manual flight? I've got an idea.

"When the going gets tough, get a beer"

I am currently looking into a non-mathematical way to solve this problem as it does not really seem to be something that can be solved straightforward.

This topic is closed to new replies.

Advertisement