Sunteți pe pagina 1din 29

PAWEL KECERSKI

! ! !

Autonomous Slot Car Racing


Final Project Report

!
Pawel Kecerski 7938361 May 2014

!
! Supervisor: Dr Piotr Dudek School of Electrical and Electronic Engineering"

PAWEL KECERSKI
Autonomous Slot Car Racing!

AUTONOMOUS SLOT CAR RACING


1

1. Introduction!
(i) Aims & Objectives! (ii) Background! (iii)Initial Specication!

1
2 3 5

2. Hardware Selection!
(i) The Microcontroller! (ii) Accelerometer! (iii)Optical Sensors! (iv)Bluetooth! (v) Motor Control! (vi)Voltage Regulator!

6
6 9 10 11 12 14

3. Hardware Integration !
(i) The Microcontroller! (ii) Accelerometer! (iii)Optical Sensors! (iv)Bluetooth! (v) Motor Control! (vi)Voltage Regulator!

15
15 16 19 21 22 23

4. Software!
(i) Algorithm Outline! (ii) Velocity Limits!

24
25 27

TABLE OF CONTENTS

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

1. INTRODUCTION
In the contemporary world of ours, electronics and small embedded systems are ubiquitous and their use has never been more prevailing. Take for example the machine that is present in over 1 billion specimens worldwide1.1 and without which humanity cannot even imagine simple, day-to-day existence - the automobile. Even such a common invention is nowadays tted with over a hundred separate electronic control units, or ECUs1.2. Those are separate microcomputer systems used to monitor and govern various elements of both the cars environment and its internal operation. The purpose of ECUs can occupy a wide range of possibilities, from such crucial features as fuel injection control or ABS, through A/C and park assist up to functions so trivial as memory-wise electronic seat adjustment or bad-air detection.! This project, however, does not deal with systems as complex as modern vehicles. Rather, it focuses on the use of embedded electronics on a simple slot-car, i.e. a Scalextric toy. It provides an insight into the world of vehicular electronics, as it requires the design and functional implementation of an embedded system onto the car. The project may sound simple in theory, but it requires extensive research and testing to create an operative embedded system, comprising of sensors and actuators; a system that is fully capable of interacting with the outside world, much like a regular automobile.!

!
INTRODUCTION PAGE "1 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(i) AIMS & OBJECTIVES


The main aim of this project is relatively straightforward: to modify a regular Scalextric slot-car into an autonomous vehicle, so that it is capable of nishing a lap of a previously unknown track without any human interaction whatsoever. In order to do this, means of interacting with the environment are needed - the car must be able to recognise its position on the track and adjust the speed accordingly. In fact, it is precisely because it is such a simple system that speed is the only control parameter that can be adjusted.! Below is a list of milestones that need to be achieved in order to guarantee the correct operation of the vehicle and thus the success of the project:! 1. Component research, selection and ordering! 2. Sensors and actuators development! 3. Hardware implementation! 4. Programming and testing! 5. Algorithm development!

!
In addition to that, several deliverables are essential for the Third Year Project, but their detailed description can be found in the Appendices.!

! !
INTRODUCTION PAGE "2 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(ii) BACKGROUND
Scalextric is a popular toy company, that is mostly recognised for its slot-car. The toy comprises of three main elements - the track, the controller and the vehicle. Each of this components plays an important part in the correct operation of the entire system. The track is connected to the mains via a 15V power supply and this is the

Fig. 1. The two metallic rails featured on the track. only source of power available, both for the unmodied toy and for the purpose of the project. There are two metallic rails along the whole length of the track (Fig. 1.),

Fig. 2. The inside of the controller, showing the variable resistor. and this is where the voltage to the car is supplied; the amount of said voltage being regulated by a simple variable resistor that is placed in the controller (Fig. 2.).

INTRODUCTION

PAGE "3 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

Because each pilot is connected to a separate rail, it allows two users to independently control their cars and hence - race with one another. The car is a simple device, which features solely a DC electric motor which is powered by

Fig. 3.a Inside of the car, showing the DC motor.! Fig. 3.b The chassis, showing the brush contacts. brushes that maintain contact with the rail on the track (Fig. 3.a). The car is rearwheel drive only, and it can be inspected that the from axis does not even make contact with the track. Instead, there is a plastic rudder that ensures that the car stays in the allocated slot (Fig. 3.b).! As can be seen, the toy is a very simple electronic systems that lacks the presence of any commanding microprocessor or even additional components. Therefore it is clear that multiple modications must be carried out in order to full the tasks aims."

