Monday, October 1, 2018

physics - Changing orientation by applying torques


Suppose you've got an object floating freely in space. You have a vector you want this object to point towards, and a vector representing the direction it's currently facing. From these two, you can get the rotation (matrix, quaternion, whatever) that represents the change in orientation to bring the two vectors into alignment.


If you only have the ability to apply torque (derivative of angular velocity) to your object, what's a good algorithm for applying torque over time that won't over/undershoot the destination?


(In this case, it's a space ship that wants to automatically orient itself in the direction of travel using thrusters. Roll is irrelevant.)



Answer



This can be handled like the similar case for linear acceleration.



First fact to note: Because the ship starts off with an angular velocity of zero, an you want it to end up with an angular velocity of zero, this means that the total change in velocity must equal zero.


From this we can see that the integral of the acceleration over time must equal zero -- there must be exactly as "much" positive acceleration as there is negative acceleration.


Therefore, your solution, whatever it is, must be constrained to this property: Equal "total" acceleration forwards and backwards.


Here is what the shape of your acceleration over time graph should follow:


Graph of acceleration over time


Looking at this, there are so many possible forms and shapes your acceleration could be in! Let us make some assumptions for the shape of acceleration that you want, in order to give an easy/concise answer.


For the sake of a simple answer, I will have acceleration be in one of three states: forwards, backwards, or zero. Forwards and backwards will be at equal magnitude, and the states can be switched instantaneously. (there is no gradual ramping up of acceleration)


You can find the change in distance for a given acceleration over a given period of time with this equation:


s = 0.5*a*t^2


The simplest solution here would be to accelerate until you reach the halfway point, then decelerate the rest of the way.


We will take P as the total distance you want to move:


s = P/2
P/2 = 0.5*a*t^2
P = a*t^2
t^2 = P/a
t = sqrt(P/a)

So basically:




  1. Accelerate at a for sqrt(P/a) units of time (units based off your units for acceleration)

  2. Decelerate at the same magnitude for the same amount of time




This is not the only solution. It will get you there in the fastest amount of time (2*sqrt(P/a)). But what if you want a more relaxed version?


In this case, you can accelerate 1/3rd of the way, coast for the 1/3rd, and decelerate the rest of the third. Or 1/4th, coast for 1/2, decelerate 1/4th as well.


Or maybe you could accelerate for a fixed amount of time, and then decelerate for a fixed amount of time, but wait until you arrive at the exact position before you start decelerating.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...