49
IN DEGREE PROJECT TECHNOLOGY, FIRST CYCLE, 15 CREDITS , STOCKHOLM SWEDEN 2017 Self Parking Robot Automated Parallel Parking LOVISA HENRIKSSON VICTOR LUNDELL KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT

Self Parking Robot - DiVA portalkth.diva-portal.org/smash/get/diva2:1200483/FULLTEXT01.pdf · 2018. 4. 24. · Parallel parking is a task that requires relatively precise movements

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • IN DEGREE PROJECT TECHNOLOGY,FIRST CYCLE, 15 CREDITS

    , STOCKHOLM SWEDEN 2017

    Self Parking RobotAutomated Parallel Parking

    LOVISA HENRIKSSON

    VICTOR LUNDELL

    KTH ROYAL INSTITUTE OF TECHNOLOGYSCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT

  • Self Parking Robot

    Automated Parallel Parking

    LOVISA HENRIKSSON, VICTOR LUNDELL

    Bachelor’s Thesis at ITMSupervisors: Joakim Gustavsson, Naveen Mohan

    Examiner: Nihad Subasic

    TRITA MMK 2017:20 MDAB 638

  • AbstractThe purpose of this report is to examine how a self par-allel parking robot performs using a pre defined parkingpath, compared to recommendations manual parking. Toexamine this a robot capable of parallel parking have beenconstructed.

    The project is divided into two parts; construction ofthe vehicle and the software which controls it. The design ofthe vehicle is based on a rear wheel driven car with Acker-mann steering. Localisation of a parking spot, parking andautomatic stopping at an unexpected obstacle is handledwith the help of three distance sensors.

    The robot was successful in 85% of the test conducted.

  • ReferatSjälvparkerande Robot

    Syftet med denna rapport är att undersöka hur bra en själv-parkerande robot presterar när den fickparkerar med en för-programmerad väg, jämfört med rekommedationer manuellparkering. För att undersöka detta har en robot kapabeltill att fickparkera konstruerats.

    Projektet består av två delar; konstruktion av robo-ten, samt mjukvaran som kontrollerar den. Konstruktionenär baserad på en bakhjulsdriven bil med Ackermannstyr-ning. Lokalisering av parkeringsplats, parkering samt auto-matiskt stopp vid oväntat hinder hanteras med hjälp av trestycken avståndssensorer.

    Roboten var framgångsrik i 85% av testerna som utför-des.

  • Acknowledgements

    We would like to thanks Nihad Subasic, Naveen Mohan and Joakim Gustavsson forguiding us through this project. We would also like to extend out thanks to the fan-tastic lab assistants who have helped us during the construction and programmingof our demonstrator.

    Lovisa HenrikssonVictor Lundell

  • Contents

    List of Figures

    List of Tables

    Abbreviations

    1 Introduction 11.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    2 Theory 32.1 Ackermann Steering . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Parking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3 Pulse-width Modulation . . . . . . . . . . . . . . . . . . . . . . . . . 62.4 Inter-Integrated Circuit . . . . . . . . . . . . . . . . . . . . . . . . . 6

    3 Demonstrator 93.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    3.1.1 Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.1.2 Distance Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . 103.1.3 Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.1.4 DC motor and encoder . . . . . . . . . . . . . . . . . . . . . . 103.1.5 Motor Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.1.6 Servomotor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    3.2 Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    3.3.1 Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.3.2 Distance Sensors and Multiplexer . . . . . . . . . . . . . . . . 14

    4 Testing and Results 154.1 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.2 Parking Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

  • 5 Discussion and Conclusions 195.1 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    5.1.1 Parking Path . . . . . . . . . . . . . . . . . . . . . . . . . . . 195.1.2 Arduino UNO . . . . . . . . . . . . . . . . . . . . . . . . . . . 195.1.3 Error Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    5.2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    Bibliography 23

    A Datasheet for DC motor 25

    B Datasheet for Gearhead 27

    C Wiring Diagram 29

    D Code 31

  • List of Figures

    2.2 Angled steering arms results in different wheel angles when steering (seenfrom above) [1]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2.1 Radiuses of the front wheels [1]. . . . . . . . . . . . . . . . . . . . . . . . 32.3 The steering arms’ symmetry lines’ intersection of the rear axle is a

    requirement for true Ackermann steering [1]. . . . . . . . . . . . . . . . 42.4 The parking path (created in Microsoft PowerPoint). . . . . . . . . . . . 52.5 PWM signals with different duty cycles [2]. . . . . . . . . . . . . . . . . 62.6 Each command starts with a start condition and ends with a stop con-

    dition [3]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.7 A complete I2C communication sequence. R/W̄ indicates the direction

    bit [3]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    3.1 VL6180 sensor mounted on the SparkFun breakout board [4]. . . . . . . 103.2 TCA9548 1-to-8 I2C multiplexer used for I2C communication [5]. . . . . 113.3 The DC motor and its attacked gearbox. . . . . . . . . . . . . . . . . . . 113.4 TB6612FNG Dual Motor Driver Carrier used to control the motor. [6] . 123.5 Parallax Standard Servo used in the steering mechanism [7]. . . . . . . . 123.6 Flowchart describing the algorithm from start until it finds a suitable

    parking spot (created on www.draw.io). . . . . . . . . . . . . . . . . . . 13

    4.1 Dimensions of the first course (created in Microsoft PowerPoint). . . . . 154.2 Dimensions of the second course (created in Microsoft PowerPoint). . . 154.3 Distance traveled by the robot when programmed to travel 380 mm,

    represented by the horizontal line (created in MATLAB R2016b). . . . . 16

    A.1 Datasheet of DC motor from Maxon. . . . . . . . . . . . . . . . . . . . . 26

    B.1 Datasheet of gearhead from Maxon. . . . . . . . . . . . . . . . . . . . . 28

    C.1 Wiring diagram of all components used (created in EAGLE). . . . . . . 29

  • List of Tables

    3.1 Dimensions of the demonstrator. . . . . . . . . . . . . . . . . . . . . . . 93.2 Relevant Arduino UNO specifications. . . . . . . . . . . . . . . . . . . . 9

    4.1 Results of parking tests. . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

  • Abbreviations

    I2C Inter-Intergrated Circuit

    IR Infrared

    PWM Pulse-Width Modulation

    SCL Serial Clock

    SDA Serial Data

    1

  • Chapter 1

    Introduction

    1.1 BackgroundParallel parking is a task that can be considered a relatively hard even by experi-enced drivers. A potential future with self driving cars could be right around thecorner, and parallel parking would no longer be an issue. Companies such as Tesla,Audi and Google are working hard to deliver a safe and reliable autonomous drivingsystem to the market [8][9].

    Parallel parking is a task that requires relatively precise movements and goodobservations of the car’s surroundings, two things which a well optimized robot intheory is better at than humans. Due to this, parking is clearly an area that couldbe automated with great benefits.

    1.2 PurposeThe purpose of this report is to answer the following question:

    How well does a self parallel parking robot perform using a pre definedparking path, compared to recommendations for manual parallel

    parking?

    In this case, well is defined as

    • as small parking space as possible,

    • reliable.

    The recommended size of a parking spot is about 1.5 times the length of thevehicle for parallel parking [10].

    To examine this a robot capable of parallel parking will be constructed. Therobot should be able to locate a parking spot on its right side while driving along astraight line of car like objects, determine the size of the spot and then parallel parkif the spot is large enough. This should be done as safe and reliable as possible.

    1

  • CHAPTER 1. INTRODUCTION

    1.3 MethodA small self driving car-like robot is constructed to resemble a car with four wheels,rear drive and Ackermann steering. An Arduino UNO microcontroller is used toprocess inputs from the robot’s surroundings, and control the motors that handlesmovement and steering.

    Three infrared (IR) distance sensors are used to measure the distance to objectsnear the robot. Two of them detect unexpected objects behind and in front of therobot, and one is used to measure the size of the parking spot. A rotary encoder isused to measure distance travelled.

    To test the robot’s performance a course is constructed from objects meant tosimulate parked cars. The robot will then travel along this line of ”cars” until it findsa suitable spot, in which it will then park. For a trial to be seen as successful therobot should have aligned itself with the other cars without colliding with anything.

    1.4 ScopeDue to budget limitations, the project is limited to three distance sensors. As aresult of this the robot can only sense certain areas around it. Obstacles in frontof it have to be directly in line with the sensor or they will remain undetected, andobstacles on its side that are below or above the sensor’s level will not be recognized.

    The robot can not be controlled by its user after it has been started, and isnot able to perform any other kind of action than parallel parking. The robot isassumed to be driven along a straight line of cars on a flat surface.

    2

  • Chapter 2

    Theory

    2.1 Ackermann Steering

    The Ackermann steering principle defines the geometry that is applied to manyvehicles to enable the correct turning angle of the steering wheels to be generatedwhen negotiating a curve [1]. What this means is that when a vehicle is travellingin a curve, its two front wheels will travel through the curve at different radii, asshown in Figure 2.1. This will lead to one or both wheels slipping which results inunpredictable steering.

    To compensate for this, and therefore improve the steering, the steering armsare angled inward to allow the wheels’ angles to change at different rates. This isillustrated in Figure 2.2.

    (a) Angled steering arms. (b) Different wheel angles.

    Figure 2.2: Angled steering arms results in different wheel angles when steering(seen from above) [1].

    h

    Figure 2.1: Radiuses of the front wheels [1].

    3

  • CHAPTER 2. THEORY

    True Ackermann angle is defined by angling the steering arms so that the sym-metry lines drawn through the steering arms intersects with the rear axle’s centreline, as shown in Figure 2.3. With this geometry the vehicle’s optimal curve radiuscan be measured as the distance between the intersection of the front wheel axes’symmetry lines and the centre of rear axle.

    Figure 2.3: The steering arms’ symmetry lines’ intersection of the rear axle is arequirement for true Ackermann steering [1].

    2.2 Parking

    The parking path used in this project is designed to mimic the path a real driverwould choose, while maintaining simplicity. It is not the optimal path for parkingin small spaces, but is considered as sufficient for this project.

    When the robot turns its wheels to its optimal angle as described in 2.1, theresulting path will be a circle with a curve radius Rc. The path that the robotfollows, C, consists of two circle sectors of two tangent circles with radii Rc.

    The robots begins by turning its wheels to its optimal angle and then reversersalong the first circle sector until it reaches the tangent point. It then turns itswheels to the opposite angle and keeps reversing until its parallel to the line of cars.The path and the variables used for calculations are shown in figure 2.4.

    4

  • 2.2. PARKING

    Rc

    Rc β

    y

    Lmin

    b

    lR2

    R1

    p

    YC

    Figure 2.4: The parking path (created in Microsoft PowerPoint).

    Depending on the dimensions of the robot and its steering capabilities, theresulting spot size is determined by a critical point at which the robot would collidewith the car in front on it when reversing into place. In figure 2.4 this point is inthe rear left corner and is shown with a dot.

    Assuming that the robot is a rectangle with length l and width b, the minimalparking spot size for the robot can be calculated as

    Lmin = p+√R22 −R21, (2.1)

    where R1 and R2 is calculated as

    R1 = Rc −b

    2 (2.2)

    and

    R2 =√

    (Rc +b

    2)2 + (l − p)2. (2.3)

    This results in a minimal spot size of approximately 386 mm, or 1.54 times thelength of the robot.

    The distance C which the robot travels when reversing along the circle sectorsi calculated as

    C = 2βRc (2.4)where β is calculated from

    β = arccos( Y2Rc), (2.5)

    and Y depends on the distance from the robot’s side to the line of ”cars”.

    5

  • CHAPTER 2. THEORY

    2.3 Pulse-width Modulation

    Pulse-width modulation (PWM) is a technique for controlling analog circuits witha processor’s digital outputs [11]. An analog signal changes continuously over itsspectrum, whereas a digital signal only outputs discrete values of either 1 or 0 (highor low). The high and low signals are usually 5 V and GND.

    The PWM signal sends out a pulse of ones and zeros. The proportion of timethe signal is high compared to when it is low is known as duty cycle and can beused to interpret the pulse of digital signals as a continuous analog signal. Theanalog interpretation changes linearly with the duty cycle as shown in Figure 2.5.For example, in the case of the high and low digital signals being 5 V and 0 V, aduty cycle of 50% would be interpreted as a 2.5 V analog signal.

    Figure 2.5: PWM signals with different duty cycles [2].

    2.4 Inter-Integrated Circuit

    Inter-Intergrated Circuit (I2C) is a serial protocol for two-wire interface to connectlow speed devices such as microcontrollers with other similar components in embed-ded systems [12]. The two wires used are one serial clock (SCL) and one serial data(SDA), both of which need to be pulled up using a pull up resistor. It is an effectiveway of allowing one or more ”master” devices to communicate with multiple ”slave”devices. The master is the device that generates clock, starts communication, sendscommands and stops communication and the slave is the device that listens to com-mands from the master. Each slave requires a unique address for the master todetermine which slave it is communicating with.

    Every I2C command is initiated by a start condition and ended with a stopcondition, as shown in Figure 2.6. Basic I2C communication works by transferring8 bits of data at a time. The first 7 bits of data is the slave’s unique address and the8th is used to signal whether the master is reading or writing to the slave; 1 indicatesreading and 0 indicates writing. After the first 8 bits are sent, the master will start

    6

  • 2.4. INTER-INTEGRATED CIRCUIT

    reading or writing to the slave. 8 more bits containing data (sensor readings forexample) are then sent through the bus followed by an acknowledge bit.

    Figure 2.6: Each command starts with a start condition and ends with a stopcondition [3].

    The acknowledge bit indicates whether the slave is ready to send more data ornot. Depending on the state if the acknowledge bit, the master can either generatea repeated start condition or a stop condition. A stop condition indicates that thebus is now free, whereas a repeated start condition can be used to change whichslave the master communicates with, without having to generate a stop condition.A full communication sequence is shown in Figure 2.7.

    Figure 2.7: A complete I2C communication sequence. R/W̄ indicates the directionbit [3].

    7

  • Chapter 3

    Demonstrator

    3.1 Hardware

    The following sections describe the individual components used to construct therobot. Some of the demonstrator’s dimensions are presented in table 3.1 below.

    Description ValueLength, l 250 mmWidth, b 180 mm

    Distance from rear end to rear axle, p 40 mmCurve radius, Rc 210 mm

    Table 3.1: Dimensions of the demonstrator.

    3.1.1 Arduino

    The Arduino board is an open-source electronics platform able to read an input andturn them into an output. Instructions are sent to the Arduino’s microcontrollerusing the Arduino programming language. In this project an Arduino Uno is usedto control the robot. Relevant specifications are presented in table 3.2.

    Description ValueOperating Voltage 5 V

    Input Voltage 7 V - 12 VNumber of Digital I/O Pins 14

    Number of PWM Digital I/O Pins 6Number of Analog Input Pins 6

    Clock Speed 16 Mhz

    Table 3.2: Relevant Arduino UNO specifications.

    9

  • CHAPTER 3. DEMONSTRATOR

    3.1.2 Distance SensorThe sensors used to measure the size of the parking spot are three VL6180 Time-of-Flight sensors from STmicroelectronics [13] mounted on a breakout board fromSparkFun [4] for easy access to the sensor’s pins. The sensor works by preciselymeasuring the time it takes for light to travel to the nearest object and reflect backto the sensor. The measured time is then used to calculate the distance to theobject.

    Figure 3.1: VL6180 sensor mounted on the SparkFun breakout board [4].

    The sensor uses the I2C protocol described in section 2.4 to communicate withthe Arduino, has an operating voltage of 2.8 V and measures distances up to 10 cmwith an accuracy of ±1 mm.

    3.1.3 MultiplexerSince the distance sensors have a fixed I2C adress a TCA9548 1-to-8 I2C multiplexerbreakout from Adafruit [14] is used to control which sensor the Arduino is commu-nicating with. A multiplexer is a circuit designed to select one of several differentinput signals and forward it to a single output.

    This multiplexer uses I2C to allow the Arduino to communicate with a singleI2C component by directing the SDA/SCL signal through a specific output pin.This way components with the same adress can be used together on the same I2Cline.

    3.1.4 DC motor and encoderA DC motor and its attached gearbox are used to drive the robot while a rotaryencoder is used to measure the distance traveled. The motor operates on a nominalvoltage of 12 V and has a nominal speed of 7060 rpm. The gearbox has a reductionof 14 : 1.

    The rotary encoder has 512 counts per turn. It communicates with the Arduinowith alternating outputs of either 1 or 0 depending of its position. It outputs from4 pins at once: A, Ā,B and B̄. B is phase shifted 90° from A and is used todetermine the direction of the rotation. Ā and B̄ are the inverse signals of A and

    10

  • 3.1. HARDWARE

    Figure 3.2: TCA9548 1-to-8 I2C multiplexer used for I2C communication [5].

    (a) DC motor. [15] (b) Gearbox. [16]

    Figure 3.3: The DC motor and its attacked gearbox.

    B. By comparing A and B with their inverses one can ensure that there is no errorin the transmission [17].

    Full specifications of the motor, gearbox and rotary encoder can be found inappendices A and B.

    3.1.5 Motor DriverTo control the direction and speed of the motor using a PWM signal a TB6612FNGDual Motor Driver Carrier from Toshiba [18] mounted on a breakout board fromPololu [6] is used. It has a recommended motor voltage between 4.5 V and 13.5 V,and a logic voltage between 2.7 V and 5.5 V.

    3.1.6 ServomotorThe servomotor used in the steering mechanism is a Parallax Standard Servo [19].It operates on 4 to 6V and is able to hold any position between 0 and 180 degrees.The servo is controlled through PWM, where the position of the servo is dependenton the duration of the pulse. In order to hold a specific position the servo needs toreceive a pulse every 20 ms.

    11

  • CHAPTER 3. DEMONSTRATOR

    Figure 3.4: TB6612FNG Dual Motor Driver Carrier used to control the motor. [6]

    Figure 3.5: Parallax Standard Servo used in the steering mechanism [7].

    3.2 ElectronicsThe entire robot is powered by a 12 V battery which connects directly into theArduino UNO, the motor driver and a 5 V regulator.

    The 5 V output from the regulator powers the servo, the logic of the motordriver and the rotary encoder. The 5 V is also applied over a 5 V to 2.8 V voltagedivider used to power the distance sensors.

    A complete wiring diagram can be found in appendix C.

    3.3 SoftwareThe robot moves along a straight line of objects while measuring the distance toits right side. If the distance is over a certain threshold value, the starting pointof a potential parking spot is assumed to have been found, and the robot beginsto measure the distance it travels until the the distance on its side is below thethreshold value or a large enough spot have been identified.

    If the spot is large enough the parking sequence is initiated, and the robot beginsto move along the pre programmed path described in section 2.2. At all times therobot is programmed to stop and wait if the distance in front or behind it, dependingon which way it’s moving, is less than a certain value.

    12

  • 3.3. SOFTWARE

    A complete flow chart of the algoritm is described in 3.6 below.

    Figure 3.6: Flowchart describing the algorithm from start until it finds a suitableparking spot (created on www.draw.io).

    3.3.1 Movement

    The servo is controlled using Arduino’s servo library, which allows for direct inputof angles between 0° and 180°, and therefor it is not required to manually controlthe PWM signal to control the servo.

    The DC motor is controlled through the H-bridge. Two functions are used tocontrol the H-bridge; move() and stop(). The stop() function simply enables thestandby pin on the H-bridge, resulting in a complete stop of the motor.

    The move() function takes two inputs; speed and direction. The speed input isthe value of a PWM signal between 0 and 255, and the direction decides which waythe motor rotates.

    13

  • CHAPTER 3. DEMONSTRATOR

    To measure the rotation of the encoder, the amount of changes from HIGH toLOW of the A pin, or vice versa, are summed up. To determine the direction ofthe rotation the value from the B pin is examined after a change in A has occured,if it is HIGH the robot is moving forwards, and if it is LOW the robot is movingbackwards.

    3.3.2 Distance Sensors and MultiplexerThe VL6180 distance sensor comes with an Arduino library from SparkFun whichallows for easy use of the components. After the initial setup of the sensors the.getDistance() command is all that is required to measure the distance.

    The multiplexer communicates over I2C and is easily programmed to selectwhich sensor to communicate with by using code provided by Adafruit [14].

    A result of the fact that the Arduino is a single core microprocessor is that itcan only perform a single command at a time. This means that it is not possibleto measure distances while performing other actions. This becomes most apparentwhile measuring distance traveled with the rotory encoder.

    For the encoder to accurately measure the distance traveled by the robot, themotor has to briefly stop to allow for the distance sensors to collect their data beforeturning back on, otherwise the data collected from the encoder could falsely implythat the robot is moving backwards. This leads to a jagged movement of the robot.

    14

  • Chapter 4

    Testing and Results

    4.1 TestingThe test described in section 1.3, where the robot tries to find a suitable parkingspot while driving along a course constructed from a line of car like objects, wereperformed with two different courses. The two courses are shown in figures 4.1 and4.2.

    Start

    280 mm 200 mm 400 mm320 mm

    60 mm

    Figure 4.1: Dimensions of the first course (created in Microsoft PowerPoint).

    Start

    180 mm 110 mm 400 mm320 mm

    60 mm

    145 mm

    Figure 4.2: Dimensions of the second course (created in Microsoft PowerPoint).

    The difference between the courses is whether the robot starts next to an objector next to an empty space, and that the distance between the objects are different in

    15

  • CHAPTER 4. TESTING AND RESULTS

    the two courses. The reason for these arrangements is to determine how the robotis affected by spaces and objects which appears before a suitable parking spot isfound.

    The purpose of these tests is mainly to investigate the reliability of the parkingalgorithm and gather data to draw conclusions regarding this method of parking,but also to examine the construction of the demonstrator.

    To perform the test the robot was placed at the start of the course and manuallyaligned with the line objects at a distance of 60 mm from its right side before beingactivated. For a test to be seen as successful the robot have to enter the parkingspot and align itself with the line of objects, without colliding with anything. Dueto the robot following a pre programmed path, other aspects such as the time ittakes for the robot to park are not considered.

    4.2 Parking ResultsWhile testing how far the robot moved while measuring a parking spot, it wasdiscovered that it constantly traveled farther than it had been programmed to. Thisis most likely due to the fact that the robot moves in small intervals, as mentionedin section 3.3.2, and measures the distance to its side between each. This in turnleads to a possible accumulation of errors from each interval. A graph showing thesetest is shown in figure 4.3.

    Figure 4.3: Distance traveled by the robot when programmed to travel 380 mm,represented by the horizontal line (created in MATLAB R2016b).

    As seen in figure 4.3, the errors are almost constant throughout the tests. Tocompensate for these errors the target distance for the robot to measure is manuallyaltered in the code to achieve desired results. This method of correcting the robotworked well, and the errors was practically eliminated. The distance traveled bythe robot when reversing into the spot had to be modified in the same way.

    With the parking path designed for this project the minimum parking spot sizewas calculated as approximately 1.54 times the length of the robot, which equals aspot size of 386 mm. Testing at this spot size returned unacceptable results, andthus the spot size was increased to 400 mm. The results of testing at 400 mm is

    16

  • 4.2. PARKING RESULTS

    presented in table 4.1. In total fourteen test were conducted across two differentcourses.

    Test Result1 Success2 Success3 Success4 Success5 Failure6 Success7 Success8 Success9 Success10 Success11 Success12 Success13 Success14 Failure

    Table 4.1: Results of parking tests.

    Twelve of these were completely successful. In test number five the robot suc-cessfully entered the parking spot but ended up misaligned with the rest of theobjects, and in test number fourteen the robot failed to detect the parking spot andkept moving past it.

    17

  • Chapter 5

    Discussion and Conclusions

    5.1 Discussion

    With a success rate of approximately 85% the results are highly positive. In thefollowing sections certain elements of the projects will be discussed.

    5.1.1 Parking Path

    As stated in section 2.2, the path which the robots follows into the parking spot isnot a path optimized to enter a minimal parking spot, but rather designed to mimicthe behaviour of a real driver while maintaining simplicity for the sake avoidingunnecessary complications throughout the project.

    A better optimized path would certainly reduce the size of the parking spot,but increase the complexity of the robot’s movements, which could lead to worseresults. Overall, the simple path could prove to be preferable due to its reliability,but further research would be required to make that statement.

    The minimal spot size depends on the dimensions of the robot. The robot iswider than a real car, which worsens the minimal parking spot size calculated insection 2.2. Had the robot been designed with the proportions of a real car [20], thecalculated spot size would be reduced to 1.34 times the length of the robot, whichis well under the recommendation of 1.5 times the length of the robot.

    5.1.2 Arduino UNO

    The Arduino UNO, as mentioned in section 3.3.2, can only perform a single in-struction at a time. This proved to be an issue throughout the project since therobot have to read the encoder while measuring distances. The .getDistance func-tion used in the code to get distance readings from the sensor proved to take toolong to execute to use it while reading the encoder without getting incorrect data.

    Although the Arduino UNO was tolerable for this project, to improve the parkingsoftware a different microcontroller or microcomputer, capable of multiple calcula-

    19

  • CHAPTER 5. DISCUSSION AND CONCLUSIONS

    tions at once, should be used. The main advantages of using an Arduino is that it iseasy to implement in a small scale project like this, and that it is well documented.

    5.1.3 Error SourcesThe major error source in this project lies in the way that the distance traveled bythe robot is measured while driving past a potential parking spot.

    As previously mentioned in section 3.3.2, the robot has to stop the motor atsmall, regular, intervals to be able to measure distances without affecting the en-coder readings. This results in two different error sources.

    The first source of error is that the resolution of the distance measurements willbe relatively low compared to the precision required for accurate parking. Assumea distance measurement is done right before the spot appears, this would result inthe robot traveling farther than it is supposed to, which leads to a larger margin oferror.

    The other error source derived from moving in small intervals is the momentumof the robot, which may cause the robot to keep moving a small distance after themotor has stopped. This error may be insignificant at first, but accumulates overtime.

    Another source of errors is the steering mechanism. Due to inaccuracies inmanufacturing, the steering mechanism have demonstrated some inconsistenciesthroughout testing. The front wheels have also shown some slipping due to poorfriction against the surface on which it travels. This leads to unpredictable steeringwhich affects the parking sequence.

    20

  • 5.2. CONCLUSION

    5.2 ConclusionThe purpose of the report was to answer the question

    How well does a self parallel parking robot perform using a pre definedparking path, compared to recommendations for manual parallel

    parking?

    Based on the gathered results the conclusion is that it performs well, at leastunder the conditions examined in this project.

    The final spot size ended up being 1.6 times the length of the robot. Comparedto the recommendation of 1.5 times the vehicle length and the calculated spotsize of 1.54 times the vehicle length, this result is regarded as a moderate successconsidering the robot’s dimensions and the parking path.

    We believe that this method of parallel parking shows great promise, but sincethe unpredictability of real traffic is completely disregarded in this project, moreresearch have to be conducted before any conclusions regarding real traffic andparking implementations can be drawn.

    21

  • Bibliography

    [1] RcTek, “RcTek - Radio Controlled Model Car Handling - The AckermanSteering Principle,” date accessed: 2017-03-23. [Online]. Available: http://www.rctek.com/technical/handling/ackerman steering principle.html

    [2] Sparkfun, “Pulse-width Modulation - learn.sparkfun.com,” date ac-cessed: 2017-03-24. [Online]. Available: https://learn.sparkfun.com/tutorials/pulse-width-modulation

    [3] I2C Info, “I2C Bus Specification,” date accessed: 2017-03-24. [Online].Available: http://i2c.info/i2c-bus-specification

    [4] Sparkfun, “SparkFun ToF Range Finder Breakout - VL6180 - SEN-12784- SparkFun Electronics,” date accessed: 2017-03-18. [Online]. Available:https://www.sparkfun.com/products/12784

    [5] Adafruit, “Adafruit Learning System,” date accessed: 2017-05-16. [Online].Available: https://learn.adafruit.com/assets/27695

    [6] Pololu, “Pololu - TB6612FNG Dual Motor Driver Carrier,” date accessed:2017-05-10. [Online]. Available: https://www.pololu.com/product/713

    [7] Parallax, “Parallax Standard Servo — 900-00005 — Parallax Inc,” dateaccessed: 2017-05-16. [Online]. Available: https://www.parallax.com/product/900-00005

    [8] A. Shontell, “A top Silicon Valley investor predicts that 2 yearsfrom now everyone will be chauffeured around in driverless cars onhighways,” 2016. [Online]. Available: http://www.businessinsider.com/chris-dixon-future-of-self-driving-cars-interview-2016-6?r=US&IR=T&IR=T

    [9] Audi of America Communications, “Audi - CES and NAIAS 2017- Press Site,” 2017, date accessed: 2017-03-23. [Online]. Available:http://autoshowsaudiusa.com/en-us/releases/11

    [10] Korkort.se, “Fickparkering,” date accessed: 2017-04-05. [Online]. Available:https://korkort.se/fickparkering/

    23

    http://www.rctek.com/technical/handling/ackerman_steering_principle.htmlhttp://www.rctek.com/technical/handling/ackerman_steering_principle.htmlhttps://learn.sparkfun.com/tutorials/pulse-width-modulationhttps://learn.sparkfun.com/tutorials/pulse-width-modulationhttp://i2c.info/i2c-bus-specificationhttps://www.sparkfun.com/products/12784https://learn.adafruit.com/assets/27695https://www.pololu.com/product/713https://www.parallax.com/product/900-00005https://www.parallax.com/product/900-00005http://www.businessinsider.com/chris-dixon-future-of-self-driving-cars-interview-2016-6?r=US&IR=T&IR=Thttp://www.businessinsider.com/chris-dixon-future-of-self-driving-cars-interview-2016-6?r=US&IR=T&IR=Thttp://autoshowsaudiusa.com/en-us/releases/11https://korkort.se/fickparkering/

  • BIBLIOGRAPHY

    [11] M. Barr, “Introduction to Pulse Width Modulation (PWM),” EmbeddedSystems Programming, pp. 103–104, sep, date accessed: 2017-03-26.[Online]. Available: https://barrgroup.com/Embedded-Systems/How-To/PWM-Pulse-Width-Modulation

    [12] I2C Info, “I2C Info - I2C Bus, Interface and Protocol,” date accessed:2017-03-24. [Online]. Available: http://i2c.info/

    [13] STMicroelectronics, “VL6180X - Proximity sensor, gesture and ambient lightsensing (ALS) module - STMicroelectronics,” date accessed: 2017-03-18.[Online]. Available: http://www.st.com/en/imaging-and-photonics-solutions/vl6180x.html

    [14] Adafruit, “Adafruit TCA9548A 1-to-8 I2C Multiplexer Breakout,” dateaccessed: 2017-05-09. [Online]. Available: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout.pdf

    [15] Maxon “maxon motor - Online Shop,” date accessed: 2017-03-18.[Online]. Available: http://www.maxonmotor.com/maxon/view/product/motor/dcmotor/amax/amax22/110147

    [16] Maxon, “maxon motor - Online Shop,” date accessed: 2017-03-18.[Online]. Available: http://www.maxonmotor.com/maxon/view/product/gear/planetary/gp22/232766

    [17] Posital, “Incremental Encoder Signals: HTL (Push-Pull) or TTL (RS422),”date accessed: 2017-03-22. [Online]. Available: https://www.posital.com/en/products/communication-interface/incremental/incremental-encoders.php

    [18] Toshiba, “Toshiba Bi-CD Integrated Circuit Silicon Monolithic TB6612FNGDriver IC for Dual DC motor,” date accessed 2017-05-10. [Online]. Available:https://www.pololu.com/file/0J86/TB6612FNG.pdf

    [19] P. Inc, “Parallax Standard Servo (#900-00005).” [On-line]. Available: https://www.parallax.com/sites/default/files/downloads/900-00005-Standard-Servo-Product-Documentation-v2.2.pdf

    [20] Volvo Personvagnar, “Dimension sketch Volvo V60 - Volvo Car SverigeAB Newsroom,” date accessed: 2017-06-05. [Online]. Available: https://www.media.volvocars.com/se/sv-se/media/photos/97546

    24

    https://barrgroup.com/Embedded-Systems/How-To/PWM-Pulse-Width-Modulationhttps://barrgroup.com/Embedded-Systems/How-To/PWM-Pulse-Width-Modulationhttp://i2c.info/http://www.st.com/en/imaging-and-photonics-solutions/vl6180x.htmlhttp://www.st.com/en/imaging-and-photonics-solutions/vl6180x.htmlhttps://cdn-learn.adafruit.com/downloads/pdf/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout.pdfhttps://cdn-learn.adafruit.com/downloads/pdf/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout.pdfhttp://www.maxonmotor.com/maxon/view/product/motor/dcmotor/amax/amax22/110147http://www.maxonmotor.com/maxon/view/product/motor/dcmotor/amax/amax22/110147http://www.maxonmotor.com/maxon/view/product/gear/planetary/gp22/232766http://www.maxonmotor.com/maxon/view/product/gear/planetary/gp22/232766https://www.posital.com/en/products/communication-interface/incremental/incremental-encoders.phphttps://www.posital.com/en/products/communication-interface/incremental/incremental-encoders.phphttps://www.pololu.com/file/0J86/TB6612FNG.pdfhttps://www.parallax.com/sites/default/files/downloads/900-00005-Standard-Servo-Product-Documentation-v2.2.pdfhttps://www.parallax.com/sites/default/files/downloads/900-00005-Standard-Servo-Product-Documentation-v2.2.pdfhttps://www.media.volvocars.com/se/sv-se/media/photos/97546https://www.media.volvocars.com/se/sv-se/media/photos/97546

  • Appendix A

    Datasheet for DC motor

    25

  • APPENDIX A. DATASHEET FOR DC MOTOR

    203203

    max

    on A

    -max

    6.010000

    2000

    4000

    6000

    8000

    0.2 0.4 0.6 1.00.8

    2.0 4.0 6.0 10.08.0

    110147

    M 1:1

    110143 110145 110146 110147 110148 110149 110150 110151 110152 110153 110154 110155139840 353017 199807 320206 323856 108828 199424 202921 267433 325492 313302 353019

    20 K/W 6.0 K/W 10.2 s 314 s -30…+85°C +125°C

    0.05 - 0.15 mm 0.012 mm 1 N 80 N 2.8 N

    0.05 - 0.15 mm 0.025 mm 3.3 N 45 N 12.3 N

    1 9 54 g

    ESCON Module 24/2 416ESCON 36/2 DC 416ESCON Module 50/5 417ESCON 50/5 418

    6 9 9 12 12 15 18 24 24 36 48 489240 9690 8500 10200 9170 10000 9770 10500 8480 9630 9110 821083.1 57.9 49.6 45.8 40.5 36 29 23.7 18.4 14.2 9.99 8.846240 6530 5350 7060 6000 6890 6600 7380 5270 6420 5840 49405.91 6.88 7.04 6.96 6.95 6.93 6.92 6.9 6.97 6.86 6.75 6.861.08 0.859 0.77 0.681 0.613 0.534 0.432 0.347 0.283 0.21 0.147 0.13519.4 22.1 19.8 23.7 20.9 22.9 22 23.7 18.9 21.1 19.2 17.63.29 2.59 2.04 2.17 1.72 1.65 1.29 1.12 0.721 0.606 0.393 0.32567 70 69 72 70 72 72 73 70 72 71 70

    1.82 3.48 4.42 5.53 6.96 9.09 14 21.5 33.3 59.4 122 1480.106 0.223 0.288 0.363 0.445 0.585 0.891 1.37 2.1 3.69 7.3 8.975.9 8.55 9.73 10.9 12.1 13.9 17.1 21.2 26.2 34.8 48.9 54.3

    1620 1120 981 875 790 689 558 450 364 274 195 176500 454 446 444 455 452 457 456 461 468 487 47920.9 20.2 20.1 19.9 19.9 19.9 19.7 19.7 19.8 19.7 19.9 19.8

    4 4.25 4.3 4.29 4.19 4.2 4.13 4.13 4.09 4.02 3.9 3.94

    Stock programStandard programSpecial program (on request)

    Part Numbers

    Specifications Operating Range Comments

    n [rpm] Continuous operationIn observation of above listed thermal resistance (lines 17 and 18) the maximum permissible winding temperature will be reached during continuous op-eration at 25°C ambient.= Thermal limit.

    Short term operationThe motor may be briefly overloaded (recurring).

    Assigned power rating

    maxon Modular System Overview on page 20–27

    April 2016 edition / subject to change maxon DC motor

    A-max 22 ∅22 mm, Graphite Brushes, 6 Watt

    Motor Data

    Thermal data17 Thermal resistance housing-ambient18 Thermal resistance winding-housing19 Thermal time constant winding20 Thermal time constant motor21 Ambient temperature22 Max. winding temperature

    Mechanical data (sleeve bearings)23 Max. speed 9800 rpm24 Axial play25 Radial play26 Max. axial load (dynamic)27 Max. force for press fits (static)28 Max. radial load, 5 mm from flange

    Mechanical data (ball bearings)23 Max. speed 9800 rpm24 Axial play25 Radial play26 Max. axial load (dynamic)27 Max. force for press fits (static)28 Max. radial load, 5 mm from flange

    Other specifications29 Number of pole pairs30 Number of commutator segments31 Weight of motor

    Values listed in the table are nominal. Explanation of the figures on page 151.

    Option Ball bearings in place of sleeve bearings

    Planetary Gearhead∅22 mm0.1 - 0.6 NmPage 327/328

    Recommended Electronics:Notes Page 24

    Planetary Gearhead∅22 mm0.5 - 2.0 NmPage 329/331

    Values at nominal voltage1 Nominal voltage V2 No load speed rpm3 No load current mA4 Nominal speed rpm5 Nominal torque (max. continuous torque) mNm6 Nominal current (max. continuous current) A7 Stall torque mNm8 Stall current A9 Max. efficiency %

    Characteristics10 Terminal resistance W11 Terminal inductance mH12 Torque constant mNm/A13 Speed constant rpm/V14 Speed / torque gradient rpm/mNm15 Mechanical time constant ms16 Rotor inertia gcm2

    with terminalswith cables

    Spur Gearhead∅24 mm0.1 NmPage 335Spindle Drive∅22 mmPage 368/369

    1606_DC_motor.indd 203 14.04.16 13:07

    Figure A.1: Datasheet of DC motor from Maxon.

    26

  • Appendix B

    Datasheet for Gearhead

    27

  • APPENDIX B. DATASHEET FOR GEARHEADm

    axo

    n g

    ear

    328

    A-max 22 201-204 54.7 61.5 68.3 68.3 75.1 75.1 75.1 81.9 81.9 81.9 81.9A-max 22 202/204 MR 388/390 59.7 66.5 73.3 73.3 80.1 80.1 80.1 86.9 86.9 86.9 86.9A-max 22 202/204 Enc 22 398 69.1 75.9 82.7 82.7 89.5 89.5 89.5 96.3 96.3 96.3 96.3A-max 22 202/204 MEnc 13 409 61.8 68.6 75.4 75.4 82.2 82.2 82.2 89.0 89.0 89.0 89.0

    M 1:2

    232763 232766 232772 232778 232782 232788 232794 232796 232803 232809 232815

    3.8 : 1 14 : 1 53 : 1 104 : 1 198 : 1 370 : 1 590 : 1 742 : 1 1386 : 1 1996 : 1 3189 : 1 15⁄4 225⁄16 3375⁄64 87723⁄845 50625⁄256 10556001⁄28561 59049⁄100 759375⁄1024 158340015⁄114244 285012027⁄142805 1594323⁄5004 4 4 3.2 4 3.2 4 4 3.2 3.2 4

    232764 232767 232773 232779 232783 232789 232795 232798 232804 232810 2328164.4 :1 16 : 1 62 : 1 109 : 1 231 : 1 389 : 1 690 : 1 867 : 1 1460 : 1 2102 : 1 3728 : 1

    57⁄13 855⁄52 12825⁄208 2187⁄20 192375⁄832 263169⁄676 1121931⁄1625 2885625⁄3328 3947535⁄2704 7105563⁄3380 30292137⁄81253.2 3.2 3.2 4 3.2 3.2 3.2 3.2 3.2 3.2 3.2

    232765 232768 232774 232780 232784 232790 232797 232799 232805 232811 2328175.4 : 1 19 : 1 72 : 1 128 : 1 270 : 1 410 : 1 850 : 1 1014 : 1 1538 : 1 2214 : 1 4592 : 1

    27⁄5 3249⁄169 48735⁄676 41553⁄325 731025⁄2704 6561⁄16 531441⁄625 10965375⁄10816 98415⁄64 177147⁄80 14348907⁄31252.5 3.2 3.2 3.2 3.2 4 2.5 3.2 4 4 2.5

    232769 232775 232781 232785 232791 232800 232806 23281220 : 1 76 : 1 157 : 1 285 : 1 455 : 1 1068 : 1 1621 : 1 2458 : 1

    81⁄4 1215⁄16 19683⁄125 18225⁄64 5000211⁄10985 273375⁄256 601692057⁄371293 135005697⁄549254 4 2.5 4 3.2 4 3.2 3.2

    232770 232776 232786 232792 232801 232807 23281324 : 1 84 : 1 316 : 1 479 : 1 1185 : 1 1707 : 1 2589 : 11539⁄65 185193⁄2197 2777895⁄8788 124659⁄260 41668425⁄35152 15000633⁄8788 3365793⁄13003.2 3.2 3.2 3.2 3.2 3.2 3.2

    232771 232777 232787 232793 232802 232808 23281429 : 1 89 : 1 333 : 1 561 : 1 1249 : 1 1798 : 1 3027 : 1729⁄25 4617⁄52 69255⁄208 2368521⁄4225 1038825⁄832 373977⁄208 63950067⁄211252.5 3.2 3.2 3.2 3.2 3.2 3.2

    1 2 3 3 4 4 4 5 5 5 50.2 0.3 0.4 0.4 0.5 0.5 0.5 0.6 0.6 0.6 0.60.3 0.4 0.5 0.5 0.7 0.7 0.7 0.8 0.8 0.8 0.884 70 59 59 49 49 49 42 42 42 4228 35 43 43 51 51 51 59 59 59 591.0 1.2 1.6 1.6 2.0 2.0 2.0 2.0 2.0 2.0 2.00.5 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.422.7 29.5 36.3 36.3 43.1 43.1 43.1 49.9 49.9 49.9 49.9

    maxon gear April 2016 edition / subject to change

    Stock programStandard programSpecial program (on request)

    overall length overall length

    maxon Modular System+ Motor Page + Sensor/Brake Page Overall length [mm] = Motor length + gearhead length + (sensor/brake) + assembly parts

    Technical DataPlanetary Gearhead straight teethHousing plasticOutput shaft stainless steel, hardenedBearing at output sleeve bearingRadial play, 10 mm from flange max. 0.1 mmAxial play max. 0.15 mmMax. axial load (dynamic) 20 NMax. force for press fits 100 NDirection of rotation, drive to output =Max. continuous input speed 6000 rpmRecommended temperature range -15…+80°CNumber of stages 1 2 3 4 5Max. radial load, 10 mm from flange 15 N 20 N 25 N 30 N 30 N

    Planetary Gearhead GP 22 L ∅22 mm, 0.2–0.6 NmPlastic Version

    Part Numbers

    Gearhead Data 1 Reduction 2 Absolute reduction 3 Max. motor shaft diameter mm

    Part Numbers 1 Reduction 2 Absolute reduction 3 Max. motor shaft diameter mm

    Part Numbers 1 Reduction 2 Absolute reduction 3 Max. motor shaft diameter mm

    Part Numbers 1 Reduction 2 Absolute reduction 3 Max. motor shaft diameter mm

    Part Numbers 1 Reduction 2 Absolute reduction 3 Max. motor shaft diameter mm

    Part Numbers 1 Reduction 2 Absolute reduction 3 Max. motor shaft diameter mm 4 Number of stages 5 Max. continuous torque Nm 6 Max. intermittent torque at gear output Nm 7 Max. efficiency % 8 Weight g 9 Average backlash no load ° 10 Mass inertia gcm2

    11 Gearhead length L1 mm

    1608_Gear.indd 328 22.04.16 14:53

    Figure B.1: Datasheet of gearhead from Maxon.

    28

  • Appendix C

    Wiring Diagram

    Figure C.1: Wiring diagram of all components used (created in EAGLE).

    29

  • Appendix D

    Code

    1 // Lovisa Henriksson and Victor Lundel l2 // Arduino code f o r bache lo r p r o j e c t in mechatronics 2017 , S e l f Parking

    Robot345 #inc lude // importerar funk t i one r f ö r servomotorn6 #inc lude // importerar funk t i one r f ö r sensorn7 #inc lude // importerar funk t i one r som använder I2C8 #d e f i n e TCAADDR 0x70 // mul t ip l exe rn9 #d e f i n e VL6180X ADDRESS 0x29 // sensorn

    1011 VL6180xIdent i f i ca t i on i d e n t i f i c a t i o n ;12 VL6180x sensor1 (VL6180X ADDRESS) ;13 VL6180x sensor2 (VL6180X ADDRESS) ;14 VL6180x sensor3 (VL6180X ADDRESS) ;15 Servo servo ;16 //Motor17 i n t STBY = 10 ;18 i n t PWMA = 3 ; // Speed c o n t r o l19 i n t AIN1 = 9 ; // D i r e c t i on20 i n t AIN2 = 8 ; // D i r e c t i on21 // encoder v a r i a b l e s22 i n t va l ;23 i n t encoderPinA = 2 ;24 i n t encoderPinB = 4 ;25 i n t encoderPos = 0 ;26 i n t encoderPosLast = 0 ;27 i n t encoderPinALast = LOW;28 i n t n = LOW;29 i n t pinB = LOW;30 i n t encoderSteps = 512 ;31 // s t e e r i n g v a r i a b l e s32 i n t servoPin = 5 ;33 // d i s t a n c e v a r i a b l e s34 i n t d i s t a n c e ;35 i n t s enso rDi s tance ;36 i n t s ensorDi s ;

    31

  • APPENDIX D. CODE

    37 i n t minDistance = 150 ;38 f l o a t s p o t S i z e = 0 ;39 f l o a t minSpotSize = 290 ; // ändrad f rån 38 f ö r mäter f e l , 270 verkar

    fungera at t b l i 38040 f l o a t p i = 3 .141593 ;41 f l o a t wheelCirc = 65 ∗ pi ;4243 i n t pwm1 = 170 ; // 15044 i n t pwm2 = 250 ;45 i n t pwm3 = 150 ; //504647 void setup ( ) {48 // S e r i a l . p r i n t l n (1 ) ;49 sensorSetup ( ) ;5051 // encoder setup52 pinMode ( encoderPinA , INPUT) ;53 pinMode ( encoderPinB , INPUT) ;5455 // servo setup56 se rvo . attach ( servoPin ) ;57 se rvo . wr i t e (90) ;5859 //motor setup60 pinMode (STBY, OUTPUT) ;61 pinMode (PWMA, OUTPUT) ;62 pinMode (AIN1 , OUTPUT) ;63 pinMode (AIN2 , OUTPUT) ;6465 t c a s e l e c t (1 ) ;66 delay (3000) ; // lång de lay f ö r a t t sensorn v i s a r 0 e t t tag i bör jan67 }6869 void loop ( ) {70 S e r i a l . p r i n t l n ( ” loop ” ) ;71 stop ( ) ;72 s enso rDi s tance = sensor1 . ge tDi s tance ( ) ;73 checkObject (2 ) ;74 move(pwm3, 1) ;75 i f ( s enso rDi s tance > minDistance ) {76 s p o t S i z e = checkDistance ( ) ;77 i f ( s p o t S i z e >= minSpotSize ) {78 stop ( ) ;79 delay (2000) ; // Delays f ö r a t t l ä t t a r e kunna

    f ö l j a robotens väg80 moveDistance (110 , 1 , pwm1) ;81 delay (2000) ;82 park ( ) ;83 delay (7000) ;84 }85 }86 delay (10) ; // t iden den åker frammåt87 }88

    32

  • 89 void checkObject ( i n t way) {90 i f (way == 2) {91 t c a s e l e c t (2 ) ;92 s ensorDi s = sensor2 . ge tDi s tance ( ) ;93 whi le ( s ensorDi s < 50) {94 S e r i a l . p r i n t l n ( sensorDi s ) ;95 s ensorDi s = sensor2 . ge tDi s tance ( ) ;96 }97 }98 i f (way = 3) {99 t c a s e l e c t (3 ) ;

    100 s ensorDi s = sensor3 . ge tDi s tance ( ) ;101 whi le ( s ensorDi s < 50) {102 S e r i a l . p r i n t l n ( sensorDi s ) ;103 s ensorDi s = sensor3 . ge tDi s tance ( ) ;104 }105 }106 t c a s e l e c t (1 ) ;107 }108109 void park ( ) {110 // 237 innan111 stop ( ) ;112 delay (500) ;113 se rvo . wr i t e (90 + 40) ;114 delay (1000) ;115 moveDistance (290 , 0 , pwm2) ;116 delay (500) ;117 se rvo . wr i t e (90 − 40) ;118 delay (1000) ;119 moveDistance (290 , 0 , pwm2) ;120 delay (500) ;121 se rvo . wr i t e (90) ;122 delay (1000) ;123 moveDistance (30 , 1 , pwm1) ;124 // stop ( ) ;125 }126127 void moveDistance ( i n t dis , i n t d ir , i n t pwm) {128 S e r i a l . p r i n t l n ( ”moveDis” ) ;129 stop ( ) ;130 encoderPos = 0 ;131 d i s t a n c e = 0 ;132 move(pwm, d i r ) ;133 whi le ( d i s t a n c e < d i s ) {134 n = dig i ta lRead ( encoderPinA ) ;135 i f ( ( encoderPinALast == LOW) && (n == HIGH) ) {136 i f ( d i g i t a lRead ( encoderPinB ) == LOW) {137 encoderPos−−;138 } e l s e {139 }140 }141 encoderPinALast = n ;142 d i s t a n c e = ( f l o a t ) encoderPos ∗ wheelCirc / ( f l o a t ) encoderSteps ;

    33

  • APPENDIX D. CODE

    143 d i s t a n c e = abs ( d i s t a n c e ) ;144 }145 stop ( ) ;146 }147148 f l o a t checkDistance ( ) {149 stop ( ) ;150 s p o t S i z e = 0 ;151 whi le ( s enso rDi s tance >= minDistance ) {152 i f ( s p o t S i z e >= minSpotSize ) {153 break ;154 }155 moveDistance (5 , 1 , pwm1) ;156 s p o t S i z e = s p o t S i z e + 5 ;157 s enso rDi s tance = sensor1 . ge tDi s tance ( ) ;158 checkObject (2 ) ;159 }160 re turn s p o t S i z e ;161 }162163 void move( i n t speed , i n t d i r e c t i o n ) {164 //Code from http :// b i l d r . org /2012/04/ tb6612fng−arduino/#165 // Accessed 2017−04−10166167 //Move s p e c i f i c motor at speed and d i r e c t i o n168 //motor : 0 f o r B 1 f o r A169 // speed : 0 i s o f f , and 255 i s f u l l speed170 // d i r e c t i o n : 0 c lockwise , 1 counter−c l o c kw i s e171172 d i g i t a l W r i t e (STBY, HIGH) ; // d i s a b l e standby173174 boolean inPin1 = LOW;175 boolean inPin2 = HIGH;176177 i f ( d i r e c t i o n == 1) {178 inPin1 = HIGH;179 inPin2 = LOW;180 }181182 d i g i t a l W r i t e (AIN1 , inPin1 ) ;183 d i g i t a l W r i t e (AIN2 , inPin2 ) ;184 analogWrite (PWMA, speed ) ;185 }186187 void stop ( ) {188 // enable standby189 d i g i t a l W r i t e (STBY, LOW) ;190 }191192 void sensorSetup ( ) {193194 // d i s t a n c e s enso r setup195 S e r i a l . begin (115200) ; // Star t S e r i a l at 115200 bps196 Wire . begin ( ) ; // Star t I2C l i b r a r y

    34

  • 197 delay (100) ; // de lay . 1 s198 t c a s e l e c t (1 ) ;199 s ensor1 . g e t I d e n t i f i c a t i o n (& i d e n t i f i c a t i o n ) ; // Ret r i eve manufacture

    i n f o from dev i ce memory200 p r i n t I d e n t i f i c a t i o n (& i d e n t i f i c a t i o n ) ; // Helper func t i on to p r i n t a l l

    the Module in fo rmat ion201 i f ( s ensor1 . VL6180xInit ( ) != 0) {202 S e r i a l . p r i n t l n ( ”FAILED TO INITALIZE 1” ) ; // I n i t i a l i z e dev i c e and

    check f o r e r r o r s203 } ;204 s ensor1 . VL6180xDefautSettings ( ) ; //Load d e f a u l t s e t t i n g s to get

    s t a r t e d .205206 delay (1000) ; // de lay 1 s207208 t c a s e l e c t (2 ) ;209 s ensor2 . g e t I d e n t i f i c a t i o n (& i d e n t i f i c a t i o n ) ;210 i f ( s ensor2 . VL6180xInit ( ) != 0) {211 S e r i a l . p r i n t l n ( ”FAILED TO INITALIZE senso r 2” ) ;212 } ;213 s ensor2 . VL6180xDefautSettings ( ) ;214 delay (500) ;215216 t c a s e l e c t (3 ) ;217 s ensor3 . g e t I d e n t i f i c a t i o n (& i d e n t i f i c a t i o n ) ;218 i f ( s ensor3 . VL6180xInit ( ) != 0) {219 S e r i a l . p r i n t l n ( ”FAILED TO INITALIZE senso r 3” ) ;220 } ;221 s ensor3 . VL6180xDefautSettings ( ) ;222 delay (500) ;223224225 }226227 void t c a s e l e c t ( u i n t 8 t i ) {228 // code from https : // cdn−l e a r n . a d a f r u i t . com/downloads/ pdf / ada f ru i t−

    tca9548a−1−to−8−i2c−mult ip l exer−breakout . pdf229 // Accessed 2017−05−09230231 i f ( i > 7) re turn ;232 Wire . beg inTransmiss ion (TCAADDR) ;233 Wire . wr i t e (1 idModel ) ;240241 S e r i a l . p r i n t ( ”Model Rev = ” ) ;242 S e r i a l . p r i n t ( temp−>idModelRevMajor ) ;243 S e r i a l . p r i n t ( ” . ” ) ;244 S e r i a l . p r i n t l n ( temp−>idModelRevMinor ) ;245

    35

  • APPENDIX D. CODE

    246 S e r i a l . p r i n t ( ”Module Rev = ” ) ;247 S e r i a l . p r i n t ( temp−>idModuleRevMajor ) ;248 S e r i a l . p r i n t ( ” . ” ) ;249 S e r i a l . p r i n t l n ( temp−>idModuleRevMinor ) ;250251 S e r i a l . p r i n t ( ” Manufacture Date = ” ) ;252 S e r i a l . p r i n t ( ( temp−>idDate >> 3) & 0x001F ) ;253 S e r i a l . p r i n t ( ”/” ) ;254 S e r i a l . p r i n t ( ( temp−>idDate >> 8) & 0x000F ) ;255 S e r i a l . p r i n t ( ”/1” ) ;256 S e r i a l . p r i n t ( ( temp−>idDate >> 12) & 0x000F ) ;257 S e r i a l . p r i n t ( ” Phase : ” ) ;258 S e r i a l . p r i n t l n ( temp−>idDate & 0x0007 ) ;259260 S e r i a l . p r i n t ( ” Manufacture Time ( s )= ” ) ;261 S e r i a l . p r i n t l n ( temp−>idTime ∗ 2) ;262 S e r i a l . p r i n t l n ( ) ;263 S e r i a l . p r i n t l n ( ) ;264 }

    36

  • TRITA MMK 2017:20 MDAB 638

    www.kth.se

    List of FiguresList of TablesAbbreviationsIntroductionBackgroundPurposeMethodScope

    TheoryAckermann SteeringParkingPulse-width ModulationInter-Integrated Circuit

    DemonstratorHardwareArduinoDistance SensorMultiplexerDC motor and encoderMotor DriverServomotor

    ElectronicsSoftwareMovementDistance Sensors and Multiplexer

    Testing and ResultsTestingParking Results

    Discussion and ConclusionsDiscussionParking PathArduino UNOError Sources

    Conclusion

    BibliographyDatasheet for DC motorDatasheet for GearheadWiring DiagramCode