
Fast line-following robots - a1k0n
https://www.a1k0n.net/2018/11/13/fast-line-following.html
======
bananasbandanas
There is a similar competition in Germany called the CaroloCup. Here is a
video of our run when I was still a student [1].

We used model-predictive control which evaluated about 10k trajectories with
look-ahead, which works really well even when tires begin to degrade after a
few minutes. You can see the effects in the video towards the end, where the
car starts to slide, but the controller manages to catch it in time.

Our CV was a bit more complex as we had to deal with missing line segments. We
pre-processed the camera image with a distance transform, then used an
optimization pass written in opencl to fit a 3rd-order polynomial to the
image.

[1]
[https://www.youtube.com/watch?v=Of_D_Z9gbeg](https://www.youtube.com/watch?v=Of_D_Z9gbeg)

~~~
a1k0n
Nice! Are you doing probabilistic roll-outs, iLQR, or SQP, or what? What does
your model look like? I've been struggling with this -- not sure how complex
the tire dynamics model needs to be, for instance; do you need the whole
Pacejka magic formula or is tanh() good enough?

~~~
gugagore
Do you know if there's work on adapting to the vehicle dynamics on the fly?
The comment about tires degrading made me thing that there should be some
parameters in the model corresponding to how degraded the tires are, and
instead of relying purely on feedback to correct for model-mismatch, you could
try to get a better model on the fly.

~~~
a1k0n
I'm aware of one paper which tries to fit a local polynomial model to the
lateral dynamics, and they have a different model for different positions on
the track (it requires really good localization to work):
[https://arxiv.org/abs/1610.06534](https://arxiv.org/abs/1610.06534)

I had some of the vehicle parameters as part of my EKF for a while, but it led
to some instabilities in the control.

The main problem is that it's really hard to know what the car's instantaneous
lateral velocity is. I think the best you can do is check the difference of
velocity*gyro yaw rate and lateral accelerometer measurement to get a noisy
lateral acceleration measurement, and that can tell you how well your tires
are hooking up. I might try fitting a least-squares model on the fly with
something like that.

------
a1k0n
Didn't mention it in the post, but info about the car hardware and all the
code is at
[https://github.com/a1k0n/cycloid](https://github.com/a1k0n/cycloid)

------
drivers99
This is really inspiring. I played around with converting an RC car to self-
driving with an arduino but it was very simplistic. It used an ultrasonic
sensor (Parallax "Ping)))" sensor) to try to keep a specific range of distance
from a wall to its left. It wasn't aware of its angle so it had a positive
feedback loop in its reactions which caused it to oscillate more and more out
of control. Just knowing there are people are there playing around with this
for fun makes me want to get back into it.

~~~
sgillen
Can also put two distance sensors on and fet the angle using some trig.

And when you’re ready to get a little more serious you can get an imu and gps.
Maybe even get a more beefy computer and add a camera!

~~~
drivers99
> Can also put two distance sensors on and fet the angle using some trig.

That is exactly what I was planning to do next. I realized that when the angle
was greater, it would see the distance to the wall as higher than it really
is, because of trigonometry. And that is a positive feedback loop which makes
it worse. (I just realized that is only true when it headed towards the wall
at an angle, but is the opposite when heading away from the wall at an angle.
It reacts later (steer right) when it's angle towards the wall, but it should
react sooner (steer left) when it's angled away from the wall... hmm...)
Getting the angle, I could set a target angle and distance together, and steer
as needed.

------
elwell
Wow, really the best email address spam protection method [0]:

    
    
      _=0;k;main(){while(_<641){for(k=0;"##K#8(38D-##C]L5870.X7\\M_b;90\\"
      "MC-M/NZGB6Q,I0VGB6a0FbN<VG.6Q\\bNb7^@`X=N@`XQaOVX:^]NX=:Z8PY]B`:>P"
      "NY8^$#SM):XA"[_/6]-35>>_++%6&1;k++);putchar(k[" _/\\\n,`)('<-"]);}}
    

[0] - bottom of OP's homepage [https://www.a1k0n.net/](https://www.a1k0n.net/)

~~~
a1k0n
Heh, you can just click on it to see the result if you don't want to actually
compile it.

~~~
elwell
Pretty cool. Works here too:
[https://www.onlinegdb.com/online_c_compiler](https://www.onlinegdb.com/online_c_compiler)

------
adrianN
A similar discipline is Micromouse, where robots have to solve mazes and then
race the path they found.

[https://www.youtube.com/watch?v=NqdZ9wbXt8k](https://www.youtube.com/watch?v=NqdZ9wbXt8k)

------
hobolord
This is great, I did a robotics course in uni that was essentially this. We
never took it further than PID control though.
[https://www.youtube.com/watch?v=oDqfKm4Ovcg](https://www.youtube.com/watch?v=oDqfKm4Ovcg)

That was a fun time in uni

~~~
bufferoverflow
We did too. Had to use Lego Mindstorms. It was a pain in the a$$ to program
back then.

One of the guys built a very fast line-following robot, much faster than what
we see here. It was simpler though, it was a solid black line.

~~~
berti
I remember having to do the solid black line with a couple of photo-diodes and
a small AVR in first year EE. Was kind of a neat project thinking back, but we
all hated it at the time because it soaked up quite a lot of time tuning it
aggressively to beat everyone else without losing the track, going back where
you came from, etc!

------
cmontella
Very cool! We ran a competition like this once for undergrads:
[https://vaderlab.wordpress.com/roscar-robot-stock-car-
autono...](https://vaderlab.wordpress.com/roscar-robot-stock-car-autonomous-
racing/)

It had to be a little more complex than line following, because at one point
in the track there are a bunch of line crossings. So you had to do some
mapping and tracking too in order to stay in the right lane.

It's really fun seeing how fast you can make them go. One team maxed out the
speed on the platform.

------
TaylorAlexander
Awesome post! I really need to attend the robo cars event. I’m working slowly
on my own autonomous robot:

[https://youtu.be/UrVnzHuTtBk](https://youtu.be/UrVnzHuTtBk)

~~~
a1k0n
Yeah, come check it out, it's pretty fun!
[https://www.meetup.com/DIYRobocars/](https://www.meetup.com/DIYRobocars/)

------
msadowski
That's super interesting! How do you generate those canvases showing the
algorithm behaviour? I think such animations could be very useful for teaching
PID tuning.

If you don't mind I would love to add this article in my next WeeklyRobotics
([https://weeklyrobotics.com/](https://weeklyrobotics.com/)) issue.

~~~
a1k0n
The canvases are just some javascript code which draw to the 2d context after
a requestAnimationFrame():
[https://www.a1k0n.net/js/steering.js](https://www.a1k0n.net/js/steering.js)

Sure, that sounds good!

------
Already__Taken
Looking forward to seeing this thing remember the line each lap and refine its
curve. At that point you're then working on traction control problems wouldn't
you?

~~~
a1k0n
Yes, that's the current state of the car. It's constantly fighting for
traction; there are some lower-level control systems trying to maintain yaw
rate (which automatically does things like counter-steering in a drift). I'll
get to that in a future post.

------
SubiculumCode
This is pretty dang cool, imo.