INTRODUCTION

PAGE "4 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(iii)INITIAL SPECIFICATION
From the background research it is clear that in order to successfully modify the slot-car, multiple components are necessary. First of all, the vehicle needs means of recognising its position on the track, monitoring the environment. Moreover, some manner of measuring and adjusting speed is necessary. It would be advantageous to have a way to communicate with the car using a laptop or a smartphone. Last but not least, a microcontroller must be tted within the car in order to govern all of the above modications, ensure that they cooperate with each other and to perform all of the necessary, on-board computations.!

Fig. 4.a and 4.b The markings of a new track piece and the end of a lap, respectively. In order to simplify the project and to reduce the amount of hardware and operations involved, it has been decided that the track is modied as well. As it consists of a nite amount of track-pieces, it has been decided that the start of each one will be marked by a white line on one side of the rail (Fig. 4.a). Furthermore, the end of the lap will feature a similar white line, but it will be on both sides of the car (Fig. 4.b), so as to enable the car to recognise when it has nished a full lap of the track."

INTRODUCTION

PAGE "5 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

2. HARDWARE SELECTION
As is the case with any embedded system, it comprises equally of hardware and software to guarantee its proper operation. Therefore it is imperative that hardware is selected appropriately and that it is implemented correctly, as without hardware there can be no functioning software and hence - a complete system. In this project, the selection starts with the most important piece, that is:!

(i) THE MICROCONTROLLER


The microcontroller is the heart and brain of every embedded systems. It processes external inputs, governs data, performs computations upon it and, probably most crucially, manages the actuators. There are many microprocessors available on the market, and without proper research it is very difcult to select the correct one. They differ in speed, the number and characteristics of input/output interfaces and the programming experience. ! After careful consideration and some initial work with one microprocessor (Texas Instruments CC2541 - see Progress Report in the Appendices), the mbed LPC1768 microcontroller has been selected. The CC2541 has been discarded, as it is a Systemon-Chip2.1 solution and therefore it is incredibly difcult to use it in prototyping and early device development. Moreover, it does not come with a ready-made compiler/ debugger and hence it has been decided that a large amount of time would be spent on trying to correctly setup and operate the microcontroller. !

HARDWARE SELECTION

PAGE "6 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

On the other hand, the mbed is a unique microcontroller that is mainly used in prototyping all sorts of small electronic devices, which makes it perfect for this project. It comes as a small DIP-package (Fig. 5) and can easily be used with a breadboard to test and develop all of the necessary I/O peripherals. One of the main advantages of the mbed over other researched microcontrollers is its simplicity in

Fig. 5. The LPC1768 microcontroller.2.2 compiling and debugging programs. It features a built-in USB programmer which gives it the functionality of drag-n-drop programming, without the need for any additional software. The compiler itself is web-based and this allows the user to save his programs in the cloud and access them at a convenient time from any webenabled computer. This has been incredibly important to me, as the OS of choice for me is Mac OSX and this online, drag-n-drop programming allowed me to work on the project from the comfort of my own house, without the need to use the Universitys facilities and Windows-based computers. Furthermore, during the course we have had experience with the Microchip PIC18LF8722 and it has been

HARDWARE SELECTION

PAGE "7 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

decided that a different microcontroller and architecture would be advantageous for further academic work and enhanced experience.!

Fig. 6. Pinout of the mbed LPC1768 microcontroller.2.3 However, this is by far not the end of the mbeds advantages and its usefulness in this project. As shown before, the slot-car must be equipped with at least two sensors, means of communication with other computers and a way to control the voltage applied to the DC motor. The mbed is a microcontroller with a 32-bit ARM Cortex-M3 running at 96MHz. It includes 512KB FLASH, 32KB RAM and lots of interfaces2.4. From the pinout in Fig. 6., we can see that it features two SPI and two I2C subsystems, which can be used when interfacing with I/O peripherals. It also has a number of Analog, Digital and PWM-enabled pins, incredibly useful for controlling the DC motor voltage. ! A link to the LPC1768 datasheet can be found in the Appendices.!
HARDWARE SELECTION PAGE "8 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(ii) ACCELEROMETER
As concluded beforehand, the only parameter that is adjustable in the slot-car is its speed, because it is placed inside the metallic rail. However, it can fall off the track, when its speed is to great during cornering and therefore it is imperative to have some means of measuring its speed or a related parameter. Basic physics tells us that the car is prone to derailing due to the centrifugal force acting on it.2.5 Hence it has been decided that an accelerometer should be tted on the Scalextric car in order to provide a reliable means of measuring that force.!

Fig. 7. The ADXL345 accelerometer.2.6 The Analog Devices ADXL3452.7 has been selected, because during research it has been found to be used in many small embedded system applications. It is a threeaxis device, which allows it be placed in any plane relative to the slot-car. Moreover, it comes in a DIP package which makes it perfect for development using breadboards. This allows for a much more in-depth design stage and reduces the probability of hardware failure further down the course of the project. It is a smallpower device, capable of measuring both static and dynamic acceleration,

HARDWARE SELECTION

PAGE "9 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

depending on its use. Due to its high resolution (up to 4mg per least signicant bit) it can measure static tilt of 1.0 and dynamic force of 16g. The output data is formatted as twos complement 16-bit and can be transmitted through either SPI or I2C interfaces, both of which are available on the mbed. Another feature which makes it work in tandem with the microcontroller is that it is powered by 3.3V and such an output voltage is available from pin 40 of the mbed.! A link to the ADXL345 datasheet can be found in the Appendices.!

(iii)OPTICAL SENSORS
Another very important piece of equipment that is featured on the slot-car is a simple optical sensor. It is used to provide the microcontroller with information about the track. As agreed before, the track has been modied with pieces of white tape, which gives good contrast with the black plastic that it is fabricated from.

Fig. 8. The QTR-1A reectance sensor.2.8 Because of this a simple infra-red reectance sensor, the Polulu QTR-1A2.9 has been chosen. It is avery small DIP-package device that outputs analog voltage in the range of 0V to VIN, which is usually 5V and correspond to logic values 0 and 1, respectively. One of its main advantages is the fact that it is a closed-package device

HARDWARE SELECTION

PAGE "10 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

which does not require any external circuitry to operate correctly and can be connected directly to the microcontroller. The analog version of this device has been selected, rather than the digital one, because it allows for the manual calibration of ON-OFF levels in the program, and over ally greater maneuverability.! A link to the QTR-1A datasheet can be found in the Appendices.!

(iv)BLUETOOTH
The mbed is connected to an external PC via USB by default so it would seem that it is enough to provide means of communications for the microcontroller. However, with a project as dynamic as this one, maneuverability is indeed very precious so it has been decided that an additional, wireless interface must be tted onto the slotcar. Because of its popularity and relative simplicity in programming, Bluetooth has been chosen to do that task.! It has been quite difcult to decide on a particular chip, because there are many options available on the market and they are quite similar to the untrained observer. After lengthy research, the Microchip RN-422.10 Bluetooth module has been chosen for the project, as it is a low-power and fully certied device. It is incredibly easy to setup, as it features automatic discovery and pairing, which allows it to be setup straight after power-up and reduced the need for additional cables. This makes it perfect for use with small embedded systems, such as the Scalextric slot-car. It has an approximated range of 20m with 300kbps data rate, which is more than enough for the purpose of this project. It is compatible with regular UART interfaces, which are

HARDWARE SELECTION

PAGE "11 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

present in abundance on the mbed. Another feature which makes it perfect with use with the chosen microcontroller is the fact that it requires 3.3V power supply, much like the accelerometer; hence it can be powered directly from the mbed. Moreover, during research, it has been discovered that the RN-42 is quite popular with smallelectronic, academic projects that require some form of wireless communications, but in which Bluetooth is only an additional tool, not the main feature.!

Fig. 9. The RN-42 Bluetooth module.2.11 One disadvantage of the RN-42 is the fact that the DIP-package solution is more expensive than the surface mount component, so it was required to design a simple PCB for the module in order to make it compatible with breadboard development and testing. However, this has proven an interesting task and has only given additional academic value to the project.! A link to the RN-42 datasheet can be found in the Appendices.!

(v) MOTOR CONTROL


One of the most important questions that arise during the project is how to control the speed of the slot-car. The driving mechanism is a DC-motor so we need to control the amount of voltage that is applied to it. However, the only available
HARDWARE SELECTION PAGE "12 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

power source is the 15V rail supply and therefore it is not possible to have a varying DC power supply only for the purpose of motor control. One way to go around this problem would be to use Pulse Width Modulation (PWM), which is a technique that uses fast switching of a supply to give a required DC voltage level.2.12 This method is very common in electronic devices, in fact it is the dominant technique to generate varying DC voltages in small embedded system applications. The use of PWM in the project would solely require the use of a transistor, which would be enabled by one of the PWM-enabled pins on the mbed (see Fig. 6). However, such a solution does not provide any form of current protection and is very prone to faults. This is very unsafe and could result in the burn-out of the most expensive components - the Bluetooth module or even the microcontroller.! For those reasons, a dedicated motor control module, the Solutions Cubed Motor Mind B Enhanced2.13 has been selected. It is available in a SIP package, which makes

Fig. 10. Motor Mind B enhanced motor control module.2.14 it perfect for the early stages of development and testing. It is powered by 5V, so the same voltage that can be used for the mbed and optical sensors and is capable of operating DC motors with voltage supplies in the range 6V-24V. It serves as a slave

HARDWARE SELECTION

PAGE "13 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

device and communicates with the master microcontroller via an UART interface, so! it is perfect for use with the mbed in this project. Moreover, it has built-in undervoltage, over-temperature, over-current protection built and two LEDs that provide information about the communications interface and protection unit without the need to access the device via software.! A link to the Motor Mind B Enhanced datasheet can be found in the Appendices.!

(vi)VOLTAGE REGULATOR
We have seen that all of the modication require either a 3.3V supply, which is available directly from the mbed, or a 5.0V supply. Because the microcontroller can only run on voltages up to 14.5V, a simple voltage regulation circuit needed to be designed. It uses a ON Semiconductor LM317 adjustable output voltage regulator.2.15 !

Fig. 11. LM313 voltage regulator circuit. A link to the LM317 datasheet can be found in the Appendices."

HARDWARE SELECTION

PAGE "14 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

3. HARDWARE INTEGRATION
After the process of component selection, it is of utmost importance that those electronic devices be tested and analysed before they are combined into a fully operational embedded system. The testing was mostly done with standard laboratory equipment, i.e. a Digital MultiMeter and a breadboard (a part of the NI myDAQ system).! Some of the components, such as the bluetooth module or the accelerometer, required testing and measurement in combination with the mbed, because their serial interfaces needed to be examined. However, the optical sensors produce simple output voltages and hence they were tested as standalone products.! Note: All of the programs mentioned in this section of the report can be found in the Appendices.!

(i) THE MICROCONTROLLER


As the mbed is the brain of the embedded system to be, it must be examined as the rst element in order to ensure that it operates correctly. ! First of all, the mbed was connected to the Mac and the compiler was run in a webbrowser. The default program, called Hello World was compiled, downloaded onto the microcontroller and then run. This has proved that the ash memory and USB serial interface of the mbed was operating. The next step involved writing a program that would test the internal logic and outputs of the microcontroller. For

HARDWARE INTEGRATION

PAGE "15 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

that purpose a simple binary counter was created; it counted from 0 to 15 on the built in LEDs with a 0.2s delay between each increment. Moreover, a DMM was used to test the voltage levels of all 40 pins of the mbed to prove that they are compliant with the specication.!

(ii) ACCELEROMETER
The rst peripheral to be tested was the accelerometer, as it provides vital functionality to the project - the ability to measure centrifugal force acting on the

Fig. 12. Schematic diagram of accelerometer connections. slot-car. The ADXL345 can be connected via either I2C or SPI, and the latter was chosen as it does not require any additional circuitry, i.e. pull-up resistors. Moreover, the 4-Wire connection setup was used, as it reduces the amount of coding required for functional operation for in this way, separate pins of the mbed are used for transmitting commands and receiving data. The accelerometer is glued to the slotcars oor.!

HARDWARE INTEGRATION

PAGE "16 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

The accelerometer was testes with a sample program, which congures the device into full resolution (16g, 4mg/LSB), 3.2kHz mode. The output data is 13-bit, formatted as left justifed, signed 16-bit integers.!

Slot-car in default position


X Y Z

34 30 30 32 32 32

-18 -18 -20 -20 -16 -18

-264 -270 -260 -270 -266 -266

Slot-car in upside-down position


X Y Z

24 22 22 22 22 22

28 28 28 28 28 28

236 230 236 234 232 234

Slot-car on left side


X Y Z

-4 0 -6 -8 0 -4

260 262 262 258 258 260

-54 -50 -54 -54 -44 -51

HARDWARE INTEGRATION

PAGE "17 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

Slot-car on right side


X Y Z

0 0 0 0 0 0

-262 -260 -258 -256 -256 -258

24 22 18 22 22 22

Slot-car on rear-bumper
X Y Z

272 270 272 272 268 271

0 6 0 0 0 1

-34 -38 -32 -44 -38 -37

Slot-car on front-bumper
X Y Z

-246 -240 -246 -244 -246 -244

-18 -20 -20 -20 -20 -20

-40 -44 -40 -44 -48 -43

Tables 1-6. Integer values of g-force acting on the slot-car in various positions.

Note: The orange colour ll denotes the working axis in question, whereas the green ll shows the average from ve measurements. !
HARDWARE INTEGRATION PAGE "18 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

From the result tables it is clear that the accelerometer is functioning correctly. It can distinguish between directions on one axis (positive and negative values are shown), is very sensitive and produces correct output values, as magnitudes of the order 234 - 278 correspond to 0.900g - 1.100g, which is a good approximation of the gravitational pull. Magnitudes 0 - 50 correspond to negligible force values up to 200mg. !

(iii)OPTICAL SENSORS
Due to the introduced track modications, two reectance sensors are tted onto the slot-car, one on each side. Because they produce analog values in the range 0V - 5V, their outputs had to be tested in relation to the black track and white tape surfaces.

Fig. 13. Schematic diagram of sensors connections. The sensors are placed 40mm from the surface of the track, so that is the distance at which we concern ourselves with the output measurements. The testing was done in normal, ambient conditions - that is a room well-lled with sunlight, the same conditions that will apply during the race and demonstrations.!

HARDWARE INTEGRATION

PAGE "19 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

Multiple measurements were taken, both on the black surface of the track and the white tape.!
3000 Black track White line

2500

LOGIC 1
2000 Output voltage [mV]

1500

1000

500

LOGIC 0
0 1 2 3 Measurement 4 5

Graph 1. Optical sensors measurement results. From the NXP LPC1768 datasheet, the logic voltage levels are 0.0 - 0.8V and 2.0V 5.0V for logic 0 and 1, respectively. Thus, even though the sensors are analogue devices, they can be connected to strictly digital pins on the mbed. This fact has quite huge consequences, which will be explained in the Software section of this report. For now, sufce it to say that digital pins can be congured with the use of interrupts.!

!
HARDWARE INTEGRATION PAGE "20 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(iv)BLUETOOTH
One of the most demanding modules, as far as implementation is concerned, is Bluetooth. It was the only peripheral which was ordered as a surface-mount component rather than a DIP package and therefore a PCB needed to be designed. The layout and connection diagram can be found in the Appendices.!

Fig. 14. Schematic diagram of Bluetooth connections. The Bluetooth is connected to the mbed via a UART interface. After power-up, the module was readily discoverable by external computers. The pairing was done automatically and then a terminal application was used to access the settings of RN-42. Basic commands (see RN-42 datasheet - link in the Appendices) were tested and the name of the module was changed to Racecar, in order to better reect the nature of the project. A sample program that sends user-entered characters to a wirelessly paired computer was applied to check whether the Bluetooth is fully functional.!

HARDWARE INTEGRATION

PAGE "21 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(v) MOTOR CONTROL


In order to control the motor voltage and thus the speed of the slot-car, Motor Mind was implemented. It is connected to the microcontroller via a a serial TTL interface and is powered by 5V, same as the mbed. Its core functionality was tested with a simple program that gradually increased the motor voltage, from 0V to 15V. The output was a PWM waveform with a frequency of 15.5kHz and a varying dutycycle. This frequency was chosen, because it makes for a more efcient PWM technique and is less audible by the human ear than lower frequencies. !

Fig. 15. Schematic diagram of Motor Mind B connections. The module proved capable of producing the necessary output and driving the motor. Furthermore, the brake feature was tested, with positive outcome. It may prove useful when the motor needs to be abruptly halted, e.g. when the slot-car is on the verge of derailing and simply reducing the speed would not remedy the situation.!

HARDWARE INTEGRATION

PAGE "22 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(vi)VOLTAGE REGULATOR
The regulator circuit is designed so that it provides all of the necessary voltage levels for the project; that is 15V, 5V, 3.3V and GND.!

no connection

Fig. 16. Veroboard layout of the voltage regulator circuit. The +15V and GND levels are taken from the rail supply, the 3.3V from the mbeds pin 40. The blue potentiometer is set so that the output voltage (rail 2) is 5.0V. There is one +15V output pin to be used with the Motor Mind B, to provide power for the DC motor. The voltage regulator circuit was tested with a regular power supply rst. All of the voltage levels were correct, there was no over-current alarm and there was no short on the 3rd rail, between the 15V pin and 3.3V pins. Because of that, the circuit was tested using voltage from the Scalextric track and it has, once again, proven to be operating correctly.! Each of the described components was initially tested as a standalone product and they have only been brought together into a full system when all of them were proven to be working properly.!

HARDWARE INTEGRATION

PAGE "23 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

4. SOFTWARE
After the successful completion of all the hardware components, the focus of the project shifted onto the software side. As in any embedded system, those two sides are required to integrate seamlessly with each other in order to provide full and expected functionality. It is very difcult to give a succinct, written explanation of software operation, therefore sample pieces of code will be included and analysed in this part of the report.!

!
The mbeds online compiler is compatible with both C and C++ programming, however, for the purpose of this project it is not necessary to distinguish between the two, as no advanced structures are needed. The nal program, used during the demonstration and viva voce, can be found in the Appendices.! Nonetheless, before the nal code was developed, it was vital to create a learning algorithm for the slot-car. The most crucial part was to create a method for the microcontroller to gather and govern accelerometer readings; then use them to control the speed of the vehicle. Rather than begin with that, however, the optical sensors were implemented in software. The ability to distinguish between separate portions of the track and recognise the end of the lap is vital with the way the algorithm is structured. Other functionality (i.e. Bluetooth) is desired, but not strictly essential for the correct operation of the system.!

SOFTWARE

PAGE "24 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(i) ALGORITHM OUTLINE


The desired algorithm uses all of the peripherals in tandem to give a fully functional embedded system. A picture speaks a thousand words and therefore rather than provide just a lengthy explanations of the program structure, its simplied owchart can be found in Fig. 17. !

Fig. 17. Flow-chart of the program. Two main parts of the program are clearly visible. The rst one, featured on the lefthand side represents the test-lap, during which the car is travelling at a constant speed and gathers data about the track. This is done by the two reectance sensors and the accelerometer. !

SOFTWARE

PAGE "25 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

As previously agreed, pieces of white tape will be featured on the start of each track segment. Those pieces will drive a change of output at the sensors, S1 and S2, and therefore trigger interrupts at the microcontroller and enable it to recognise particular elements of the track and the end of the lap, respectively. We can see that the accelerometer is constantly gathering measurements of the G-force acting on the slot-car until a S1 interrupt occurs. Those measurements are stored in the microcontroller and then used to determine the curvature of the particular track segment. Because there are only so many track pieces, the curvature information can be used to deduce exactly which segment that is. As a result of testing that will be done before creating the nal program, the microcontroller will be populated with a table of maximum allowable speed per each particular piece of the track. Those two facts will allow the mbed not only to determine the exact layout of the track, but also create the algorithm to increase and reduce speed, accordingly to the slot-cars position on the track. That information will be fed out through the Bluetooth interface to allow the user to easily check whether the track layout was correctly calculated.! Once the S2 interrupt occurs, i.e. when the test lap is completed, the program will automatically switch into the so-called race-mode. In this mode, the microcontroller will apply a particular speed, calculated before, until a new track segment is detected. Then the car will accelerate or decelerate to achieve the best possible lap time. Of course, rather than a simple proportional algorithm, some form of PID control will be implemented to provide better results and a more seamless operation.!

SOFTWARE

PAGE "26 OF "27

PAWEL KECERSKI

AUTONOMOUS SLOT CAR RACING

(ii) VELOCITY LIMITS


Due to the fact that the Motor Mind B is connected through an 8-bit serial interface, it accepts integer values in the range 0 - 255. Those values are used as a scale for the PWM output, in our case 0V and 15V, respectively. It has been found experimentally that a supply voltage of 10V is low enough to allow a standard Scalextric car to navigate round any lap at top speed, without the need to change it in any way. 10V corresponds to a motor control value of ~170, and that has been set as the absolute lowest speed. To nd the upper velocity limits a more cunning technique was used. A program which incrementally increases the speed after each lap was created and then run. It allowed us to nd which track segment is the most prone to cause derailment, and the speed at which such a situation occurs.!

SOFTWARE

PAGE "27 OF "27

S-ar putea să vă placă și