0

I'm working on AI vehicle movement for a game. This is an open terrain game so the vehicles are not using a predefined track. The AI is given a list of waypoints that they must follow believably. Right now they kinda are but they need to adjust their speed for corners, so I need some help trying to figure out the correct speed they should be going during turns.

The variables I am currently working with are: the angle for the next turn (if several turns are close together I add them to the current turn angle), the current speed, the braking distance, gravity, and friction between the ground and the vehicle.

I saw this post but I wasn't sure how Ri and Ro played into my way-point list: Car racing: How to calculate the radius of the racing line through a turn of varying length

Any help would be really appreciated!

LDOG
  • 3
  • You’re not always going to be able to use that solution as is, but it’s a reasonable starting point: as the angle gets shallower and the road wider, the turn starts and ends farther and farther from the apex. If your waypoints are spaced close together relative to the vehicles performances, there might not be enough room for it to reach max cornering speed for the next turn. As well, it might not have room to slow down enough to take the next corner at all. Have a look at Beckman’s old The Physics of Racing. – amd Sep 15 '18 at 00:13

2 Answers2

1

A reasonable model is that you can accelerate up to some limit in any direction-forward, backward (braking), or sideways (turning). If $v$ is the speed you are running and $a$ is the acceleration limit, the acceleration due to turning is $\frac {v^2}r=\omega^2r$ where $\omega$ is the angular velocity, $\omega=\frac vr$. I did the problem once and convinced myself that if you want to make a U turn it is worth decelerating to zero speed, making a sharp corner, and accelerating back to speed. There is some smaller angle where you should just make the turn at speed because the decelerate/accelerate is a fixed cost while the time saved turning is proportional to the turn angle. A reasonable acceleration limit for cars is $0.8-1$g.

Ross Millikan
  • 374,822
  • It really depends on what you’re trying to optimize. If it’s time spent in the turn in isolation, then the shortest path usually wins. On the other hand, if you’re trying to minimize the total time to traverse some path that includes that turn, it can be better to trade time spent in the corner for increased exit speed. – amd Sep 15 '18 at 04:49
  • @amd: That is what I remember doing for a U turn. It was better to decelerate to save the time in the turn. Clearly for a small turn you should not. I have not calculated the transition point in angle. I suspect it is a sharp jump. It was long ago and the memory is hazy. – Ross Millikan Sep 15 '18 at 04:52
  • That’s a great edge case that illustrates why the simplified “racing line” of a constant-speed circular arc isn’t the real racing line: You spend too much time changing direction and can’t start to increase your speed until after you’ve gotten a long way out of the corner. The transition angle is going to (obviously) depend on the car’s characteristics, though. Generally speaking, I’d expect that the better the longitudinal acceleration, the greater range of turn angles benefit from a “point and shoot” approach, but what comes next will have an influence, too. Real-time brachistochrones :) – amd Sep 15 '18 at 05:41
  • 1
    I’ll note that for a realistic-feeling model, longitudinal acceleration (throttle) should be less than deceleration (braking). – amd Sep 15 '18 at 05:43
  • @RossMillikan so is ω the speed I want to have in the corner? I understand that its the angular velocity, but I don't really have control over that, I can only modify forward velocity and steering. Also is r calculated the same as the answer above? And how does a acceleration limit play into this equation? Thanks for the responses. – LDOG Sep 17 '18 at 16:40
  • $\omega$ is useful to understand how much time you will spend doing the actual turn. You set it when you choose the route to get $r$ and choose the velocity. For a given acceleration you get higher $\omega$ when you use lower $r$, so the fastest turn is to slow to $0$ velocity, make an instant turn, and reaccelerate. If the turn is small enough, the time spent in acceleration/deceleration is more than the time saved in the turn and you should just keep going at your max $v$ and choose the $r$ so the acceleration is acceptable. – Ross Millikan Sep 17 '18 at 16:47
0

$R_i$ and $R_o$ are the inner and outer radii of the road which determines the actual radius of your turn. The larger the radius the better which is always larger than $R_o$ enabling you to go through the corner faster. This is a geometry problem as a vehicle will go from outside to inside and back to outside in making the turn radius as large as possible.

Phil H
  • 5,579
  • Thanks for the response! So are R_i and R_o arbitrary, can they be whatever I want or do I have to calculate them? – LDOG Sep 14 '18 at 23:53
  • @LDOG For your application, they are parameters that you get to adjust—they constrain how far off the “connect the dots” path you allow the vehicle to go. – amd Sep 15 '18 at 00:08
  • @amd Not really, I am using physically based vehicle model and a custom path-following implementation. So I'm trying to figure out what the best target speed is for my vehicle so that it doesn't skid or veer to far off the track. – LDOG Sep 15 '18 at 00:14
  • @LDOG In your question, you wrote that there is no track. “Too far” is entirely up to you to define, which in turn constrains the inner and outer radii—effectively the width—of the imaginary road that you’re trying to keep the vehicle on. – amd Sep 15 '18 at 00:17
  • @LDOG Yes, you can make them whatever you want If you want to constrain the path of the vehicle. – Phil H Sep 15 '18 at 00:21
  • Okay thank you both. One last thing, something I don't entirely understand yet is what exactly is the center point of the inner and outer radii? If I set R_i = 0 and R_o = 100 would the apex of the turn lie exactly on the way-point that the vehicle is pivoting on? – LDOG Sep 15 '18 at 00:37
  • The apex is the point on the turn closest to $R_i$ usually midway through the turn whereas waypoints are general markers on a course for various reasons, change in direction etc. In this case, it could be where the turn starts.and ends. – Phil H Sep 15 '18 at 01:08
  • @LDOG If you want the vehicle to pass through the waypoints, it might be easier to work with a maximum lateral deviation $w$ from the “connect the dots” path instead of $R_i$ and $R_o$. If you use the waypoint as the midpoint of the turn (the apex), the derivation of the maximum turn radius is similar to the one you reference. – amd Sep 15 '18 at 05:48