onsdag 6. april 2016

Scalextric Digital APB Project

A friend of mine bought him self a Scalextric Digital slot car race set which I have found quite amusing, both due to its possibilities as well as racing! Regarding the possibilities I learned that the APB got an AUX-port on one of the side which let users connect PC's to the base and communicate with it and eventually the cars. The slot car it self got some sort of LED underneath which sends signals to sensors placed on the track, which is used for timing and such.

This gave me one good idea; What if i could drive the car automatically and fine tune its speed through each corner to win a race? Before and after each corner I would place sensors which would read and decode signal from each car passing.

First I was in the need for an API which would let me communicate with an Advanced Power Base(APB) (Scalextric C7042 APB) and to perform just three simple things - speed up/down and brake the car.

Project is broken into two different parts
  1. Get control over the car via the APB.
  2. Create a IR-controller which reads signals from the car decodes it and sends it to the Car-controller
First part could easily be achieved by following the documentation found on Jackaments software' webpage. This documentation is released by Horby - the manufacturer of Scalextric systems. Jackaments software have created a Race Management System (RMS) for Scalextric, but I did not find it to fit my needs, nor would i learn much about the base it self. Thus i wanted to create an interface for communicating with the base. The second part is by far the greatest challenge as i didn't find anything regarding the car's LED in the documentation.

Connection

A key part in this project is the cable which would go from the computer to the base. According to the APB-specifications i would need an RS485 converter of some sort. When i measured voltage between D+ and D- on the base I found that the voltage was around 5 volts, so i decided to try communicating via an Westermo MDW-45 RS232/RS485 converter without any luck. I opened the display which comes along with the APB to see if i could find any information regarding RS485-chips used and next to the PIC was a chip which was named 75176B.

After a quick search I ended up with some information about its being a RS485 chip of some sort. Luckily FTDI chips support this and I were able to communicate with the APB using USB-RS485-WE-5000-BT.  

 
Electrical schematics.

Note1: Pin5 on APB is 18VDC, which is the power supply for the display usually connected to AUX-port.
Note2: Be aware of the RJ11 connectors orientation, which is marked on the top by a "tap".

Advanced Power Base-controller

Liek mentioned above i only needed to send some packets to control the car speed, brakes and lane change, but ended up with something that could parse the OutPackets as well. This could be quite handy for future use regarding each cars start / finish time. The packets aren't handled directly but rather through the APB-controller.
An APB-instance has several methods implemented such as enable car / track and drive each car ID individually. The APB instance is initialized with 6 Car-instances with ID from 1 to  6, and are available through an readable attribute called #cars.

Communication with the base is initiated with instance-method #start. This will create an communication thread which sends and receives packages until #stop is called. While communication is on-going Car-objects can directly be modified by users and is sent in the next communication cycle. As of writing this blog I set each cycle to be performed each 0,05 secs.

Basic example:
base = APB.new
base.start
base.enable_car(1)
base.disable_red_led
base.run_car(1, 40)
base_run_car(1,20)

Code is available at Github and further documentation is found there.

Next up would be the Sensor-controller which is addressed in part two of this post.

Resource

SNC Protocol Specifications

Scalextric Sport Digital Console

Scalextric Advanced 6-car Power Base (C7042)