3 ms·
Can someone who knows C help me understand the source code? https://gist.github.com/skeeto/da7b2ac95730aa767c8faf8ec309815c https://gist.github.com/skeeto/da7b
by ZephyrBlu 6y ago
Can someone who knows C help me understand the source code?
https://gist.github.com/skeeto/da7b2ac95730aa767c8faf8ec309815c https://gist.github.com/skeeto/da7b2ac95730aa767c8faf8ec3098...
The concepts and equations he has are pretty simple but I'm really not seeing how they translate into code.
The code also isn't the easiest to try and understand for me. Multiple 1-3 letter or otherwise (Seemingly) poorly named variables, some C jargon I'm not familiar with (Mostly the -> operator) and the fact it's a relatively large chunk of code.
It seems like the core logic loop is here: https://gist.github.com/skeeto/da7b2ac95730aa767c8faf8ec309815c#file-aidrivers-c-L428 https://gist.github.com/skeeto/da7b2ac95730aa767c8faf8ec3098...
And the position and acceleration of the car is altered each iteration through randomization?
It's hard to piece together.
- organian 6y agoThe arrow operator is a field access through a pointer. That is, if you have a pointer to a struct, it's the same as dereferencing the pointer and accessing the field: "(*foo).bar" corresponds to "foo->bar". I think the main driving logic is on line 228. It could definitely do with some more descriptive variable names, though - "a" for angle, and "s" for sense inputs seems a bit too short.
- devdas 6y ago-> is a dereference operator. On line 65 (function ppm_create), f is declared as a pointer to a structure of type ppm (a reference to an object of type ppm). f is the actual structure/object. (f).w is the 'w' member of the structure. The brackets are needed for operator priority. f->w is another way to write (*f).w