Calculating arrival with soft turn (help!)

This topic is 2062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So, we have a mobile that behaves very much like a car, with some rules simplified.

The mobile has a maximum turning speed and a turning acceleration, this goes to both directions of the car relative to its forward vector.

It also has a top forward speed, which is limited to a linear interpolation between the maximum in straight line and the maximum while using top turning speed.

In order to reach this top speed and to stop it has an acceleration as well, considered to be constant.

Unlike a car, we are not meant to move backwards.

For the purposes of this task we are in a wide open empty parking lot, so room to move and manouver is plenty, we start in a given position facing a given angle and we are given the goal of arriving at another specific spot at another specific orientation.

This goal may very well be to end up standing in the same spot but facing the opposite direction.

Acceleration and speeds for both translation and rotation will make the beggining of our movement process look very nice, but arrival is more complicated, we need to arrive from a specific direction in order to end up looking in the angle we were given.

My first instinct is to try to extrapolate the arrival turn from the goal backwards, but I have no idea how to do this mathematically. Formulas? hints? alternative solutions? it needs to look soft and obey the rules stated above.

Acceleration and deceleration may have different magnitudes.

Share on other sites

This is a difficult problem that I have thought about in the past. The paradigm I would use to solve it is that of optimal control using dynamic programming.

In coordinates in which the goal is the origin and the target orientation is 0 (the positive x axis, if you use standard trigonometric conventions), your mobile is at (x,y) with a speed s and an orientation o (between -pi and pi). So your state is described by 4 numbers. Now discretize those 4 numbers, discretize time and discretize the possible actions you can take in one time step.

Write down an instantaneous utility function, which tells you how close to achieving the goal you are (something like exp(-(s^2+x^2+y^2+o^2)) would do, perhaps with weights in front of each quantity squared). Now define the total utility as the sum of future values of the instantaneous utility function, with some exponential decay to discount the distant future (so you get there earlier if possible).

In a 4-D array, store the current estimate of the total utility assuming optimal actions are taken in the future (this is known as the "value function"). Whenever you query this 4-D array you'll use some sort of interpolation, because you will be querying at situations that aren't necessarily in the grid. This estimate can initially be very bad (say, the instantaneous utility). You can then iterate over the entries in this 4-D array and refine your estimate of the total utility by finding the action that would lead to the best next situation from each hypothetical situation. Repeat until it converges.

You can do all of this optimization offline, and then online you simply look up for each of your actions what leads to the best value in one step, and take it. You could also just store the optimal action from each state and simply take that.

I believe this procedure is called "value iteration", although Bellman equation seems to refer to the same thing, or something very similar.

If you end up implementing something like this, I would love to see a demo.

Edited by Álvaro

Share on other sites

Oh, I forgot to post a link to this lecture on the subject. It's hard to get through the notation at the beginning (perhaps watching the previous lectures would help with that). But then there are some neat examples where the state is 2D and the actions are 1D (so you can make neat images to represent both the optimal policy and the value function).

Share on other sites

I just came up with an idea that has potential, Given a starting linear velocity, angular velocity and their respective accelerations, if the mobile were to turn and decelerate (regardles of a target) it would descrive an inward spiral, which has a center (that must be aligned with our target) and an entry radius, if I can calculate that radius based on the mobile's current kinematic parameters and steer it towards the center offseted by the radius in a perpendicular direction to the mobile's heading, it would enter by the tangent of the spiral.

Once the mobile reaches the entry tangent, it changes its behavior from seek to arrive, steering and decelerating towards the target, it should reach it with a very small margin of error that can be compensated easily.

Any idea what would be the formula of the radius? I know that for linear movement with a final speed of 0 the traveled distance is d = (So * So) / (2 * a)
d being distance, So being initial speed at the moment of evaluation and a being constant acceleration, I'm looking up angular movement to see if I can figure out a similar formula that gives me the entry tangent radius.

Share on other sites

Hmmm, though this will make the mobile arrive at the target from a spiral, it doesn't solve heading arrival (arriving to the target position from a specific heading as well), but if we can calculate the entry spiral, we can force it to be oriented in such a way that the final heading is as desired, and then force the entry tangent and radius to satisfy that condition as well, question is how.

Share on other sites

Another way to do this my coleagues and I thought of, that aproximates the previous idea well enough and might even take other things into consideration (obstacle evation and other movement rules) is to simulate an anti-mobile, that starts at the target and tries to get to our mobile, with the same parameters our mobile should use on arrival, deceleration speed, turning angle and so on, each frame our mobile moves towards the anti-mobile instead of the final target, and the anti-mobile moves toward the mobile.

Once the path of the mobile towards the anti-mobile requires no steering (both mobiles are moving in a colinear fashion), we stop moving the anti-movile, and once the mobile catches up with the anti-mobile, our mobile tries to move to the target, but from a state that favors a good arrival trayectory.

Does this make sense?

Share on other sites

A couple of ideas, if it helps:

- How would you steer the vehicle yourself to reach the goal? If you analyze the steps you would take when steering the vehicle, your reasoning behind it, it could be a guide to modelling this behaviour.

- Resort to AI: http://www.red3d.com/cwr/steer/

Look for the "arrival" sample. It doesn't take as many parameters as you want, but it's a start.

It's part of the OpenSteer library, and the logic behind the "arrival" sample is described here.

Share on other sites

I already have arrive implemented, and the mobiles do arrive and slow down at target, the problem is when you want them to end up looking with a specific direction and you don't want them to reorientate after arriving, but rather come softly from behind the desired heading.

I'm already using steering behaviors for this.

The target ghost boid as I've come to call it seems a promising approach, though it still needs tweaking.

Share on other sites

I think this is similar to the "Piano Movers Problem".  It is motion planning / pathfinding with lot's of degrees of freedom.

This article touches on some of the methods (See configuration space part).

http://www.gamasutra.com/blogs/MattKlingensmith/20130907/199787/Overview_of_Motion_Planning.php?print=1

Beyond giving you some search terms and links, I can't be much more help as this is kind of over my head, though...

Good luck.

Share on other sites

The target ghost worked quite well, its not perfect and its subject to a fine tuning of the kinematic parameters of the mobiles, but gives out a nice effect for what I wanted,
A more precise method would probably exist but I don't need to dig deeper at this moment.

For reference, the idea is to create a ghost mobile starting on the target position and orientation and having it move backwards based on the same logic used to move forwad with some reversed signs and considerations, the positive and negative boids are aligned you can move on to follow the target directly and arrival should do the rest quite nicely.

• 21
• 11
• 9
• 17
• 13
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!