Вы находитесь на странице: 1из 46

Autonomous Slot Car

Racing

Third Year Project Report


May 2013

Ganegama Vithanage Don Perera


ID number: 8091067
Supervised by: Dr. Piotr Dudek

School of Electrical and Electronic Engineering

Table of Contents
Table of Figures......................................................................................................................................... 4
Table of Tables .......................................................................................................................................... 5
Abstract..................................................................................................................................................... 6
1

Introduction....................................................................................................................................... 7

Aims and objectives........................................................................................................................... 8

Tests done on the car ........................................................................................................................ 9

Power Delivery to components and motor ..................................................................................... 11

Different configurations considered ............................................................................................... 13


5.1

1st Configuration ...................................................................................................................... 13

5.2

2nd Configuration...................................................................................................................... 15

5.3

3rd Configuration ...................................................................................................................... 18

5.3.1
6

Comparator circuit ............................................................................................................ 19

Software .......................................................................................................................................... 20
6.1

Initial EEEPROM setup ............................................................................................................. 20

6.2

Accelerometer Test .................................................................................................................. 20

6.3

Simple sensor to PWM ............................................................................................................. 22

6.4

Testing interrupts and EEPROM............................................................................................... 24

6.5

Reading values off the EEPROM .............................................................................................. 25

6.6

Main Program .......................................................................................................................... 26

6.6.1

Power Loss ........................................................................................................................ 29

Total Costs ....................................................................................................................................... 30

Conclusion ....................................................................................................................................... 31
2

Bibliography..................................................................................................................................... 32

10

Appendix ...................................................................................................................................... 34

10.1 Progress report ........................................................................................................................ 34


10.2 Project Specification ................................................................................................................ 44
10.3 Project Plan .............................................................................................................................. 45
10.4 Risk assessment ....................................................................................................................... 46

Table of Figures
Figure 1-1: Basic components of the slot car and track system [1] ......................................................... 7
Figure 1-2: chassis and body of car originally........................................................................................... 8
Figure 3-1: Track to measure maximum cornering speed..................................................................... 10
Figure 3-2: Example track using crossover ............................................................................................. 11
Figure 4-1: Power regulator and motor drive circuit ............................................................................. 11
Figure 4-2: Crossover section, shown intersection of tracks do not provide power. ............................ 12
Figure 5-1: 1st Configuration diagram..................................................................................................... 13
Figure 5-2: Example LabVIEW front panel. ............................................................................................. 14
Figure 5-3: 2nd Configuration diagram .................................................................................................... 15
Figure 5-4: LabVIEW VI connecting from Arduino to Pc ......................................................................... 16
Figure 5-5: Horizontal axis of the car...................................................................................................... 16
Figure 5-6: Bluetooth module test VI ..................................................................................................... 17
Figure 5-7: 3rd Configuration diagram .................................................................................................... 18
Figure 5-8: Final components ................................................................................................................. 18
Figure 5-9: Comparator circuit ............................................................................................................... 19
Figure 6-1: Accelerometer output .......................................................................................................... 21
Figure 6-2: Effect of changing scaling ..................................................................................................... 23
Figure 6-3: Optical markers .................................................................................................................... 28
Figure 8-1: Final car ................................................................................................................................ 31

Table of Tables
Table 3-1: Circular track speed test ........................................................................................................ 10
Table 6-1: Scaling to PWM...................................................................................................................... 22
Table 6-2: Effect of changing scaling ...................................................................................................... 23
Table 7-1: Costs ...................................................................................................................................... 30

Abstract
This project involves the creation of an autonomous slot car that can run the track at a reasonable
speed. Many designs for the component configurations were considered and tested but due to some
unforeseen circumstances the most optimal was not chosen. The final car uses an accelerometer and
two infrared sensors to recognize the track. The program will save the track to its non-volatile
memory so the car can be placed back on the track if it comes off.

1 Introduction
Slot cars are powered miniature vehicles that run on a standard Track. They are mainly used as toys
or in the competitive hobby of slot car racing but they have also been used to model highway traffic
on scenic layouts. The cars run on a track that has a groove in it. The cars are kept on the track by a
pin or blade which extends from the car to the groove in the track, the very first slot cars ran
between two rails. The term Slot car was invented to differentiate it from older Rail cars. Power
is sent to the car from two metal rails at either side of the groove to 2 brushes on either side of the
pin or blade on the car. The power supply can provide 15 volts but a potentiometer in the controller
can alter the voltage for each of the two tracks individually, in the early days the speed control was
an optional extra.

Figure 1-1: Basic components of the slot car and track system [1]

The standard cars are quite simple as it consists of a simple chassis, a fashionable interchangeable
body, a motor, a set of gears and wires connecting the brushes to the motor with a capacitor in
parallel to the motor. In the late 1930s,some mechanics/hobbyists used miniature combustion
engines to power the cars and had no control over the cars speed, this is similar to applying a
constant voltage to a modern track and running a slot car

Figure 1-2: chassis and body of car originally

The main challenge of this hobby is to adjust the speed to optimize the speed around the bends or
turns so that the cars do not come off the track; full speed on the straight (straight piece of track) and
then slow down just before the corner. The more enthusiastic of the hobbyists can and will change
almost all of the components. There is a wide variety of cars with different layouts;

