Skip to content

Attempt PID controlled steering#3

Closed
clungzta wants to merge 2 commits into
Sentdex:masterfrom
clungzta:master
Closed

Attempt PID controlled steering#3
clungzta wants to merge 2 commits into
Sentdex:masterfrom
clungzta:master

Conversation

@clungzta
Copy link
Copy Markdown

Great video series!

I added PID control steering using this PID implementation

I currently do not have access to a copy of GTA5 to test this with. Thus, the code is completely untested. Although it should be close to working, likely just a few minor bugs.

The P, I and D values provided will need to be changed through trial and error (I added PID tuning instructions in the comments).

I found a graphical python demo for tuning PID controllers here

@Sentdex
Copy link
Copy Markdown
Owner

Sentdex commented Apr 12, 2017

Thanks for your submission here. If anyone tests this or has improvements, let me know. I'll test this one soon, currently knee-deep into another driving method entirely with deep learning and using our original key inputs. I'd like to see that through before making this switch, but this is obviously the better choice if we can get it implemented right.

@Sentdex
Copy link
Copy Markdown
Owner

Sentdex commented Apr 14, 2017

Running this gives me:

Traceback (most recent call last):
File "C:\Users\H\Downloads\pygta5-master\pygta5-master\main - Copy.py", line 227, in
left()
File "C:\Users\H\Downloads\pygta5-master\pygta5-master\main - Copy.py", line 162, in left
ReleaseKey(D)
File "C:\Users\H\Downloads\pygta5-master\pygta5-master\directkeys.py", line 55, in ReleaseKey
ii_.ki = KeyBdInput( 0, hexKeyCode, 0x0008 | 0x0002, 0, ctypes.pointer(extra) )
TypeError: int expected instead of float

@clungzta
Copy link
Copy Markdown
Author

I am not entirely sure what the problem is there, it seems to be something to do with the ReleaseKey function in directkeys.py.

I didn't modify anything with the directkeys or steering functions (see my Git diff comparison). I simply called your original "left()", "right()" and "straight()" functions to control the steering based on the PID controller output value.

I currently don't have access to any Windows machines to test out the directkeys. Although I can have a look into this issue in coming days.

@Sentdex
Copy link
Copy Markdown
Owner

Sentdex commented Apr 16, 2017

Do you have any game you could test this with? I'll keep poking around with it, but I feel like I am shooting in the dark since I have no idea how any of this works.

@Sentdex
Copy link
Copy Markdown
Owner

Sentdex commented Apr 19, 2017

So I looked more into this, it was getting mad always about "D" ... then it clicked, we have two definitions for D, one is for the D key and the other is for the D in PID. That's the breaking error.

There's a new error 'NoneType' object is not iterable ... but it's now past my bed time, so I will look into this more tomorrow.

@fiveNinePlusR
Copy link
Copy Markdown

fiveNinePlusR commented Apr 19, 2017

having done PID controls professionally for industrial automation, I am not sure PID is all that well suited for this type of application with changing setpoints often(as it would be for following a road as it curves) I suppose you could do a PI loop with the derivative term being 0 and the integration term being very small. You should also have an antiwindup to control for accumulation of errors.

Edit: PID was meant for long running industrial automation (think boiler temp control or controlling the flowrate of a system by modulating the the pump output with a VFD)

I can help you out, though, if you have any questions.

@Flandan
Copy link
Copy Markdown

Flandan commented Apr 21, 2017

Today I've pulled together some code for virtual joystick input for solving this same input issue in a different way (I'm afraid I must have missed this post). It might not be as robust a solution but it is certainly easy to use. I have posted it as an issue.

Edit: Correct me if I am wrong but isn't PID control designed primarily to avoid problems with hysteresis? I feel that the problem is more due to the lack of fine control. using PID would introduce extra lag into the reactions of the net which doesnt sit right with me as a gamer. Also isn't there already a (cheap?) form of PID built into the bike controls?

@pedrocunial
Copy link
Copy Markdown

Also, adding to @fiveNinePlusR comment, from my personal experience, PID seems to be way more useful when dealing with "real world" data through sensors, and acting through non-perfect methods (AKA any kind of thing related to robotics, mechanics etc, such as motors, joysticks etc).

I fail to understand where the imprecision would be in this model, since we're dealing with a fully responsible controller (in the sense that the answer that the system gives us not only should be but actually is exactly the expected one) and the "street detection algorithm" could always be improved programmatically.

Anyway, I really like the initiative and I also do think that a PID controller should be implemented in any real life self-driving car (tbh, not only should but must be implemented). I just fail to recognize how the necessity of the PID would translate to this fully computational model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants