# Calculate the amount of torque impulse needed to get to a certain orientation.

## Recommended Posts

I’m programming some steering behaviors in 3D and am a little lost on figuring out how to figure out the necessarily torque impulse necessary to match a target orientation.

Ive been looking at some boids steering code and it seems like often the orientation is dependent on velocity. I’m trying to implement a space simulation so I want to do steering based on rotational thrust.

I’ve tried finding the difference between the two orientations (q2 * q1.inverse()) and then converting that to ruler angles. However I’m not sure that’s completely the same thing. Doing this also leads to some spinning out of control so I haven’t figured out how to try to go to the nearest target and then be able to stop.

##### Share on other sites

Do you want to apply just 1 impulse in 1 frame and then let it rotate until it converges at the desired orientation based on the angular momentum? Over how long time? Infinite? Finite? Is there angular drag? (in space? :D)

Wouldn't it be slightly better to rotate every frame by applying a smaller impulse of a constant size (maximum rotation thrusters thrust) until you're close enough and if you overshoot a little, it'll automatically rotate back?

Sounds like a job for a PID controller, but I haven't done this so I'm awaiting for someone to link something useful

Edited by pcmaster

##### Share on other sites

Yes, ideally, I would both use angular forces to accelerate and then decelerate. However I feel like figuring out the total angular impulse would be the first step, then I could try and use that to figure out how to accelerate and decelerate angularly to stop at the target orientation.

Thanks for the keywords. I've since found these, which look promising. I'll try to read up on them in the morning.

Edited by Axiverse

##### Share on other sites

Figuring out the angular impulse to reach some target orientation is the angular equivalent of figuring out the linear impulse to reach some target position. It basically makes no sense. You have to decide how quickly you want to get there, as pcmaster pointed out.

##### Share on other sites

I didn't expect to, but I managed to do this, albeit only in 2D (box2D in libGDX; shouldn't be a problem to translate into 3D), without a PID controller, just with some boid tutorial. There's some wiggling at the end, but I haven't been able to program a PID controller without it either, quite frankly.

Anyway, in the boid tutorial it's just a variation on linear arrival, and I found it pretty straightforward and effective.

##### Share on other sites
21 hours ago, Axiverse said:

Ive been looking at some boids steering code and it seems like often the orientation is dependent on velocity.

Really angular velocity is integration of applied torque impulses. So to get a required orientation it required to apply at least 2 consequtive impulses - one to start rotation and other to stop it. On most use-cases it require a proportinal navigation , so PID regulation is  better (intendent for its kind of tasks)and simpliest way to implement it.

Edited by Fulcrum.013

##### Share on other sites
22 hours ago, Axiverse said:

Doing this also leads to some spinning out of control so I haven’t figured out how to try to go to the nearest target and then be able to stop

Find a normalized vector from your object to target. Find projection of its vector to coordinate planes of object's local coordinate system. Now calculate angles betwin of its projections and forward axe .  Use a PIDs to turn on orientation trust proportionally to its angles (or ever proportionally to just a projections of target dir vector to other local axes for simplified but much faster approach). It will follow a target point ever in case target point is moving. Say more if you will use a differences of angles calculated on 2 consequtive steps as input of PIDs it will follow a interseption point for moving targets.

Edited by Fulcrum.013

##### Share on other sites

I've been looking more into PIDs, however I'm not sure where to start learning how PIDs are combined in automation. For example, we have both the turning mechanism as well as the acceleration - both affecting how we arrive at our goal but independent on each other. I can implement some logic which attenuates the acceleration by the difference between the heading and the target angle, but I wouldn't know how to extrapolate this if more actuators were involved.

I'm sure this is an existing problem, however I don't know what the field is called or what to look for.

##### Share on other sites
6 hours ago, Axiverse said:

For example, we have both the turning mechanism as well as the acceleration - both affecting how we arrive at our goal but independent on each other.

Real-world autopilots use separate channel for each axe.    Each PID converts input  volume (that usually is a input from sensors) to output volume (that is a power delivered by drives)  only. If we drive a some feedback (that usually sensors do) to PID input it able to keep/follow target value of sensed signal with some dT kown as regulation delay. Linked to chains it able to keep a orientation using angular speed as intermediate (PID regulated by chained regulator) value for example.  But it works separately for each deegry of freedom and able to drive system from current state to target state only. So if you need sequence of moves you have to set a sequence of targets to channels that can be followed sequentaly or simulateousely. For example you can setup required to acceleration impulse orientation to orientation channels, await until it reach required orientation, then setup a target velocity vector to main thrust channel, avait while it reach it velocity, and then setup other orientation (for example that match velocity direction). It what you logic have to do - to setup targets for regulators, wich drive system from current state to target state by shortest possible way. Really PIDs level of system  work like a cerebellum, while higher level logic works as brain that set sequential goals to cerebellum

Edited by Fulcrum.013

##### Share on other sites
4 hours ago, Axiverse said:

however I don't know what the field is called or what to look for

Dont sure how it exactly called by English, but litherally translated from Russian it sounds like "theory of automative control".

Edited by Fulcrum.013

## Create an account

Register a new account

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633387
• Total Posts
3011608
• ### Who's Online (See full list)

There are no registered users currently online

×