different tire diameters, width and material,

different number and placements of magnets under the car( magnets attract the metal rails
embedded in the tracks and so creates more down force on the car which increases the grip
and so the maximum cornering speed of the car,

the gear ratio can be changed,

Some high speed slot cars have aerodynamic shapes so as to reduce drag and also to create
down force as air passes over the car and creates different pressure levels above and under
the car.

2 Aims and objectives


The aims of the project is to create an autonomous slot car. It will have to:

Learn the track

Deduce the optimal speed per section of track

Run the track at a reasonably fast speed

Be of lower cost than available solution

The main aim of this project is to build a car that can be placed on a track with minor modifications
and to run competitively. There are other autonomous options, most notably the Scalextric Digital
series. This product requires a special controller, power unit for the track and either a digital car or a
circuit which can be bought from then to be fitted into compatible analogue cars. The basic Scalextric
Digital set for 2 cars and track will cost 175 [2] but to get the autonomous features a Scalextric
Digital Advanced 6 Car Powerbase is required which costs 150 [3]. The price point for this project is
aiming at is 40 per car. Any track is compatible with this car and will work with that standards power
base that provides at least 12V.

3 Tests done on the car


Since the limitations in speed are mainly in the bends (turns) the first tests done were to check the
maximum speed around a full circle. The circle is standard because there is only one standard section
of 45 track.
45 curved track inside lane length =

20cm

full circle: 160cm

Diameter: 51.5cm

45 curved track outside lane length =

26cm

full circle: 208cm

Diameter: 66.25cm

Full length straight track both lane =

35cm

Half-length straight track

17.5cm

The car was first run until it reached the fastest speed without going off the track. The current drawn
was measured from the 15DC power source as this reflects the current drawn when the track has a
15VDC constant. The current measured was used to ensure a constant speed. The car was run at this
constant speed for 10 laps and then then the time are divided by ten to get a speed per lap. The 10
laps were run 5 times for each of the lanes to reduce errors due to reaction times to click stopwatch
and the accuracy of the ammeter.

Connection between the


standard Power delivery
and the circular track

Probes used to measure


current from the power

source

Figure 3-1: Track to measure maximum cornering speed

The starting current of the car is 0.33A from 15.2V and the lowest current required to keep the car
moving when already moving is 0.23A.

Table 3-1: Circular track speed test

CORNER
Outside

RUN 1
RUN 2
RUN 3
RUN 4
RUN 5
AVERAGE TIME
Current Drawn

Inside

Time
Average Time
(s/10 laps)
(s/lap)
7.35
0.735
7.59
0.759
7.15
0.715
7.18
0.718
7.99
0.799
7.31
0.731
0.7A = 10.71W

Time
Average Time
(s/10 laps)
(s/lap)
6.23
0.623
6.05
0.605
6.34
0.634
6.54
0.654
6.33
0.633
6.30
0.630
0.72A=11.02W

Average Speed
0.285
0.168
(m/s)
This shows that there is a clear reduction in speed when travelling in the smaller radius circle but the
lap time is actually lower when the cars are in the smaller radius inner circle which may mean that
this car in these conditions is actually faster if it takes the inner lane. This reduction in time is
normally compensated by allowing cars to have a crossover which allows the car to go into the other
lane and running two laps:
10

Figure 3-2: Example track using crossover

The increased power drawn from the slower car can be attributed to the increased resistance in the
variable resistor in the controller.

4 Power Delivery to components and motor

Figure 4-1: Power regulator and motor drive circuit

A Unipolar Pulse Width Modulation signal generated by the microcontroller is used to control the
speed of the motor. A unipolar pulse width modulation signal is a square wave where the equivalent
DC voltage is given by the ratio of signal ON time to the total period multiplied by the ON voltage.

11

The PWM signal is passed into the optocoupler [4] which controls a 5V regulator [5] which is used to
amplify the current from the microprocessor. The 5V regulator and the optocoupler help isolate the
sensitive Input / output microprocessor pins from the power circuit. If 10V is needed the ratio will
have to be 2/3 (2/3 * 15 = 10). The motor cannot react to the quick changes from ON to OFF so
sees it as a constant voltage. There is a considerable amount of heat generated from the transistor
which required 2 24C/W to dissipate the heat.
The microprocessor is powered with a 12V regulator [6]. The microprocessor has in built regulators
(5V and 3.3V) to power itself and the I/O. The previously mentioned 5V regulator can also be used to
power the microprocessor but the current drawn from the regulator (5V) would increase the heat
generated. Inside the confined body of the car will cause the temperature of both transistor and
regulator to increase rapidly and may damage the components. Experiments I conducted showed
that using a separate 12V regulator reduced the temperature of all the components.

Figure 4-2: Crossover section, shown intersection of tracks do not provide power.

As mentioned earlier the track provides power to the car but in some sections contain interruptions
in power like the crossover shown in Figure 4-2:
The area shown here is made of plastic so when the pickup contacts pass over this part the car will
momentarily loose power, momentum ensures the car will continue over this section but the
microprocessor will lose power. To avoid loss of power to the microprocessor there is a large
capacitor across the output of the 12V regulator. The software is also capable of continuing after a
complete power loss and this will be discussed later in the software section.

12

5 Different configurations considered


5.1 1st Configuration
Microprocessor +
Digital Accelerometer

Wireless Module

Motor

Comparator

Infrared Sensor

External Processor
Figure 5-1: 1st Configuration diagram

All processing is done externally. This method has a small microprocessor and Bluetooth module on
board. Bluetooth is preferred because most modern laptops have embedded Bluetooth capability
and Bluetooth adapters are quite common. An ideal external processor is software on a Personal
Computer preferably LabVIEW due to its many libraries including a Bluetooth library. The
microprocessor is used to relay the values from the accelerometer and IR sensor to the external
processor via the Bluetooth connection.
If the microprocessor has no Analogue to Digital Converter (ADC) both the IR sensor and the
Accelerometer need to be digital; in this case the microprocessor will need to convert the signal it
gets from the Accelerometer to numerical values then send it to the computer while a comparator
can be used to digitize the infrared sensor
If the microprocessor has an ADC a simple analogue accelerometer can be used. While a second ADC
channel can be used for the IR sensor, using a comparator will increase the processing speed as the
processor does not have to wait for the second ADC.
The data coming from the Accelerometer and IR sensor can then be processed by the computer. The
data can then be viewed in real-time through the computer which will ease troubleshooting. The
software can also be used to create a virtual track to be viewed on the screen and track the progress
of the car. Data such as the gain and sensitivity of the infrared sensors can be changed without

13

needing to stop the car. The computer will then send a numerical PWM value (0-255) to the
microprocessor which will then convert it to a PWM signal to send to the motor.
Components used in this configuration do not use much power and can be powered with one 5V
regulator. The main reason this was not used is because creating the microprocessor and Bluetooth
combination would be too time consuming. Possible solutions to this would be the BLEduino [7] or
the Lightblue Bean [8]. The Lightblue Bean would be ideal for this configuration as it has 4 PWM
ports, 2 ADC channels and a built in accelerometer but it was not available during the allocated time.

Figure 5-2: Example LabVIEW front panel.

This configuration is the most optimal as the weight will be the lowest compared the other two and
the components will be comparatively small which could ease in the placement and to keep all the
weight as low as possible.

14

5.2 2nd Configuration

Infrared Sensor
Microcontroller

Motor

Analogue Accelerometer

Wireless Module

External Processor
Figure 5-3: 2nd Configuration diagram

A microcontroller and a wireless module are on-board. The microcontroller will perform some key
functions including Using its ADC to sample analogue sensors then send digital values to the wireless
module which in turn sends this data to an external processor. This data can be saved and then
viewed in real time. The processing is done by the microprocessor i.e. the algorithm is contained in
the microprocessor. This configuration is quite flexible and can have many fail safe programs as the
processing can be done by the microprocessor or the external processor. Like in the previous
configuration some variables can be changed while the car is running and if required the
microprocessor can be reprogrammed through the Bluetooth module. This method was initially
chosen mainly due to its flexibility but the Bluetooth module purchased developed an error and
damaged the microprocessor when it failed. The Arduino UNO was used as the microprocessor [9].

15

Figure 5-4: LabVIEW VI connecting from Arduino to Pc

This LabVIEW VI was used to test the Arduino and to test the capabilities of the accelerometer to
check that various parts of the accelerometer and Arduino are functioning properly together. Two
analogue pins were tested for the x-axis and y-axis but final design only measures the acceleration
along the y-axis. The acceleration of the car along the x-axis was going to be used as well but the
increased processing time required outweighed any advantages of using it in the algorithm. A gain
was attached to the Y axis values to get a simple but varying PWM output that will be able to drive
the car around the track.

Figure 5-5: Horizontal axis of the car

The same VI was used to try and control the Arduino trough the Bluetooth module but it did not
seem to be able to connect to the Arduino.

16

Figure 5-6: Bluetooth module test VI

This VI was created to try and troubleshoot the problem and to figure out whether the problem was
with the Arduino or the Bluetooth module. The program looks for Bluetooth devices, choses the first
one (the only Bluetooth device connected to the computer is the Bluetooth module which is checked
via the device manager on Windows) displays the ID of the Bluetooth module and the various
services. It then selects the first service (the Bluetooth module has only one service: 1
communication port), displays its unique ID then sends some data and receives data from the
communication port.
Running the program revealed that the Bluetooth close function is not able to close the Bluetooth
connection so the Bluetooth module reports that it is still active so a physical reset is required.
An android phone with an application to read the communication from the Bluetooth module was
used to look further into the problem. Using a simple send function from the Arduino the
accelerometer data was sent over the Bluetooth module. This yielded some promising results as the
values from the accelerometer were seen on the phone but prior to being able to figure out the
reasons for this success the Bluetooth module ceased working so based on the amount of time
already invested and results obtained it was deemed that continuing this method would be a waste
of time.

17

5.3 3rd Configuration

Digital Accelerometer

Infrared Sensor

Microprocessor

Motor

Comparator
Figure 5-7: 3rd Configuration diagram

This is similar to the previous configuration except for the lack of the Bluetooth module. A
comparator circuit is used similar to the first configuration to reduce the time taken to process the
data.

Figure 5-8: Final components

18

5.3.1 Comparator circuit

Figure 5-9: Comparator circuit

Two TCRT5000 [10] were used as the optical sensor, the TCRT5000s have an infrared emitter
alongside the sensor. If there is no light hitting the sensor the output from the sensor is pulled to 0V
as the transistor acts like an open circuit. As the amount of light increases the transistor allows more
current through which would increase the voltage across R3 or R5, this is the voltage used as the
input. The reference voltage is provided by a voltage divider shown above. To make the reference
voltage adjustable a three pole variable resistor is used. The operational Amp [11] compares the
voltage from the sensor to the reference voltage and outputs +5V if the input from the sensor is
greater than the reference voltage else it outputs 0V.

19

6 Software
6.1 Initial EEEPROM setup
#include <EEPROM.h>
boolean Learning = true;
int currSection = 3;
boolean Start = false;
void setup(){
needed
EEPROM.write(0,Learning);
EEPROM.write(1,currSection);
EEPROM.write(2,Start);
}

//initializes the eeprom values to the type


//this initializes the zeroth element to boolean
//first element int
//second element boolean

void loop(){
}

This program is needed to ensure the variables on the EEPROM (Electrically Erasable Programmable
Read-Only Memory) is in the correct format/type i.e.; int (integer), boolean.
This will ensure that there are no errors when requesting values: it will ensure the variable type
requested by the main program is the same as the value saved in the EEPROM. The programmer
cannot check for these errors when it is verifying the code.
This program is only to be run once if a new Arduino is used or the EERPROMs first three elements
have been rewritten.

6.2 Accelerometer Test


void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println(analogRead(0));
//
delay(500);
}

