Gaming PID controllers and bike game handling

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
Hello, fellow space-people! - i got a very geeky little challenge for ya.....


as some of you may already know (since i talk about it annoyingly often), i'm working on a trials bike game....

you know, one of those ride-over-obstacles physics driven type deals.... it's a flash game, and i'm coding it in HaXe (which is sooo much better than AS3)


anyways....

i didn't wanna have the game "cheat" itphysics for its handling to become playable (as these games usually do)

so instead, i decided for a largely overdone stability-augmentation control system, which can be compared to something akin to a fly-by-wire setup such as that on EuroFighter jets....


well, first things first - let me explain what we're dealing with here....
this is what the aforementioned abomination looks like:
picture.php



that mad-scientist looking control panel to the right is what i'm dealing with... i made it just so that i could tune the bike handling dynamics to an optimal stable/fun sweetspot


but it's tricky.... sometimes changing a single parameter makes a world of difference, but then changing something else makes it irrelevant or over-sesitive.... anyways, the goal of my work for that past month has been solely that of finding this "optimal" setting


this tuning is of great importance for this type of game - since the general "feel" of the bikes handling is a lot of what makes players enjoy themselves addictively or casually browse away in boredom/frustration


well, i've set up a whole scheme to make this more manageable....

the game is capable of saving and loading simulation config files, so it's easy to swap between settings and compare things that worked before....

as you can see, i've been up to a LOT of seat-of-my-pants tuning work up 'till now (i had even considered using some genetic algorithm at one point) :p


the game also saves and loads the tracks you race on (it starts out as a crude map editor thing, so you can create a track before you go)


well - you can get the swf and some of the lastest config tests here: http://dl.dropbox.com/u/1374365/XCC.zip

the zip contains the swf file for the game, a "default.bike" file (which is not auto-oaded by default, despite the name) and a folder with some saved tracks i made for testing or just thought were cool....



well - these are the controls you need to know:

in EDIT MODE:

click and drag to "paint" the track

WSAD keys move camera

ENTER to build the scenery and start riding
F4 -- load track file (only in edit mode)

in RACE MODE:

LEFT/RIGHT arrows -- lean back/forward respectively (hold both to duck)
UP ARROW -- accelerate
DOWN ARROW -- brakes

SPACE BAR -- unflip bike

ENTER -- unflip bike and return to track start


F5 -- sace track file (only after built)

F11 -- load handling config file
F12 -- save handling config file


well, off to lunch -- BRB - :cheers:


Edit: ok, now i'm back, where was i?



right - let me help you get started, so you at least kinda know what you're doing....


the riders name is Bob - so ii'll refer to him as such from here on....


bob is controlled by a system of 6 PID loops, with different parameters and functionality, each accounting for a specific aspect of his movement and how he reacts to forces and acceleration as he goes....

each controller can be individually configured by its respective panel on the control UI..... so let me explain a bit how it works



the topmost controller in the panel (the purple-ish one) is for bobs torso rotation - it works towards rotating bobs body a few degrees (quite a subtle effect, really) back and forth according to his position relative to the bike and to the current inclination angle

it does very little for handling... it's almost just for making the motion look a little more fluid




now, the three blue controllers are of greater importance - they are called "subcontrollers" - because of the way they are wired to the final two XY loops (the yellow output controllers below)

this is called a "cascade" setup - in which one (or in this case 3) loop sets the target for another....

now, since each loop handles only a single floating-point value, some inline logic is installed in order to convert back and forth from this single-valued representation into 2d vector form.... but anyways, that's not very much relevant, it's more important to understand what each controller does and what to expect of tweaking it


the rotation sub-controller

this one gauges the rotation velocity of the bike as it spins around, and determines how bob should move tangentially to the rotation center in order to try to slow it down to zero....

it doesn't actually stop the spinning too much, but just by "trying", it makes it much less prone to toppling over on steep terrain or during jumps and other stunts as long as the parameters are properly tuned


the counter-acceleration subcontroller

this is set to respond inversely to the bikes acceleration - so if bob throttles up and starts going forward, he'll also pull himself forward to compensate the forces.... moreover, when bob lands from a jump or rides over some bumpy patch, this controller also serves to stabilize the bikes motion, since bobs own movement affects the bike as by Newtons laws


again, it won't prevent acceleration, nor will it stop bumps from knocking bob around -- it's just another stability measure, which if tuned correctly, makes for a stable ride (or if not, makes bob try and jump off the bike, even tho i haven't programmed him to yet)



the command-response subcontroller

this last loop simply tries to minimize the distance between bobs body and the "target" set by the players controls when leaning around (see also the "command targets" tab)

this is useful to eliminate "command slack" (a nasty effect where bob doesn't move all the way to the target) - but also allows bob to react to the other two controllers before he finishes doing what he's told


the outputs of these three controllers are added up to an XY vector (we'll call it the "control vector") - this is then wired into the final two (yellow) loops




the X and Y output controllers

the sole purpose of these is to mediate the control vector and the output acceleration for bobs body
it measures the error between bob's velocity and the control vector, then outputs an adapted acceleration which bob must respond to....



i can elaborate more on it later - but righht now, i've encountered some errors in my code, so i'll have to upload a fixed version before anything else....

but anyways - feel free to play around with the variables and see what each does for bobs riding skills.... if you think you hit something good, please post the .bike file so i can check it out :thumbup:


i thank you for your attention :salute: :cheers:
 
Last edited:

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
Wow. This is the Orbiter of the Trials Game world! (...)

well, i only wish.... :rolleyes: - but thanks anyways! :thumbup:


well, i've replaced the files in the zip with the new fixed version - now the controllers really do what i said they did (yeah, they were messed up before), so everything behhaves a lot more friendly :hmm:



if he spins out for whatever reason - hit space, even if he doesn't stop at once, keep hitting it until he does....

that's a bug i have yet to work out (not sure what isn't getting reset that causes it to spin around again)



anyways - forgot to say - whenever you make changes to the settings, they're not applied right away.... you gotta press space or enter in order to commit whatever changes you just did.... well, figures :hmm:


well, the DL link is the same... see if its any better now - and whatever doubts (i'm sure there'll be many), just feel free to ask me


and remember, i'm taking a very pragmatic approach here... so there's no really "right" or "wrong" way to configure this stuff -- it's only about "what works" and "what doesn't"

:cheers:
 

Quick_Nick

Passed the Turing Test
Donator
Joined
Oct 20, 2007
Messages
4,088
Reaction score
204
Points
103
Location
Tucson, AZ
Hm... unzipped, and opened with Flash Player (6). The whole window is just filled with black. (and is fairly large) I'd really like to try this sim.
EDIT: um... never mind. Opening in IE works. :) I figured Flash 6 was old. XD
The only problem is I can't hit F4 or F11, etc. :p
 
Last edited:
Top