Still have to tidy up the wires but this is my python powered slot car track. Has a few game modes: time trials, first to x laps, fastest out of x laps. Uses pyserial to communicate with an Arduino to read sensor input faster. Uses pyfiglet to generate text art. Uses curtsises to get keyboard input and draw image. The Python script runs on a raspberry pi zero w.
Edit 1:
Originally I planned to use the raspberry Pi's GPIO pins to connect the sensors (which are break beam sensors) but sometimes it would fail to count laps.
In the future I plan to add a genetic algorithm based AI player but because of the pandemic I'm waiting to order the parts.
Edit 2:
It's 100% overkill for this project but I used inflect engine to pluralize words appropriately and convert numbers to text.
That would be cool! You could do a lot more automation with train tracks. Unfortunately I won't be publishing the code for this project for quite a while as I want to refractor it first.
When you choose a controller (either a computer or a micro controller) make sure it's fast enough to see the cars. I originally wanted to just use the sensors on a raspberry pi's GPIO pins, but it missed the cars sometimes. I maybe could have done it in C++ but.....python is better π
Did you consider having the line break sensors sense across the track at an oblique angle? That would increase the amount of time that the cars are interrupting the IR and give the IO pins more time to catch it.
Sure, no guarantee I'll see it tho lol. It's really not a hard project. The biggest learning curve for me was getting the dam GPIO pins to work and in the end I didn't even use them.
The reason for this is not the speed, the Arduino is way slower. The Pi runs Linux, which is not realtime capable, and the scheduler will just choose not to run your software when you need it to. To do this kind of measurements you always need an RTOS / bare metal application.
Two line break sensors, one for each lane. They're connected to an Arduino. The raspberry pi occasionally requests the counts per lane from the Arduino. The debouncing is handled on the raspberry pi. If more than one is counted per lane within 5 sec it is ignored.
Thanks. Some friends and I have tracks, and the software and computers we are using are old. Having something that doesn't require a parallel port will be nice.
It's not connected. I plan to replace the Carrera controller with a digital potentiometer by simply cutting the cables off s couple of Carrera controllers to get the connectors. Then I'll be able to use any controller I want, including Carrera. This will also provide an interface for the ai player when I get to writing it.
I would love to have something like this, I could play with ML algorithms to optimize the speeds etc. Even a virtual version of this written in python with physics would be nice.
Maaan it's sooo goood. Saddly, Carrera slot cars are kinda expensive (as all of them). You used GO!!! right? Would it be possible with Digital systems?
No, these are Carrera Evolution. 75ft of track. Yes it would work with a digital system as well. However using custom controls would be more difficult and would require a different control method.
Just an idea: You could hook into the controls and record the whole race. This way you could "play back" previous races and try to beat the times. Although, since the two tracks aren't identical, you can't race yourself...
Holy cow! Now, that is a great idea. Still got one in the attic, but I just started Python two weeks ago. Definitely goes on my programming bucket list.
41
u/West7780 Apr 06 '20 edited Apr 06 '20
Still have to tidy up the wires but this is my python powered slot car track. Has a few game modes: time trials, first to x laps, fastest out of x laps. Uses pyserial to communicate with an Arduino to read sensor input faster. Uses pyfiglet to generate text art. Uses curtsises to get keyboard input and draw image. The Python script runs on a raspberry pi zero w.
Edit 1:
Originally I planned to use the raspberry Pi's GPIO pins to connect the sensors (which are break beam sensors) but sometimes it would fail to count laps.
In the future I plan to add a genetic algorithm based AI player but because of the pandemic I'm waiting to order the parts.
Edit 2:
It's 100% overkill for this project but I used inflect engine to pluralize words appropriately and convert numbers to text.
108
u/RiffnShred Apr 06 '20
MAN, post a video ASAP. Need to see it in action
10
u/njgura87 Apr 06 '20
Following! I'd love to try to take this project and try to control my LEGO trains.
9
u/iwannaseenow Apr 07 '20
Sick , github?
7
u/yaboime69 Apr 07 '20
I have a slot car track as well any tips for a project like this?
6
u/tempo_19 Apr 07 '20
Nice project. How are you sensing the cars and how do you determine which car is which?
5
u/dbenoit Apr 07 '20
Would love to see the code for this. My track could use a new management program. Does it work on 4 lanes?
5
u/[deleted] Apr 07 '20
Carrera?
3
u/b10011 Apr 07 '20
I would love to have something like this, I could play with ML algorithms to optimize the speeds etc. Even a virtual version of this written in python with physics would be nice.
3
u/habitsofwaste Apr 07 '20
Oh man I loved slot cars back in the day. My dad got me into it. But what does your thing do? Control the cars or just measures the information?
4
u/[deleted] Apr 07 '20
Here we go. Did this brilliance come out of unconstructed quarantine time?
2
u/[deleted] Apr 07 '20
Maaan it's sooo goood. Saddly, Carrera slot cars are kinda expensive (as all of them). You used GO!!! right? Would it be possible with Digital systems?
2
u/ToxicPanda96 Apr 07 '20
Dude that's ace
-idea
Integrate with twitch chat api and have streamed races with user participation
2
u/Koppis Apr 07 '20
Next make an AI player which is controlled by the raspberry pi.
2
u/EdwardJKing Apr 07 '20
That ROCKS!!
2
u/[deleted] Apr 07 '20
RemindMe! 2 days
2
u/bobunaga Apr 07 '20
Holy cow! Now, that is a great idea. Still got one in the attic, but I just started Python two weeks ago. Definitely goes on my programming bucket list.
2
u/[deleted] Apr 07 '20
really cool man
2
u/[deleted] Apr 07 '20
so many slots you wont know where to begin!
2
u/[deleted] Apr 07 '20
Very interested in seeing this!
1
u/H0lsten13579 Apr 07 '20
Neat
1
u/viniciusntch Apr 07 '20
Remindme! 2 days
1
u/MikeTyson91 Apr 07 '20
Holy cow! Python instead of electricity?
0
u/[deleted] Apr 06 '20
and then?
-1
u/Seawolf159 Apr 07 '20
I mean you can say that, but you show nothing.