//initializes the serial communication

//reads the analog pin 0 then sends it over


the serial communication port

20

This program is used to ensure the Accelerometer [12] and ADC work correctly.
Shown below is an example output from this program

Figure 6-1: Accelerometer output

During the above example, the accelerometer was given an excitation of +g and g (g = 9.80665 m/s2
acceleration due to gravity) along the Y-axis (only the y axis values are shown above). The value of
116 is obtained when there is no acceleration along the y axis. Values of 91 and 141 are obtained
with g and +g respectively giving an approximate 25 per g.

21

6.3 Simple sensor to PWM


int val = 0;
void setup(){
pinMode(6,OUTPUT);
}
void loop(){
val = analogRead(0);

//read analog pin 0

val = val -116;


val = abs(val);
val = val*10;
if (val <= 0){val = 0;}
if (val >= 255){val = 255;}
val = 255- val;
val = val*0.8;

// scaling
//the analog
//value to
//pwm which
//can be sent
//to the motor
//scaling the final value down

analogWrite(6, val);

//generate the PWM signal

This program scales the output of the ADC connected to the accelerometer (val) to control the car
such that the car goes faster on the straight and slower around the corners.

Table 6-1: Scaling to PWM

Line of code\acceleration -g

+g

Output of ADC 91
val = val -116; -25
val = abs(val); 25

116
0
0

141
25
25

val = val*10 250


val = 255- val; 5

0
255

250
5

As see above a lower a lower lateral acceleration results in a higher PWM value which means an
increase in speed.

22

In the piece of code (val = val*10 ) the number 10 can be changed to adjus the acceleration to spped
ratio. A Larger number such as 10 would mean a small lateral acceleration will result in a large
decrease in speed and a smaller value will result in a smaller decrease in speed.
250
200
150
100
50
0
-9.8

9.8

Lateral acceleration (m/s^2)


val *10

val * 7.5

val * 5

Figure 6-2: Effect of changing scaling

Table 6-2: Effect of changing scaling

Lateral Acceleration
-9.8

9.8

255

VAL * 7.5

67.5

255

67.5

VAL * 5

130

255

130

VAL *10

Currently the speed of the car is limited by the weight and the fact that the centre of weight of the
car is relatively high.

23

6.4 Testing interrupts and EEPROM


#include <EEPROM.h>
volatile int state = LOW;
volatile int state1 = LOW;
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
attachInterrupt(0, blink, RISING);
attachInterrupt(1, blink1, RISING);
}
void loop()
{
digitalWrite(13, EEPROM.read(1));
digitalWrite(12, EEPROM.read(0));
}
void blink()
{
state = !state;
EEPROM.write(1,state);
}
void blink1()
{
state1 = !state1;
EEPROM.write(0,state1);
}

