Forums

Full Version: AI driver
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have implemented a rudimentary AI driver. So far it can successfully navigate through Ruudskogen, Nuerburgring, Jarama and Kyalami using a MC.

Should I post the patch here, let you guys have some test first, or should I commit to SVN? The patch is about 300 lines.
I'd say go ahead and check it in, unless your changes break things. Sounds pretty good though. How did you determine how to tell the car where to go?
Done. Checked in as rev 1356.

I've added an option in "practice game" screen called "Number of AI Opponents". If it's set as 0, it's the same old practice game. If you set it to 1, this will create an AI controlled car (same car as player selected but random color). You can race against the AI.

Quote:How did you determine how to tell the car where to go?

Pretty simple actually, the AI routine just steer the car towards the center of the next bezier patch. That's why it's called a 'rookie' level AI. :lol:
That's a pretty good start. The MC did alright on Jarama, obviously not a good line Smile but it works. I tried the AX2 on Le Mans and this didn't work, I got lots of messages on the console about missing player car, get ready for a crash...and then when I tried to quit it crashed.
Not happend to me so far, although I do encounter NaN error at certain point on Le Mans and other tracks.
Not a bad start! I can do laps on Jarama with the computer and I in G4s and it's pretty enjoyable.
Quote:I got lots of messages on the console about missing player car, get ready for a crash...and then when I tried to quit it crashed.

In DrawHUD(), I have some code that displays the AI car status. This causes the excessive 'missing player car' message when there is no AI car. I've commented out that. Check out rev 1357. However, I don't think that is the cause of the crash.
Awesome...

Got a feeling I'll be building SVN on the Mac this weekend.
I've made some improvement to the AI (rev 1363). Most noticeable is the improved steering code. Instead of steer towards center of next patch, now it's steering towards some point further ahead. This has 2 effects,

1. Reduce the car wobbling (noticeable in G4)

2. The car is moving along a better line, instead of staying at the center of track
This is coming along nicely. Here are a few things I've noticed/questions I have:
* the lap timer is tripped every time the player goes around as well as every time the robot goes around. We need to set up some kind of timing tables class to put lap data in for each of the robots (as well as the players...this should eventually also work into the player profile).
* Why do some tracks work and others don't? Lots of the cars seem to work alright. I haven't tried them all yet.
* I get segfaults when doing pause -> restart game, pause -> leave game, pause -> quit.
* Will this system be able to accept other robot modules? Is it compatible with TORCS robots API?
* Both cars have bounding boxes so theoretically it should not be hard to do collision. Joe, any comments there?

Sorry for so many questions, I honestly haven't had time to look over the code yet, I have been busy since you added this, and testing the code is much more fun Wink All in all the AI is a blast to play with. I like your latest improvements to the driving, they are not hard to overcome but still they can get a good bit ahead of you if you screw up.
Quote:* Why do some tracks work and others don't? Lots of the cars seem to work alright. I haven't tried them all yet.
Probably due to the roads.trk and starting position of the tracks. Starting position of some tracks are in the pit lane, and there is no proper traced road leading to the main track. AI can only follow the bezier patch 1 by 1 on the traced road. I propose we should set the starting position at the starting line, not the pit lane.
Quote:* I get segfaults when doing pause -> restart game, pause -> leave game, pause -> quit.
No segfault when i do pause -> quit. No segfault at pause -> leave game either, but I do get 'NaN in origin vector' quite frequently in this case. Haven't found out why yet.

I do have segfault at pause -> restart game. From back trace, it seems after restart, somehow the AI car's drivetrain pointer is invalid (probably been deleted during restart). Couldn't figure out why though.
<edit>segfault fixed in r1372

Quote:* Will this system be able to accept other robot modules? Is it compatible with TORCS robots API?
The AI code is base on Berniw's TORCS robot tutorial. However, it's not using TORCS API. Bascially, there are 4 functions in the AI module,

updateGasBrake()
updateGear()
updateClutch()
updateSteer()

Each function handles 1 particular aspect of the input, and pass the input similar to a player controlled car, via Vamos_Body::Car::gas(), Vamos_Body::Car::brake(), etc.

There is no shared library/DLL support built in. So some more work is needed if we want to be able to add robot modules dynamically.


I'm not familiar with the collision code. But do note that the AI currently does not have the capability to avoid colliding with other cars. It also lacks the ability to return back on track once it's off.
Code:
* the lap timer is tripped every time the player goes around as well as every time the robot goes around. We need to set up some kind of timing tables class to put lap data in for each of the robots (as well as the players...this should eventually also work into the player profile).

The timer class (see timer.h) could be easily extended to do this.
rookie1 Wrote:Probably due to the roads.trk and starting position of the tracks. Starting position of some tracks are in the pit lane, and there is no proper traced road leading to the main track. AI can only follow the bezier patch 1 by 1 on the traced road. I propose we should set the starting position at the starting line, not the pit lane.
This seems like a good idea. Anybody want to work on this?

rookie1 Wrote:No segfault when i do pause -> quit. No segfault at pause -> leave game either, but I do get 'NaN in origin vector' quite frequently in this case. Haven't found out why yet.
OK, on some cars it does segfault, on others it doesn't. I'll do a little more testing and let you know which ones do/don't.

rookie1 Wrote:<edit>segfault fixed in r1372
Good work, thanks Smile

rookie1 Wrote:The AI code is base on Berniw's TORCS robot tutorial. However, it's not using TORCS API. Bascially, there are 4 functions in the AI module,

updateGasBrake()
updateGear()
updateClutch()
updateSteer()

Each function handles 1 particular aspect of the input, and pass the input similar to a player controlled car, via Vamos_Body::Car::gas(), Vamos_Body::Car::brake(), etc.
I see, I have been investigating the TORCS robot system and I'll start a new thread about it soon...

rookie1 Wrote:I'm not familiar with the collision code. But do note that the AI currently does not have the capability to avoid colliding with other cars. It also lacks the ability to return back on track once it's off.
I've noticed that some of the cars can get back on the track (XS for example, but since your last updates it doesn't go off-track anymore on Jarama at least), on others it can't. This is probably the fault of it being very hard to get out of the sand traps in some cars (probably due to clutch force or tire friction problems, for instance the 3S).

joevenzon Wrote:The timer class (see timer.h) could be easily extended to do this.
If we could have a timer object associated with each robot that is triggered when the robot crosses the finish line, that would work well... I'm guessing this should go in vamosworld.cc somewhere.
Playing with the AI is very hard because the robot gets a head start every time. This reiterates the need for multiple starting positions support in our tracks.
Well, I guess this is more because AI gives input to the car immediately when the simulation starts, while human player has to wait for the screen to show. If we can introduce a proper start sequence, like the traffic light thing at the start of the race (sorry, don't know what it's called in racing terms), we should even out.

Of course, we should still have proper start positions. Currently both the player car and AI car starts at the exact same position. I'm interested to know what will happen if we introduce collision between cars :lol:
Pages: 1 2