Calculate ideal speed by approaching angle and object's turn speed?

Started by
3 comments, last by CombatWombat 6 years, 1 month ago

Hello

I am a bit noobish with this but am trying to work out how to calculate the correct velocity of an object to have for an approaching corner.


So the object has the following stats:

    acceleration : 3 units/s  (this is also for slowing down)
    max speed : 15 
    turn speed :  45 degs/s

 

I want to find the correct velocity to approach a corner so that, it will take the corner without over steering. If the object literally has to stop entirely and rotate thats also fine (kind've like a tank).

I don't know the right formula to do this. Most google results include complicated aspects like drag and friction, mass etc and stuff that is too complex for my needs and then i don't know how to simplify it for my own needs.

If it helps, i calculate the angle in degrees not radians (since i use Unity's Vector3.Angle).

Hope some one can help, don't need code, just the math logic for it i can translate to code from that.
 

Advertisement

Measuring acceleration in units/s is weird, unless "unit" is a unit of velocity: Something like m/s^2 would make more sense. Max speed 15 means absolutely nothing; it should be in units like m/s. Turn speed can't possibly have the same units as acceleration; it should be something like degrees/s^2, or simply 1/s^2 (which means radians/s^2).

There is a field called Control Theory and a class of algorithms called Dynamic Programming that deal precisely with problems like yours, but I only know a little bit about them, and it's pretty heavy stuff.

My practical advice is to turn your problem into a path-finding problem. Are you familiar with any path-finding algorithms? A* is probably the best, but not the easiest thing to get right if you are new at this. Anyway, if you discretize your states (i.e., divide time into steps, restrict the position of your vehicle to a grid and express velocity as two integers), you can think of all the possible states as a big graph. Your map and max speed will determine what states are possible. Your restrictions on acceleration and turning speed will determine connectivity between nodes. So set a goal state and velocity and run something like A* to figure out how to get there. The discretization step requires judicious choices of time step and grid resolution: Finer is closer to the original problem, but the CPU time it takes to run the algorithm will quickly get prohibitive.

I understand even this solution might not be easy to implement, but you came here with a difficult problem.

 

Hi

 

Sorry about the vagueness with units. Unity3D refers to everything by a unit which is equal to 1m. Just a habit i have picked up.  

I do have path finding, i use a navmesh, it has found the path. But i don't want it to follow the sequence of nodes so rigidly as it looks a bit unnatural. So i wanted it to accelerate up and down as well as take smooth curving paths.

 

The units i use are:
    acceleration : 3 m/s^2  (this is also for slowing down)
    max speed : 15  m/s
    turn speed :  45 degrees/s

 

The current issue is, if the turn is quite sharp and the object is going near its max speed. Then it will over steer the corner since its turn speed is too low for it. So i need to calculate what speed he needs to be going in order to take the corner giving his limited turn speed. If he has to stop completely to turn for very sharp corners (like a tank) thats fine.

The radius of you turn will be velocity/turn-rate (for constant velocity and turn rate).  Watch your unit conversions.

For your example, at maximum 15m/s and 45 deg/s turn rate, you can turn with a radius "R" of 19.09m.

Consider this crazy picture.

DiagramA.png.6952b86fe7b7b62e339c2f3b8e1caf6b.png

With "R" solved, you can check your target point.  Project a distance "R" normal to your velocity vector.  From this center point, if your target destination "A" is inside a circle of radius "R", then you cannot reach the target point without slowing down.  You will need a circle for "left" and "right" directions obviously, so you can project both normals for this.

 

 

This topic is closed to new replies.

Advertisement