The comparator circuit shown before is used to change the analogue values of the IR sensors to a
digital signal when they detect the start of the lap and the start of every section. These signals are
used to drive two interrupts. In this test the signals toggle on and off the two LEDs independently
(connected to Pin 13 and 12).
EEPROM storage is used as it is a form of non-volatile memory; this memory does not get erased
when there is a loss in power.
Saving the state of the LEDs in EEPROM means that the LEDs will still have their values after the
Arduino has been turned off.

24

6.5 Reading values off the EEPROM


#include <EEPROM.h>
int count = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
if(count >= 200)count = 0;
Serial.println(EEPROM.read(count));
delay(500);
count++;
}

Example output:
0

The value of learning currently 0 = false as the learning phase was over

13

The value of the last piece of track the car was on

the value of Start 1 = true, it has started the program

183
156
116
135
145
156
161
147
137
37
73
76
100
152
159
This program is used to check the values written to the EEPROM
The first value is the boolean value Learning, the second is the int currSection the third is the boolean
Start.

25

6.6 Main Program


#include <EEPROM.h>
volatile int val = 0;
volatile boolean Learning = EEPROM.read(0);
volatile boolean Start = EEPROM.read(2);
volatile int currSection = EEPROM.read(1);
volatile float sum = 0;
volatile float count = 0;
volatile int mtr = 100;
//current motor PWM value
volatile int mtrB = 110;
//previous motor PWM value
volatile float avg = 0;
//average of val
volatile int state = LOW;
//state of LED
void setup(){
pinMode(13, OUTPUT);
pinMode(12, INPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
attachInterrupt(0, inter02, RISING);
attachInterrupt(1, inter14, RISING);
digitalWrite(8,HIGH);//
digitalWrite(7,LOW);
}

//left sensor
//right sensor

void loop(){
Learning = EEPROM.read(0);
Start
= EEPROM.read(2);
currSection = EEPROM.read(1);
if (digitalRead(12) == HIGH){

//refreshes Start and


//Learning every loop
//Initializing using a pin

EEPROM.write(0,true);
EEPROM.write(1,3);
EEPROM.write(2,false);
}else{
if(Learning){
count++;
analogWrite(6,100);
delay(5);
val = analogRead(0);
//Serial.println(val);
val = val -116;
val = abs(val);
val = val*4.5;
if (val <= 0){
val = 0;
}
if (val >= 255){
val = 255;
}
val = (255- val) * 0.85 ;
sum = sum + val;
}else{

26

if((mtrB-mtr)>35){
analogWrite(6,0);
delay (50);
}
analogWrite(6,mtr);

//brake
//delay in milliseconds sets the
//amount of time braking occurs
//generates a PWM signal

}
}
}
void inter14(){
if(Learning){
avg = sum/count;

//right sensor interrupt


//calculates the average of the
//accelerometer values sampled
//writes the average to EEPROM
//reset sum
//reset count
//increments the counter that
//indicates the current
//section of track then saves
//it to the permanent memory
//reset val

EEPROM.write(currSection,avg);
sum = 0;
count = 0;
currSection++;
EEPROM.write(1,currSection);
val = 0;
}else{
mtrB = mtr;
mtr = EEPROM.read(currSection);
currSection++;
EEPROM.write(1,currSection);
}

//saves the previous track's val


//reads the current track's val
//increments current section

}
void inter02(){
state = !state;//
digitalWrite(13,state); //
if(Start){
if(Learning){
avg = sum/count;
EEPROM.write(currSection,avg);
sum = 0;
count = 0;
val = 0;
EEPROM.write(1,currSection);
}
Learning = false;
EEPROM.write(0,false);
currSection = 4;
EEPROM.write(1,3);
}else{
Start = true;
EEPROM.write(2,true);
}
}

//left sensor interrupt

//cals avg save it


//like the previous interrupt
//reset val,count and sum

//indicates learning is complete


//reinitializes the current section
// to the first track

27

Figure 6-3: Optical markers

When the car is initially placed on the track the car has a constant velocity of 40%. The car will come
over the start of the lap denoted by the white strip on the left. As seen above the left sensor
interrupt will be triggered before the start section marker (white strip on the right). The left interrupt
will initially only set the Start boolean variable to true which allow the car to only start implementing
the recorded data after the next pass over the start line.
The ADC constantly samples the accelerometer and then this value is stored in val. This is then scaled
to end up with a viable PWM output which is ready to be sent to the motor as described in section
5.3. This value is then summed up over a period of time while taking count of the amount of data
being summed up. When the right sensor interrupt is triggered the average is taken. This average is
then stored in the EEPROM in the with respect to the section of the lap it is on. The sum, val, and
count are reset. The variable containing the number of the current section of track the car is currently
on (currSection) is incremented.
The incrementation of count in the main loop is placed prior to the sum being calculated. If it was
placed after sum has been calculated there is a chance of the interrupt occurring prior to count being
incremented causing a higher than expected motor speed which may cause the car to go off the
track. The interrupt will reset sum, val and count so if the incrementing if count is placed near the
end of the loop this will register an increased count causing a less than optimal average.
When the car passes over the start line again the boolean Learning will be disabled which cause the
car to implement a recall mode. This will also count as the end of the current section of track and so
will calculate and save the average into the EEPROM as in the right interrupt; this only happens when
learning is still true, only during the second pass over the start. During the first crossing of the start
28

line val is being calculated so the section of track prior to the start will have its value saved in the
third element of the EEPROM. To avoid this, the second passing of the start line will cause the
program to start reading the values from the fourth element onwards; currSection is set to 4 and will
count forward from there.
From the second lap onwards the car reads the PWM value from the memory to send to the motor.
The PWM value written gets updated every time the right interrupt is triggered. If the left interrupt is
triggered (car goes over start) the currSection gets initiated to 4 again and the car continues reading
from the EEPROM.
Resetting the car to learn a new track or relearn the current track can be done by applying 5V across
the pin 12, this will turn Learning true, Start false and currSection to 3.
Variables used in both the ISR function and the mail Loop function need to be declared as volatile.
This tells the compiler that the variables may change out of sync with the main code and to load the
variable from the RAM rather than the storage register.
6.6.1 Power Loss
As mentioned earlier there is a fairly large capacitor across the 12 regulator output which will keep
the Arduino running for a second and a half but what happens if the car comes off the track? It will
need to relearn the whole track.
Using the permanent values stored in the EEPROM the car will not need to relearn the track.
Currently the car cannot resume if it leaves the track during the learning phase as the values from the
accelerometer will corrupt the data; a possible solution is to check the values with the previous two
values from the same section of track and reject the value if it deviates by a large amount (as would
be expected if the car leaves the track).
Due to the fact that all the variables controlling the various phases and the final PWM values being
stored on the permanent memory the car will be able to re-join the track and continue given that the
car is placed anywhere on the section of track the car originally came off of. The first section of track
after re-joining will be done on 50% speed initially then from the next section onwards the car will
resume as normal.
29

7 Total Costs
Table 7-1: Costs

COMPONENT

QUANTITY

PRICE PER UNIT TOTAL PRICE

Cars
Track
Arduino Uno R3

1
1
1

25
27
15.65

25
27
15.95

solder less Breadboard

3.6

3.6

extractor Set

3.55

3.55

Analog Devices - ADXL335BCPZ - IC,


Accelerometer, 3 Axis

3.47

3.47

VISHAY SEMICONDUCTOR - 4N25 OPTOCOUPLER

0.27

1.08

ROHM - BA033T - LDO, FIXED, 3.3V,


1A, TO-220FP-3

1.05

2.1

JY-MCU HC-06 Wireless Bluetooth


transceiver module for Arduino

5.89

5.89

Vishay Semiconductor - 4N25 Optocoupler

0.27

1.08

Arduino Uno Atmega328

18.05

18.05

INTERNATIONAL RECTIFIER IRL3803VPBF - MOSFET, N, LOGIC, TO220

1.81

1.81

Aavid Thermalloy - 507302B00000G Heatsink, TO-220, 24C/W

0.233

0.932

Arduino Uno Atmega328

18.05

18.05

Arduino Uno Atmega328

18.05

18.05

TOTAL

145.612

As seen above I have used four Arduinos. During assembly a 15V lead was attached to the 5V input
pin due to improper wiring where there was a confusion of colours. As mentioned earlier the second
Arduino was damaged due to fault in the Bluetooth module. The third Arduino developed a fault
which resulted in a corrupted boot loader, an attempt was made to reinstall the boot loader but
there was no success.
30

8 Conclusion
The project start was delayed due to the late arrival of the ordered cars and track pieces. Further
delays ( failing Arduinos and Bluetooth module) set back the project further causing the first
hardware prototype available mid semester two and the first fully functioning car was available in
week 10 just prior to the start of the Easter vacation.
Further developments could have been done on the Bluetooth communication to allow more
complex algorithms run by the computer.
Possibilities of using bipolar PWM to increase the braking effect to counter the increased weight of
the car were considered but were not implemented due to time constraints, inefficiency and
increased heat generated in the motor.
The car currently works as planned but the speed is less than optimal and further optimization is
needed to match the speed of a much lighter stock car.

Figure 8-1: Final car

31

9 Bibliography

[1] D. H. (. u. D.Helber), Wikipedia, 15 February 2007. [Online]. Available:


http://en.wikipedia.org/wiki/File:SlotcarElecCircuit.png.
[2] Scalextric, Scalextric Digital Racer Set, [Online]. Available:
http://www.scalextric.com/shop/sets/digital/c1327-scalextric-digital-racer-set/.
[3] Scalextric, Scalextric Digital Advanced 6 Car Powerbase, [Online]. Available:
https://www.scalextric.com/shop/pit-lane/power-and-controllers/c7042-advanced-6-cardigital-powerbase/.
[4] Semiconductors, Vishay, 4n25, [Online]. Available:
http://www.vishay.com/docs/83725/4n25.pdf.
[5] Fairchild semiconductor, 7805, [Online]. Available:
http://www.fairchildsemi.com/ds/LM/LM7805.pdf.
[6] Texas Instruments, 7812, [Online]. Available:
http://www.ti.com.cn/cn/lit/ds/symlink/lm7805c.pdf.
[7] BLEduino, [Online]. Available: http://bleduino.cc.
[8] Punch Through Design Light blue Bean, Punch Through Design, [Online]. Available:
http://launch.punchthrough.com.
[9] Arduino, [Online]. Available: http://arduino.cc/en/Main/arduinoBoardUno.
[10] Vishay Semiconductors, TCRT5000, [Online]. Available:
http://www.vishay.com/docs/83760/tcrt5000.pdf.
[11] Microchip, MCP6001, [Online]. Available:
http://ww1.microchip.com/downloads/en/DeviceDoc/21733j.pdf.

32

[12] ANALOG DEVICES, ADXL335, [Online]. Available: http://www.analog.com/static/importedfiles/data_sheets/ADXL335.pdf.

33

10 Appendix
10.1 Progress report

Introduction
Slot cars are powered miniature vehicles that run on a standard Track. They are mainly used as toys
or in the competitive hobby of slot car racing but they have also been used to model highway traffic
on scenic layouts. The cars run on a track that has a groove in it. The cars are kept on the track by a
pin or blade which extends from the car to the groove in the track, the very first slot cars ran
between two rails. The term Slot car was invented to differentiate it from older Rail cars. Power
is sent to the car from two metal rails at either side of the groove to 2 brushes on either side of the
pin or blade on the car. The power supply can provide 15 volts but a potentiometer in the controller
can alter the voltage for each of the two tracks individually, in the early days the speed control was
an optional extra.

34

Figure 1: Basic components of the slot car and track system [1]
The standard cars are quite simple as it consists of a simple chassis, a fashionable interchangeable
body, a motor, a set of gears and wires connecting the brushes to the motor with a capacitor in
parallel to the motor. In the late 1930s,some mechanics/hobbyists used miniature combustion
engines to power the cars and had no control over the cars speed, this is similar to applying a
constant voltage to a modern track and running a slot car

Figure 2: chassis and body of car being worked on currently


The main challenge of this hobby is to adjust the speed to optimize the speed around the bends or
turns so that the cars do not come off the track; full speed on the straight (straight piece of track) and
then slow down just before the corner. The more enthusiastic of the hobbyists can and will change
almost all of the components. There is a wide variety of cars with different layouts;

different tire diameters, width and material,

different number and placements of magnets under the car( magnets attract the metal rails
embedded in the tracks and so creates more down force on the car which increases the grip
and so the maximum cornering speed of the car,

the gear ratio can be changed,


35

Some high speed slot cars have aerodynamic shapes so as to reduce drag and also to create
down force as air passes over the car and creates different pressure levels above and under
the car.

Aims and Objectives


The aims of this project is to create an autonomous Slot car. The car should be able to memorize the
track within one lap and then run the track as fast as or ideally faster than if a human were
controlling a similar car. This car is aimed at enthusiasts and even household consumers to test their
skills against. There are other autonomous slot car solutions, notably the Digital car and track set
from Scalextric but tis digital system requires for one to have digital enabled cars and tracks.
The major aim of this project is that the car can be placed on any track and run competitively with
little modifications; the only modification needed is small white reflective strips placed at the start of
each track section, the placement does not have to be exact.

Progress to date
Tests done on the car
Since the limitations in speed are mainly in the bends (turns) the first tests done were to check the
maximum speed around a full circle. The circle is standard because there is only one standard section
of 45 track.
45 curved track inside lane length =

20cm

full circle: 160cm

Diameter: 51.5cm

45 curved track outside lane length =

26cm

full circle: 208cm

Diameter: 66.25cm

Full length straight track both lane =

35cm

Half-length straight track

= 17.5cm

The car was first run until it reached the fastest speed without going off the track. The current drawn
was measured from the 15DC power source as this reflects the current drawn when the track has a
15VDC constant. The current measured was used to ensure a constant speed. The car was run at this
constant speed for 10 laps and then then the time are divided by ten to get a speed per lap. The 10
36

laps were run 5 times for each of the lanes to reduce errors due to reaction times to click stopwatch
and the accuracy of the ammeter.
Connection
between the
standard
Power
delivery and
the circular
Probes used
track
to measure
current from
the power
source
Figure 3: track to measure maximum cornering speed
Corner
Outside

Inside

Run 1

Time
(s/10 laps)
7.35

Average Time
(s/lap)
0.735

Time
(s/10 laps)
6.23

Average Time
(s/lap)
0.623

Run 2

7.59

0.759

6.05

0.605

Run 3

7.15

0.715

6.34

0.634

Run 4

7.18

0.718

6.54

0.654

Run 5

7.99

0.799

6.33

0.633

Average time
between the
runs
Current drawn
from 15.3v
source
Average Speed
(m/s)

7.31

0.731

6.30

0.630

0.7A = 10.71W

0.72A=11.02W

0.285

0.168

Table 1: Circular track speed test

37

This shows that there is a clear reduction in speed when travelling in the smaller radius circle but the
lap time is actually lower when the cars are in the smaller radius inner circle which may mean that
this car in these conditions is actually faster if it takes the inner lane. Another surprise is the power
consumption, the slower car in the inner lane uses 0.3W more than the faster car in the outer lane;
this may be caused by over steer causing the rear wheels to slide about.
The starting current of the car is 0.33A from 15.2V and the lowest current required to keep the car
moving when already moving is 0.23A. Using:
P=I*V

(1)

The power loss in the drivetrain is a maximum of 5.0W and a minimum of 3.5W, these values will
increase with the weight of components put in the slot car.

Power Delivery to components and motor


A Unipolar Pulse Width Modulation signal generated by the microcontroller is used to control the
speed of the motor. A unipolar pulse width modulation signal is a square wave where the equivalent
DC voltage is given by the ratio of signal ON time to the total period multiplied by the ON voltage.
The PWM signal is passed into the optocoupler to then control the 15V going into the motor. E.g. if
10V is needed the ratio will have to be 2/3 (2/3 * 15 = 10). The motor cannot react to the quick
changes from ON to OFF so sees it as a constant voltage.

38

Figure 4: Basic circuit layout


The power delivery circuit contains a regulator that outputs 5 volts but it is inefficient because it is
known to dissipate twice the power it provides to the 5V output. A buck regulator was considered
due to its utilization of a switching circuit which is more efficient but it is more expensive and needs
more components to run properly, the power drawn from the current setups 5V is acceptably low
(varies with the number of Input/output used on the microcontroller) so the regulator is being used.
The data connection between the microcontroller and Bluetooth module has been highly simplified
into one wire to have a neater circuit diagram.
The accelerometer outputs the acceleration through the x axis and the y axis as a voltage that can
then be read by the ADC on board the microprocessor.

Different processing methods considered


1st Processing method
All processing is done on the car. This method uses a microprocessor on board, Arduino, to sample
the accelerometer and infrared sensor then store the data, process the data into an easily
implementable PWM value to control the motors. The sensors can either be analogue or digital as
the microcontroller will have multiple ADC inputs. The advantage is that only one extra component
(microcontroller) over the standard accelerometer and infrared sensor is needed. But the

39

disadvantages are that the variable of the program can only be changed if one reprograms it. Real
time data is not available so it will be a bit harder to debug the algorithm.
INFRARED SENSOR
MICROCONTROLLER

MOTO
R

Analogue
ACCELEROMETER
Figure 5: 1st processing method
2nd Processing method

All processing is done externally. This method only has a wireless module on board. Bluetooth is
preferred because most modern laptops have embedded Bluetooth capability and Bluetooth
adapters are quite common. An ideal external processor is software on a Personal Computer
preferably LabVIEW due to its many libraries including a Bluetooth library. The wireless module is
connected to both the accelerometer and Infrared sensor, but both the sensors have to be digital
because most Bluetooth modules do not have an ADC. Accelerometers are available with digital
outputs but a comparator circuit is needed for the infrared sensor. The software on the PC will be
able to process all the data and store the data. Data can now be seen in real time easily by some
simple Graphical user interface. Without a dedicated PWM signal generator the computer software
will have to generate a PWM then send it through one of the channels of the Bluetooth module
which is then sent to the optocoupler. Similar to method one only one extra component is needed.
Variable can be changed by using a graphical user interface so the car does not need to stop to adjust
noncritical data (critical data is data that cannot be changed while the program is running such as the
Bluetooth channel being used).

40

Digital ACCELEROMETER

WIRELESS MODULE

MOTO
R

INFRARED SENSOR

Comparator

EXTERNAL PROCESSOR

Figure 6: 2nd processing method


3rd Processing method
A microcontroller and a wireless module are on-board. The microcontroller will perform some key
functions including Using its ADC to sample analogue sensors then send digital values to the wireless
module which in turn sends this data to an external processor. This data can be saved processed and
then viewed real time. The external processor then sends a digital value to the wireless module which
then sends it to the microprocessor to then write it to the built-in PWM controller for the
optocoupler. This method is quite flexible and can have many fail safe programs as t can either be
based on this method or method one. This method needs both a microprocessor and a blue tooth
module so it may be the most expensive. Like in method two some variable can be changed while the
car is running. This method was chosen mainly due to its flexibility.

41

INFRARED SENSOR
MICROCONTROLLER

MOTO
R

Analogue
ACCELEROMETER
WIRELESS MODULE

EXTERNAL PROCESSOR

Figure 7: 3rd processing method

Problems encountered
The main problem faced was the renewal of the finance system for orders so orders were placed late
and arrived late as well. Due to the unknown size and shape of the interior of the car no components
could be ordered in case the components do not fit in the car.

The next steps

Test the Arduino to make sure all the features needed work as planned.
42

Printing out a PCB that will get screwed on between the chassis and the body.

Test and make sure the power circuit is working and does not take power away from the
motor as the power supply may have a fixed maximum current.

Run tests on the Buck regulator to see if the performance can outweigh the cost of the
component.

Conclusion
The majority of time sent on the project was spent researching the various possible methods to
control the buggy and if the components needed were too expensive or too big because the smaller
and easier a component is to install and implement the more expensive it gets. The choice was made
and this choice will bring up challenges but the outcome will be a clean and innovative design.

References
[1] Photo SlotcarElecCircuit.png from http://en.wikipedia.org/wiki/Slot_car

43

10.2 Project Specification


Project Title: Autonomous Slot Car Racing
Slot car racing is where model cars are run on a track with a slot in the track. The DC motor in the car
is controlled by varying the voltage on the metal tracks by potentiometers in a controller.
If the slot car can be automated the lap times can be reduced. A marker on each section of the track
helps in learning the track to optimise the speed into and out of corners. Processors placed on the car
or externally (example: on a computer) can either learn the track or process the track real time so
that the cars may be able to go faster than if a person were controlling it.

44

10.3 Project Plan

45

10.4 Risk assessment

46