Automated cars.

Discussion in 'Ideas and Suggestions' started by Garebear, Jun 8, 2013.

  1. Kamil_

    Kamil_
    Expand Collapse

    Joined:
    Mar 17, 2013
    Messages:
    691
    Seems so easy right?

    The way you describe it, you would have 2/3 cars crushing eachother to get to that 1 point because thats not AI but a following bot.
     
  2. Djhg2000

    Djhg2000
    Expand Collapse

    Joined:
    Jul 16, 2013
    Messages:
    31
    I gave this some thought and I think this might be the easiest AI implementation to get working well without human intervention. First off, what factors does a human use to determine what is an optimal path? Evenness - humans avoid rough surfaces where possible, both because they're uncomfortable and because they have a higher risk of causing dangerous situations.

    Evenness is defined as the perceived difference in height. For example, imagine driving in the dark with only your headlights as a light source. If you see large shadows on the ground, you try to avoid that spot because the surface is unknown and potentially dangerous. For the same reason you try to avoid walls; it may be a harmless sheet of paper but chances are it will severely damage your car.

    From the evenness you can then calculate the approximate braking distance (evenness / speed = braking potential). This will also be required for the AI.

    This makes sense for a lot of situations an AI may encounter. If it encounters a blind corner, it would slow down because it cannot see what is behind it (the evenness decreases in the direction of the obstacle, thus causing a worse braking potential and the AI slows down). In the exact opposite situation, an open field, the AI would go full throttle (unless given a speed limit) because it is surrounded by extremely good evenness.


    This would allow for different driving styles depending on what the goal of the AI is; if the AI is driving normally it would aim to achieve maximum evenness. If the AI is chasing someone it would only try to stay above a certain threshold of evenness (which would allow for it to take shortcuts across grass and such). In order to match up with a story line it could also decrease this threshold as time goes by and eventually crash.


    I hope this makes sense, I'm awfully tired now but I really think this would allow for a revolutionary AI. I'll take another look at this post tomorrow and fill in the gaps.
     
  3. Kamil_

    Kamil_
    Expand Collapse

    Joined:
    Mar 17, 2013
    Messages:
    691
    Before we get into the AI driving, it must first know where there hell it is, because it has no idea. Which most of you are missing.

    The thing with AI is that you must give it it's situation awareness, and that is the hardest part; especially when you don't have a "track" like in BeamNG. Making the AI do something with that data is the easy part.
     
  4. Djhg2000

    Djhg2000
    Expand Collapse

    Joined:
    Jul 16, 2013
    Messages:
    31
    Actually, it doesn't as long as it knows where it's going. A relatively simple GPS navigation algorithm from a map would suffice since the AI could attempt shortcuts on its own.

    If it's following someone it's even easier; just drive towards the target and avoid obstacles.

    In my solution all of the additional situation awareness it needs is the minimum evenness threshold. Again, for efficient driving it could make use of a rough map and a destination but the rest it would sort out on the fly.

    Actually, I think it might be pretty entertaining to watch the AI aimlessly drive around and look for ways to go.
     
    #64 Djhg2000, Jul 16, 2013
    Last edited: Jul 16, 2013
  5. Kamil_

    Kamil_
    Expand Collapse

    Joined:
    Mar 17, 2013
    Messages:
    691
    Following someone won't work. It won't stay on the road.

    What I'm getting at is that, this isn't a racing simulator, so there is no sort of GPS/Waypoint/Navigation mesh for the AI .... by default ... it's easy to put in. Although, just a "go here, then go here" waypoint won't work, AI doesn't know where the roads are. You'd need to let them know exactly where the road is, what you said sounds quite good to be honest; I didn't understand it at first.
    Did you mean something like scanning the road ahead of the AI for the road, cars, obstacles? If so, it's quite a good way to do it.

    Right..Now I feel like programming that AI
     
  6. Djhg2000

    Djhg2000
    Expand Collapse

    Joined:
    Jul 16, 2013
    Messages:
    31
    True, it doesn't "know" where the roads are, but assuming it aims for maximum evenness it will automatically avoid sidewalks, trees, light posts, etc. With some tweaks it might also be able to avoid crossing lanes from the lines painted on the road, but that's a different issue entirely.

    Yes, that's exactly right. This way it would gain and "understanding" of what it's driving towards and choose the most even path it can find with reasonable effort.

    The difference between this and most other systems I've seen is that the goal isn't to make the most efficient and mathematically optimal driving line, the goal is to create a good enough approximation of how a human would drive. This includes the negative side effects like misjudging the surroundings and crashing into things.
     
  7. Kamil_

    Kamil_
    Expand Collapse

    Joined:
    Mar 17, 2013
    Messages:
    691
    That made me laugh, heh.

    I actually don't think this is too hard to do with something like raycasting/raytracing, you could even pick out the colors, so grass would instantly be avoided.

    I'm trying to write a 2D version of something like this, but I have no knowledge of raycasting, basically just learning it along as I do it.
     
  8. Djhg2000

    Djhg2000
    Expand Collapse

    Joined:
    Jul 16, 2013
    Messages:
    31
    I think you can simplify the raytracing part in a 3D context. It needs is a height map of the terrain in front, after that sample a series of lines in a folding fan pattern across the height map and add the height deltas together disregarding the sign. This would also avoid steep hills as a side effect. When that's done set the steering angle to match up with the line that holds the lowest total delta.

    C-like pseudo code showing what I mean:
    Code:
    signed int steeringAngle()
    {
        // Start walking across the height map 100 steps 17 times
        // (17 * 5 degrees gives a range of 85 - 5 degrees or 40 degrees in each direction of the center line)
        // Check previous sentence for brain farts
    
        for (line=0; line<17; line++)
        {
            for (x=0; x<100; x++)
            {
    
                // This will add the deltas together until we reach 100 samples
                deltaOfLine[ line ] =+ abs(heightOf( x ) - heightOf( x + 1 ));
    
            }
    
            // This will rotate the height map so that we don't get parallel lines (which are useless in our case)
            rotateRaytracerFiveDegreesClockwise();
    
        }
    
        // Should return a steering angle with negative being left and positive being right.
        return( ( line * 5 ) - 40 );
    
    }
    
    You could also use the previous method but instead of adding together the deltas you simply discard every value except for the maximum one:
    Code:
    signed int steeringAngle()
    {
        // Start walking across the height map 100 steps 17 times
        // (17 * 5 degrees gives a range of 85 - 5 degrees or 40 degrees in each direction of the center line)
        // Check previous sentence for brain farts
    
        for (line=0; line<17; line++)
        {
            for (x=0; x<100; x++)
            {
                if ( abs((heightOf( x ) - heightOf( x + 1 ))) = temp > deltaOfLine[ line ] )
                {
    
                    // This will save the delta if it's bigger than the previous value
                    deltaOfLine[ line ] = temp;
    
                }
            }
    
            // This will rotate the height map so that we don't get parallel lines (which are useless in our case)
            rotateRaytracerFiveDegreesClockwise();
    
        }
    
        // Should return a steering angle with negative being left and positive being right.
        return( ( line * 5 ) - 40 );
    
    }
    
    Optionally don't set a new steering angle if it's within a threshold from the best one, occasionally randomizing this threshold value would make a spectacular drunk driver mode.

    Edit:
    4th time's the charm, right?
     
    #68 Djhg2000, Jul 16, 2013
    Last edited: Jul 16, 2013
  9. Kamil_

    Kamil_
    Expand Collapse

    Joined:
    Mar 17, 2013
    Messages:
    691
    Yeah, you would probably need more tracing for 3D - with 2D you just need a few lines in one axis (since there is only one axis) but not for 3D, if you want better AI that is.
    I also thought, you could have the AI keep track of other cars/roads/objects for a few (5?) seconds if a trace hits it, that way you get a artificial awareness of things, basically: you keep track of the car ahead of you and see if its braking or not, treating it like a car not a distance.

    I've kind of done the raycasting on my little testy thing, but I started playing Borderlands 2 with friends, so yeah. OT but just saying.
     
    #69 Kamil_, Jul 16, 2013
    Last edited: Jul 16, 2013
  10. Djhg2000

    Djhg2000
    Expand Collapse

    Joined:
    Jul 16, 2013
    Messages:
    31
    You could, but I think a "stateless" AI should be implemented first (not actually stateless if tracking the previous steering angle but tracking a single variable for one physics frame is close enough). That way the AI can take over any car and act in the same way regardless of what lead up to the situation. For instance, cars could spawn moving instead of starting from a dead stop, much like the AI Gabester implemented.

    If at this point everything work well, you could experiment with tracking nearby cars and approximate their movement, although I don't really see the need for it. Say for example a truck is coming towards the AI in what could become a head on collision. What can the AI to with a trajectory of the truck that it can't do by just choosing the most even path? Both would lead to an avoidance maneuver, right?
     
  11. Kamil_

    Kamil_
    Expand Collapse

    Joined:
    Mar 17, 2013
    Messages:
    691
    I'd love to try out both, but I'm using Love2D(lua framework for games) which has, or LuaJIT has a problem, not going into too much detail: basically means I can't do efficient raycasting (and a lot of other things). Actually, can't do none really; just one raycast...
    Might give it a shot using C++ but it will probably take some time.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice