Slot car racing sets have always fascinated me, and I have owned a few over the years. Unfortunately, it was always difficult to find opponents to race against beyond just a few runs. I have dabbled many times with the idea of a computer controlled opponent over the years, and finally decided to tackle it as a demo project for the 2016 Chicago International TI Faire in October 2016.
I have a lot of experience under my belt interfacing the TI computer to the real world, using the PIO, joystick and cassette port as interfaces, and therefore it was only natural for me to attempt doing this using my good old TI 99/4A computer.
The first idea I came up with was outfitting one of the slot cars with a centrifugal force sensor that could send a wireless signal to the TI equipped with a compatible wireless receiver, and thus allow the computer to adjust the speed of the car in order to keep the centrifugal force under a certain limit that would keep the car on the track. The obvious advantage here is that this would be track independent regardless of how tough and twisted the track was. I may still do that at some point, but it required a fairly large scale car and track in order to be able to accommodate the needed electronics and power supply, and I did not want to invest in a large slot car race track at this time.
The alternative idea required a different approach, with 2 problems to solve:
How to sense the location of the car on the track
How to control the speed of the car
The sensing part was solved by strategically positioning photoresistors on the track which will sense when the car is over them and thus report back a location to the computer. One only needs to know where a particular type of track starts, whether a curve or a straight, and adjust the speed of the car accordingly. These track sections will be labeled as sectors with a fixed car speed for each optimized by trial and error.
Here's the basic circuit diagram:
When the photoresistor is fully lit, i.e. there is no overlying car, then its resistance is very low and the PIO line is connected to the positive pole of the battery, and so is in a high state or 1. When the car is on top of the photoresistor, then the latter's resistance becomes very high, therefore the PIO line goes to ground or 0. From there, it's just a matter of masking in software the appropriate bit in the PIO data lines (there are 8 of them) to find out whether it is high or low and thus figure out which photoresistor got triggered. Since there are 8 available PIO lines, it's possible to detect up to 8 sectors on the track.
As for speed control, I decided to use the cassette port motor control plug for the purpose. Earlier on, I had experimented with that method to ignite a rocket motor igniter at the request of a fellow TIer (Omega) as seen in the video below:
Here, I replace the igniter with the connection to the track hand controller which is nothing but a variable resistor. The problem here is that when the relay is activated, then the slot car will get full power and will very likely fly off the track in an instant. One way I came up with to mitigate that problem was to use what I call Pulse Frequency Modulation, where full power is applied for a very brief amount of time, but then repeated frequently. The frequency of the on/off cycles will then determine the speed of the car. The frequency can be easily controlled in software and again I relied on a previous project where I control a robotic arm with the TI as detailed below (skip to 14:11 for the relevant part):
And here's the basic control circuit. I will be using a solid state relay instead of a mechanical one for durability, speed of actuation and lack of bounce.
So now we have solved both problems, and it's just a matter of experimentation and putting it all together. I created a small PCB which incorporates both the sensing and motor components as discussed above. The slot car racing set I'm using is a cheap small one which only requires 5 photoresistors. The PCB layout was designed using Circuit Wizard and the PCB was produced using a homebrew process.
And the finished product. It won't win any design awards, but hey it's functional
Here's the source code for the control program:
Below is the video of the experimentation and the completed project:
That was a fun one