DEGREE PROJECT IN TECHNOLOGY, FIRST CYCLE, 15 CREDITS STOCKHOLM, SWEDEN 2018

Electric A dual-purpose personal vehicle

LEO SÖDERGREN

KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT Electric Longboard

LEO SODERGREN¨

Bachelor’s Thesis at ITM Supervisor: Nihad Subasic Examiner: Nihad Subasic

TRITA-ITM-EX 2018:72

Abstract

Keywords: mechatronics, personal transportation, , last mile transport, adaptive power management.

The aim of this thesis is to explore the possibility of a dual-purpose electric vehicle. The vehicle should be able to be used for both commuting and racing. It also aims to describe different power limiting methods and their effect on performance. Lastly it hopes to see if the Swedish laws, as written today are reasonable. An electric longboard has been constructed for this purpose and several tests have been performed.

A list of goals were set up for the board prototype. These included power output, running time, and that the board should have an audible warning device.

The findings demonstrated that all tested power limiting methods worked and that the “Simple power limiting” method provided quickest movement over a fixed distance. Most of the goals were met by the prototype and the board’s two modes worked as planned. While the law is reasonable it can be improved to cover the diversity of electric vehicles. Further work may include better measurements and imple- mentation of a dual microcontroller system. Referat

Elektrisk Longboard

Nyckelord: Mekatronik, personlig transport, elfordon, ”sista str¨ackan” transportmedel, adaptiv energidrift.

Syftet med detta arbete ¨ar att testa m¨ojligheten med ett tv˚a-l¨ages personligt fordon. Fordonenet ska kunna anv¨andas f¨or b˚adependling och t¨avling. Arbetet har ¨aven testat olika energilimeteringsmetoder samt unders¨okt hur dessa meto- der p˚averkar prestandan. Arbetet har ¨aven f¨ors¨okt besvara fr˚aganom det svenska lagarna, som det ¨ar skrivna idag, ¨ar l¨ampliga. En elektrisk longboard har konstruerats och flera test utf¨orts.

Ett antal m˚als¨attningar har definerats f¨or prototypen. Des- sa inkluderar: effekt, k¨ortid och att br¨adan b¨or ha en ring- klocka.

Resultaten visar att alla metoder fungerade och att “Simple power limiting” var den som gav snabbast r¨orelse ¨over den best¨amda str¨ackan. Det flesta av m˚alenn˚addesav prototy- pen och br¨adans tv˚al¨agen fungerade som t¨ankt. Dagens la- gar ¨ar rimliga men kan f¨orb¨attras f¨or att t¨acka m˚angfalden av elektriska fordon. Framtida arbete kan inkludera b¨attre m¨atningar och implementation av ett system med tv˚amikro- kontroller. Acknowledgements

I would like to thank Rosalinn Aponte Persson for being my helping hand and test subject.

I would also like to thank Nihad Subasic and Staffan Qvarnstr¨omfor their help.

Lastly I would like to thank Axel Fyresk¨ar,Olivia Ekman, Stefan Ionescu, Elizabeth Watson, and Tom S¨odergrenfor their feedback and ideas. Contents

Acknowledgements

List of Abbreviations

1 Introduction 1 1.1 Background ...... 1 1.2 Purpose ...... 2 1.3 Scope ...... 2 1.4 Method ...... 2

2 Theory 3 2.1 The longboard ...... 3 2.2 Permanent magnet synchronous motor and speed controllers . . . . . 5 2.3 Longboard drive systems ...... 7 2.4 Battery technology ...... 8 2.5 PPM and PWM ...... 11

3 Demonstrator 12 3.1 The system ...... 12 3.2 Logic ...... 14 3.2.1 Lighting ...... 14 3.2.2 Sensors ...... 15 3.2.3 LED matrix ...... 15 3.2.4 MCU ...... 15 3.3 Driveline ...... 16 3.3.1 Motors ...... 16 3.3.2 Batteries ...... 18 3.3.3 Parking brake ...... 19 3.3.4 Power distribution ...... 19 3.3.5 ESC ...... 20 3.4 Control ...... 21 3.4.1 Hand controller and receiver ...... 21 3.5 Structure ...... 23 3.5.1 The Deck ...... 23 3.5.2 Trucks and wheels ...... 25 3.5.3 Lids ...... 25 3.5.4 Lenses ...... 26 3.6 Software ...... 26

4 Experiments 31 4.1 Acceleration and retardation test ...... 31 4.2 Range test ...... 31 4.3 Light pattern measurements ...... 31 4.4 Light strength test ...... 32 4.5 Parking brake test ...... 32

5 Findings 33 5.1 Acceleration and retardation ...... 33 5.2 Range ...... 35 5.3 Light pattern ...... 36 5.4 Light strength ...... 38 5.5 Parking brake ...... 38

6 Discussion and conclusion 39 6.1 Discussion ...... 39 6.2 Conclusion ...... 40

7 Further work 42

Bibliography 43

Appendices 46

A Arduino code to control the board 47 A.1 The main code ...... 47 A.2 Config code ...... 57

B Acceleration tests graphs 60 B.1 Average mode ...... 60 B.2 Running average cutoff ...... 61 B.3 Running average ...... 62 B.4 Simple power limiting ...... 63 B.5 Race mode ...... 64

C Matlab code to convert accelerometer data 65

D Matlab code to analyze light measurements 67

E Layout and schematic for the LED board 69 F Layout and schematic for the power distribution board 70

G Layout and schematic for the voltage divider board 73

H Layout and schematic for the buzzer board 75

I Images of the completed board 76

J Images of the completed hand controller 82

K 3D model of the hand controller 84

L 3D model of the board 85 List of Figures

2.1 A deck in red with the griptape in blue. Designed in Autodesk Fusion 360 rendered in Blender...... 3 2.2 Exploded view of a truck. The hanger is marked blue, the connecting elements in red and the hanger in yellow. Made with Autodesk Fusion 360...... 4 2.3 Exploded view of a wheel assembly. The wheel is blue, bearings red and the spacer yellow. Made with Autodesk Fusion 360...... 4 2.4 Back EMF for one phase in BLDC and BLAC motors. Drawn in Adobe Illustrator...... 6 2.5 Simplified motor schematic. Drawn in Adobe Illustrator...... 7 2.6 Geared drive system [1]. Motor in grey, pulleys highlighted in orange and belt highlighted in blue. Highlights drawn in Illustrator...... 8 2.7 Expected cycle life corresponding to level of discharge [2]...... 10 2.8 PPM and PWM signals over time correlating to an analog value. Drawn in Adobe Illustrator...... 11

3.1 System diagram. The orange lines are data and black, power. Drawn in Adobe Illustrator...... 13 3.2 Light module PCB. Made with Adobe Illustrator and Autodesk Eagle. . 15 3.3 Render of Maytechs 90 mm hub motor. Made with Autodesk Fusion 360. 16 3.4 Cutaway drawing of the parking brake assembly. Servo arm in green, the metal wire in blue and wire guide in red. Made with Autodesk Fusion 360 and Adobe Photoshop...... 19 3.5 Diagram of the board’s two voltage systems. Drawn in Adobe Illustrator. 20 3.6 Exploded view of the hand controller. The 3D-printed shell is in blue, the 18650-battery in pink, the controller circuit board in grey and black, the buzzer circuit board in green and the buzzer is the black hexagon. Made with Autodesk Fusion 360...... 22 3.7 Placement of the three compartments. Battery compartments in blue and the main compartment in orange. Drawn in Adobe Illustrator . . . 23 3.8 Exploded view of the deck’s structure. Made with blender and Adobe Illustrator ...... 24 3.9 Render of the main lid. The push-button is seen as black and red on the top of the lid. Made in Autodesk fusion 360...... 25 3.10 Render of the front lens. Note the 6 divots for the LED. Designed in Autodesk Fusion 360 rendered in blender...... 26 3.11 Flowchart for the ”Running average cutoff” function. Made with draw.io and Adobe Illustrator...... 28 3.12 Flowchart for the ”Running average cutoff” function. Made with draw.io and Adobe Illustrator...... 28 3.13 Flowchart for the ”Average” function. Made with draw.io and Adobe Illustrator...... 29 3.14 Flowchart for the push-button interrupt function that changes between light states. Made with draw.io and Adobe Illustrator...... 29 3.15 Program main flowchart. Made with draw.io and Adobe Illustrator . . . 30

4.1 Test pattern for the lights. Drawn in Adobe Illustrator...... 32

5.1 Measured light pattern for the board’s headlight, generated in Matlab. . 36 5.2 Measured light pattern for the board’s taillight, generated in Matlab. . . 36 5.3 Measured light pattern for Lezyne Hecto Drive 300XL, generated in Mat- lab...... 37 5.4 Measured light pattern for Lezyne Strip Drive, generated in Matlab. . . 37

E.1 LED module circuit board layout. Made in Autodesk Eagle ...... 69 E.2 LED module circuit board layout. Made in Autodesk Eagle ...... 69

F.1 Power distribution circuit board top. Made in Autodesk Eagle . . . . . 70 F.2 Power distribution circuit board bottom. Made in Autodesk Eagle . . . 71 F.3 Power distribution battery connection circuit schematic. Made in Au- todesk Eagle ...... 71 F.4 Power distribution voltage regulation circuit schematic. Made in Au- todesk Eagle ...... 72 F.5 Power distribution VESC connection circuit schematic. Made in Au- todesk Eagle ...... 72

G.1 Voltage divider circuit board layout. Made in Autodesk Eagle ...... 73 G.2 Voltage divider circuit schematic. Made in Autodesk Eagle ...... 74

H.1 Buzzer circuit board layout. Made in Autodesk Eagle ...... 75 H.2 Buzzer circuit schematic. Made in Autodesk Eagle ...... 75

I.1 The completed board ...... 76 I.2 The underside of the completed board ...... 77 I.3 Lid over battery compartment ...... 77 I.4 The main compartment lid with the push-button...... 78 I.5 The front of the board with the headlight...... 78 I.6 The parking brake as seen from underneath the board. Note that the wire guide is missing...... 79 I.7 The LED matrix displaying a battery cell error for cell 8...... 79 I.8 The LED matrix displaying an in-signal error...... 80 I.9 The LED matrix displaying a checkered flag...... 80 I.10 The board with its head and taillights lit...... 81

J.1 Side view of the hand controller...... 82 J.2 Front view of the hand controller. Note the push-button to activate the AW-dev ...... 82 J.3 Top view of the hand controller...... 83 J.4 The hand controller in a hand...... 83 List of Tables

2.1 Comparison between battery technologies [3, 4, 5] ...... 9 2.2 Recommended cutoff voltage for different technologies[6]...... 9

3.1 Used LEDs characteristics [7, 8] ...... 14 3.2 Possible battery configurations [9]...... 18

5.1 Acceleration data from the different power modes...... 34 5.2 Noted data from the range test...... 35 5.3 Measured angles and failures for the parking brake tests...... 38 List of Abbreviations

AC – Alternating current BLDC - Brushless direct current BLAC - Brushless alternating current DC – Direct current EMF – Electromotive force FOC - Field orientation control IC - Integrated circuit LED – Light emitting diode MDF – Medium density fibreboard PCB – Printed circuit board PID – Proportional-integral-derivative RC – Radio control RGB - Red Green Blue

Chapter 1

Introduction

1.1 Background

A longboard is a type of , a personal vehicle, generally used for commut- ing and downhill riding. It can have many benefits over more traditional modes of transport: it is generally quicker and requires less effort than walking or running, it is portable so it can be brought inside, removing the need for roadside parking and locks. The major drawback with longboards are their lack of brakes and that they require a high grade of mobility from the user.

Electric “last mile” vehicles are growing in popularity in today’s urban environ- ment. “Last mile” refers to the smallest and often overlooked part of everyday urban commute; the last stretch from the bus or train to the door of the destina- tion. Several major cities are looking into the possibility of -free city centers [10]. In March 2018 the Swedish government made it possible for municipalities to adapt new environmental zones to regulate which vehicles would be allowed to travel within these new zones [11]. The strictest zone, “class 3”, would forbid all types of petrol and diesel vehicles, which accounts for about 95% of new vehicles in Sweden, 2015 [12].

In the summer of 2001 the Swedish government chose to redefine several street vehicles [13]. The new definitions expanded on the category ”bicycles” to include electric vehicles. The new definition was followed by a regulation change from The Swedish Transport Agency [14]. The regulation (TSFS 2009:31) states several re- quirements on electric vehicles such as maximum allowed speed, brake requirements, and illumination requirements.

An electric longboard combines the biggest advantages of both longboards and electric vehicles. While electric longboards exist on the market, none follow the Swedish laws. They also have primitive ways of providing board status back the user[1] [15].

1 CHAPTER 1. INTRODUCTION

1.2 Purpose

The purpose of this thesis is to explore the possibility of a dual purpose electric vehicle. The vehicle should be able to be used for both commuting and racing. It will examine different methods of power management to follow the above noted laws and regulations. Other aspects of this thesis will be the construction of a safe, user friendly vehicle prototype, while still providing adequate performance. The thesis hopes to examine the following questions:

• How do different power limiting methods affect performance?

• What methods of power limiting are possible?

• Are todays laws and regulations reasonable?

• How can a street-legal board be constructed?

1.3 Scope

Since the thesis is done within a limited time frame, a substantial part of the thesis was based on prior work.

• The motors, wireless transmitter/receiver, batteries, and battery charger have been purchased and used without modification.

• The speed controllers were purchased but have been configured.

• The hand controller was purchased but modified to follow the above noted regulations.

• The battery management system has not been implemented in the board.

• The deck has been constructed for this purpose, but the design and construc- tion was not fully documented.

• The lens system has been designed and constructed parallel to the work on the board, but is not documented.

1.4 Method

A carbon fiber composite deck was constructed for the purpose of this thesis. The deck allows for the different components to be fitted while being protected from the environment. An Arduino microcontroller was used to monitor the board and con- vert the signal from the hand controller to the motor drivers. A power management system was designed to safely offer power to the board’s different electrical systems. An LED matrix was used to provide feedback to the user. The completed board was used to test different power limiting methods and validate the concept.

2 Chapter 2

Theory

2.1 The longboard

A standard longboard’s components are: The deck- The deck is the actual board which the rest of the components are mounted to. This is the surface which the user interfaces with, to control the board. To improve traction between the user’s shoes and the board, a layer of griptape, a type of sand- paper, is commonly glued to the board [16]. See Figure 2.1.

Figure 2.1. A deck in red with the griptape in blue. Designed in Autodesk Fusion 360 rendered in Blender.

The trucks- The trucks are the connection between the wheels and the board. They are made of two major parts with connecting elements between. See Figure 2.2. The major parts are: The hanger that holds the axle and the baseplate, which is mounted to

3 CHAPTER 2. THEORY the board. Together the parts convert the leaning of the board to a twisting of the axles [17].

Figure 2.2. Exploded view of a truck. The hanger is marked blue, the connecting elements in red and the hanger in yellow. Made with Autodesk Fusion 360.

The wheels- The wheels are the connection between the vehicle and the road. Ball bearings are pressure fited into the hub of the wheel and a spacer can be used to lower the axial load on the bearings thus improving bearing life[18]. See Figure 2.3. Having bigger wheels make the board less susceptible to uneven terrain. The higher wheels can however add weight and raise the height of the board, making it more difficult for the user to reach the ground.

Figure 2.3. Exploded view of a wheel assembly. The wheel is blue, bearings red and the spacer yellow. Made with Autodesk Fusion 360.

4 2.2. PERMANENT MAGNET SYNCHRONOUS MOTOR AND SPEED CONTROLLERS 2.2 Permanent magnet synchronous motor and speed controllers

There are two major kinds of brushless permanent magnet synchronous motors (PMSM), brushless DC motors (BLDC motor) and brushless AC motors (BLAC). Unlike brushed motors these brushless motors need an electric controller, commonly known as an “electric speed controller” (ESC), to generate the alternating currents needed for each phase[19].

A synchronous motor is when the rotation of the magnetic field matches the ro- tation of the rotor. The motor can be run with or without feedback. Without feedback, the ESC has no way of knowing if the motor is spinning or how fast the motor is spinning. This makes motors without feedback very susceptible to stalling during changing loads. Stalling occurs when the rotation of the magnetic field falls out of sync with the rotation of the rotor, thus resulting in a loss of torque. With feedback, the ESC can continuously monitor the rotor’s position and thereby control the rotation of the magnetic field accordingly. Some methods of providing feedback are: Back EMF and Hall effect sensor [20].

Back EMF measures the voltage generated by the relative rotation between the magnetic field and the motor’s windings. This requires the motor to run as a gen- erator for a short time and will not work when the motor is stationary since no relative motion is present. Back EMF requires a more complex ESC to be able to monitor each phase’s voltage but can be used on any motor [21, 19]. This method may be called “sensorless” since no external sensors are needed.

The hall effect sensor method uses sensors placed around the motor’s periphery to accurately define the rotor’s position. The hall effect sensors measure the mag- netic field of the rotor’s magnets. This method needs at least one extra sensor with its own power to be able to tell the motor’s rotational frequency and there- fore speed. By placing several sensors with different spacing around the stator, a relatively precise position can be read. This solution gives high precision feedback which gives good low speed torque [22].

The major difference between the BLDC and BLAC motors are the back EMF generated when the motor is spun by an external force. The back EMF generated by the BLDC is trapezoidal, whereas the back EMF of the BLAC is sinusoidal. While a BLDC motor can be driven with a sinusoidal ESC the BLAC motor will have higher mechanical losses if run with a BLDC driver. Figure 2.4 shows the back EMF for both types of motors. The driver needed for BLDC are generally simpler and may be more efficient than the that of BLAC drivers [23]. While in theory the ideal BLDC and BLAC could have a constant torque the actual motors have some variation. In general the BLAC have a lower amount of torque variation leading to

5 CHAPTER 2. THEORY less noise while in operation [19, 24].

Figure 2.4. Back EMF for one phase in BLDC and BLAC motors. Drawn in Adobe Illustrator.

Since the motors can have more than one pole per winding, the motors may run at a different frequency, fmec, than that of the electric frequency, fel. The total amount of motor poles, p, will determine the ratio between the two frequencies [20].

fel · 2 f = (2.1) mec p

Further the rotational speed of the motor, ωmec will be a result of the electrical “rotational speed”, ωel. ωel · 2 ω = (2.2) mec p

A generalized equation for the mechanical output power, Pmec, of a BLAC motor is depending on the current, I, and mechanical efficiency cos ϕ [20]. A schematic can be seen in Figure 2.5. Pmec = 3 · Eph · I cos ϕ (2.3)

Here Eph is the back EMF generated by a phase for a certain rotational speed. This depends on the motor’s voltage constant ΨR [20].

Eph = ΨR · ωmec (2.4)

To measure the voltage constant the motor’s generated voltage must first be mea- sured. Without having the motor connected to anything but a multimeter between two phases, the generated voltage will be that of the back EMF since little to no current will go through the motor windings. For three phase sinusoidal machines the voltage between two phases Ub can de- scribed by the following formula. Further the formula for the voltage constant, ΨR, can be defined by the back EMF between two phases, Eb. √ Ub = 3Uph (2.5)

6 2.3. LONGBOARD DRIVE SYSTEMS

Figure 2.5. Simplified motor schematic. Drawn in Adobe Illustrator.

Eb ΨR = √ (2.6) 3 · ω

The variable cos ϕ is a result of the inductive voltage, ωel · LI, the restive voltage RI as well as the back EMF[20].

  ωel · LI  cos ϕ = cos arctan (2.7) RI + Eph

To calculate the resistance of each phase, R, the total resistance between two phases, Rtot, can be measured and divided.

Rtot R = (2.8) 2

Similarly, the inductance can be measured between two phases, Ltot, to calculate that of each phase L. Ltot L = (2.9) 2

2.3 Longboard drive systems

There are two major kinds of drive systems for electric longboards, in-wheel motors (hub motors) and external motors with pulley gearing. Geared drives such as those of Boosted Inc have the motors mounted parallel to the wheels with a smaller geared pulley on the motor and a bigger pulley on the wheel, see figure 2.6.

7 CHAPTER 2. THEORY

Figure 2.6. Geared drive system [1]. Motor in grey, pulleys highlighted in orange and belt highlighted in blue. Highlights drawn in Illustrator.

Hub motors are constructed with the motor built into the wheel. This significantly simplifies the mechanical construction of the board. The hub motor design is also less susceptible to dirt and water since the motor is within the wheels. Inboard Technology utilizes this in their board M1 [15]. The gearing of the geared drive can give a higher torque than the hub motors, thus giving better performance while braking and accelerating. While having higher torque, the gearing is reported to feel ”like riding an angry wild animal” [25] and may result in a lower top speed.

2.4 Battery technology

For electric vehicles, battery technologies with high specific energy and energy den- sity is preferable. Keeping the weight and size of the batteries down can lead to higher efficiencies due to lower frictional losses.

A battery is built up of one or more cells. Each cell has an EMF which varies depending on battery chemistry, charge, and other factors. For common lead acid batteries (Pb), the nominal voltage is 2.1V [3]. By combining six cells in series the whole battery will have a nominal voltage of 12.6V, this configuration is the stan- dard for car-starter batteries. While common, lead acid batteries do not possess optimal characteristics with relatively low specific energy and energy density. More modern battery technologies such as lithium-ion (Li-ion) and lithium-ion polymer (Li-Po) offer higher energy density, higher specific energy, and also higher specific power. Table 2.1 compares the technologies.

8 2.4. BATTERY TECHNOLOGY

C-rate is the safe rate of discharge depending on the battery’s maximum capacity [26]. It is described with this simple formula:

Discharge rate[A] = maximum capacity · C rating (2.10)

By placing batteries in series, the safe discharge rate is unchanged but the total

Table 2.1. Comparison between battery technologies [3, 4, 5]

Technology Nominal voltage Specific energy Energy density Specific power [V] [Wh/kg] [Wh/L] [W/kg] Pb 2.1 35-40 80-90 250 Li-ion 3.6 150-180 200-350 315-800 Li-Po 3.7 155 220 260 voltage will be increased. While placing the batteries in parallel will increase the safe discharge rate and the total power capacity.

Terminal voltage is the voltage of the battery when measured across the poles with a load applied. This voltage is strongly dependent on the load and on the battery’s internal resistance. A battery’s internal resistance is the major contributor to bat- tery losses.

A battery’s cutoff voltage is the voltage when the battery is considered “empty” [26]. Even though a battery might be at its cutoff voltage the battery may still have a significant charge. This when the load is high on a battery with high inter- nal resistance. The high current and high internal resistance will lower the battery’s terminal voltage leading to a lower measurable voltage [20]. Table 2.2 shows differ- ent cutoff voltages for different technologies.

Table 2.2. Recommended cutoff voltage for different technologies[6].

Recommended Li-ion/Li-Po Lead acid cut off voltage [V/cell] [V/cell] Normal load 3.0-3.3 1.75 Heavy load 2.7 1.4

The state of charge (SOC) is an expression of the battery’s current level of dis- charge: It is the remaining percentage of the maximum capacity. The opposite to SOC is depth of discharge (DOD), and indicates the percentage the battery has been discharged to. [20, 26].

9 CHAPTER 2. THEORY

While common lead acid batteries are relatively safe, some lithium-based battery technologies have tendencies to combust when improperly handled [27, 4]. In recent years stories about batteries catching fire have surfaced [28, 29]. The US Federal Aviation Administration has compiled a list of over 80 known accidents involving lithium-technology batteries [30]. To minimize the risks associated with Li-ion technology batteries a few points should be considered:

• The batteries are not supposed to be charged above 4.2V [31].

• The battery’s temperature should never exceed 90°C [31].

• The batteries should never be discharged at a rate higher than they are rated for [32].

Lastly, cycle life is the number of times a battery can be charged and discharged. The problem with the cycle life is that it is very dependent on level of discharge. A battery that is only discharged to 10% DOD may handle over a thousand cycles while a battery discharged to 90% DOD might only handle a hundred [20]. Figure 2.7 shows the relationship between DOD and cycle life for a lead acid battery, similar results can be expected for the modern battery technologies [33].

Figure 2.7. Expected cycle life corresponding to level of discharge [2].

10 2.5. PPM AND PWM

2.5 PPM and PWM

Pulse position modulation (PPM) and Pulse width modulation (PWM) are both methods of signaling analog data through a digital interface [20, 34]. Both methods are based on a set frequency but use different methods of signaling the data. PWM uses a differing signal length to define the analog value while PPM uses the position of the pulses to signal the analog value. Figure 2.8 shows the different signals. For common RC servos the frequency is 50Hz corresponding to period time of

Figure 2.8. PPM and PWM signals over time correlating to an analog value. Drawn in Adobe Illustrator.

20ms. A 2ms pulse represents a 100% value while 1.5ms pulse represents a neutral value (50%) and 1ms pulse a low value (0%) [35]. The two types of signals can be generated by an MCU either by “bit banging” or with signal generating hardware. Bit banging refers to the act of signal generation with software, this method is easy to implement but can be more computationally intensive and might be less stable.

11 Chapter 3

Demonstrator

The project has a list of goals which it has tried to reach. These goals are based on safety (following the above noted laws and regulations). The aim was also to create a prototype electric board with advanced user feedback functions and to make the ride as practical and comfortable as possible. These goals were (goals with an asterisk are required by law): • *Maximum speed (street mode): 20kmh, 5.56m/s.

• *Maximum continuous motor power (street mode): 250W.

• *The board must be able to brake at 3m/s2. The braking system should be functionally safe during normal operating conditions.

• *The board should have a parking brake that can keep the board stationary on a 15° incline, even without electrical power. This brake should not be a danger to the user if accidentally engaged.

• *The board should have white lights forward and red lights backwards that can be clearly seen from 300m. The lights cannot be blinding or must be able to be dimmed quickly.

• *The board should have an audible warning device (AW-dev).

• The board should be able to monitor the batteries to allow safe usage.

• The board should be able to run at full power (street mode) for at least half an hour.

• The board’s components should be protected from the environment.

3.1 The system

The board has several components that all need to work together for the board to function properly. Figure 3.1 shows how these components work together.

12 3.1. THE SYSTEM

Figure 3.1. System diagram. The orange lines are data and black, power. Drawn in Adobe Illustrator.

The components are grouped into four subsystems:

Logic – Lighting, sensors, LED matrix, and MCU. The logic monitors and pro- vides feedback to the user. It also controls the mode, converts the signal for correct power output, and turns off/on the lights.

Driveline – Motors, batteries, parking brake, power distribution, and ESC. The driveline is responsible for the propulsion of the board.

Control – Controller and receiver. The control has to be easy and comfortable to use while providing exact control signals.

Structure – Deck, trucks, wheels, lids, and lenses. The structure is the base which the rest is assembled on. It protects the components from the environment. It also incorporates the lenses that protect the LED circuit boards while directing the light.

13 CHAPTER 3. DEMONSTRATOR

3.2 Logic

3.2.1 Lighting To minimize the number of components needed for the board, an module was de- signed for use as both headlight and taillight. A Texas Instruments TL4242 ad- justable LED driver was used. The driver can directly control a series of LEDs with a PWM signal. For the actual LEDs Osram’s OSLON® series LEDs were chosen. The specific number and characteristics of the chosen LEDs can be found in table 3.1.

Table 3.1. Used LEDs characteristics [7, 8]

For use Color Serial number Forward voltage Forward current VF [V] IF [mA] Headlight White GW CS8PM1.PM 2.85 350 Taillight Red LJ CKBP-JZKZ-25 2.15 350

The PCB can be seen in Figure 3.2. See Appendix E for the circuit board’s layout and schematic.

The LED driver uses a resistor in series with the LEDs to monitor the current. The formula to determinate the current out of the driver, Iout, relies on the internal reference voltage, Vref and the resistor’s value, Rref [36].

Vref Iout = (3.1) Rref ⇓

Vref Rref = (3.2) Iout The TL4242’s internal voltage is typically 177mV and both types of LEDs need a forward current of 350mA. 177 Rref = = 506mΩ (3.3) 350 Since 506mΩ is an uncommon value a 510mohm resistor was used. The current is therefore, according to 3.1: 177 Iout = = 347mA (3.4) 510

The power dissipated by the resistor, PRdis, is:

2 2 PR dis = Iout · Rref = 0.347 · 0.51 = 0.061W (3.5)

14 3.2. LOGIC

To minimize the power dissipated by the driver, PD dis the driver is connected to one battery giving an maximum input voltage, Vin, of 21V.

The forward voltage of the series of LEDs has to be less than the input voltage. For the red taillight eight LEDs are used. For the white LEDs six in series are used and two LEDs positions are bypassed, this is done with a ”solder jumper” on the board. Since the driver provides a constant current the number of LEDs does not affect the current over each LED. The white and the red LED have forward voltages of 17.1V and 17.2V respectively.

Figure 3.2. Light module PCB. Made with Adobe Illustrator and Autodesk Eagle.

3.2.2 Sensors To monitor the batteries a simple voltage divider board was constructed. The volt- age divider is connected to six of the batteries’ cells. The voltage dividers convert the high voltage of the battery cells to a predictable lower voltage, which can be safely measured with an MCU. See Appendix G for the voltage divider’s circuit board’s layout and schematic.

Originally digital temperature probes were supposed to monitor battery and motor temperatures, this proved hard to implement with a single MCU and was therefore omitted.

3.2.3 LED matrix An 8x8 RGB LED matrix was chosen to provide feedback to user. The matrix is an Adafruit design rebranded as Luxorparts [37, 38]. All LEDs are individually addressable which makes it possible to show graphics and text. Since the used MCU lacks the needed protocol a “bit-banging” approach is used. This however limits matrix updates to times when the board is stationary. Each LED can use up to 60mA. The maximum total consumption is just under 4A [39]. The LED matrix showing ”cell error” can be seen in Appendix I.

3.2.4 MCU The MCU used in the board is an Arduino mega 2560. It was chosen for its relatively large usable flash memory of 248KB [40]. It also provides more than enough outputs and inputs.

15 CHAPTER 3. DEMONSTRATOR

3.3 Driveline

3.3.1 Motors To validate that the motors would be able to brake with enough force, the required 2 force was determined. With a retardation, aret, of 3 m/ an 80 kg user, musr, would need a braking force according to this equation:

Fbrake = musr · aret = 80 · 3 = 160N (3.6)

Further the braking effect, Pbrake, is dependent of the speed, v. It is the highest at the maximum speed. The highest needed braking effect is therefore:

Pbrake = Fbrake · V = 160 · 5.56 = 880W (3.7)

Two MTO9055-HBM-60-HA hub motors from Chinese Maytech Electronics Co, Ltd were chosen. The hub motors were chosen for their simplicity and large diameter. They also have hall effect sensors built in. The motors are 90 mm in diameter and have a rated power of 800 W which gives a total power of 1600 W. A rendering of the motor can be seen in Figure 3.3. The motors are also rated for 22 A and 36 V. Their voltage constant is ΨR = 1/60 V/rpm , 1/2π (V s)/rad [41].

Disassembly found that the motor has 24 poles. The ratio between the electrical ro- tational speed and mechanical rotational speed is therefore according to formula 2.2

ωmech 1 = (3.8) ωel 6

Figure 3.3. Render of Maytechs 90 mm hub motor. Made with Autodesk Fusion 360.

16 3.3. DRIVELINE

For a top speed of 20kmh (5.56m/s) the wheel and motor has to rotate at a rotational speed of 123.5 rad/s and the electrical field at 370.5 rad/s. The motor’s EMF at the top speed is according to equation 2.4 1 E = · 123.5 = 19.66V (3.9) ph π Measurements on the motor found that the winding resistance R is 62.5mΩ and the inductance L is 13.8µH. With all needed variables known, the factor cos ϕ could be calculated according to formula 2.7. A current of 22A is assumed.

  370.5 · 13.8 · 10−6 · 22  cos ϕ = cos arctan = 0.999986 (3.10) 62, 5 · 10−3 · 22 + 19.66

This proves the high efficiency of the motors with almost all electric power converted into mechanical effect. This also means that the continuous electric power may not exceed 250W as required by the law.

17 CHAPTER 3. DEMONSTRATOR

3.3.2 Batteries To keep the scope of the project within the time constraints, commercially available hobby RC Li-Po batteries have been used.

The maximum continuous power at street mode is 250W. For half an hour the total power consumption, W h1h, comes to 125Wh. A 10-cell battery was chosen for its nominal voltage of 37V. To keep the batteries’ cycle life high, an maximum discharge of 80% is allowed.

The batteries’ energy content, W h, is calculated by using the maximum allowed discharge. To calculate the required capacity, Ah1h, the highest nominal battery voltage was used: W h W heff = = 156.25Wh (3.11) 0.8 W h 156.25 Ah0.5h = = = 4.22Ah (3.12) Vnom 37 Since Li-Po batteries are only available in some common configurations the final battery pack was based upon one of these. Hong Kong based Hobbyking was used as a source of configurations. A safe discharge rate of 20C is assumed. Table 3.2 has some possible configurations, based both on available batteries and the calculated cell count and capacity. The batteries have to be charged individually and have to fit within the board.

Table 3.2. Possible battery configurations [9].

In se- In Cells per Capacity Total Total Total Total ries paral- battery per bat- capac- current energy amount of lel tery ity capacity batteries 2 1 5 5.0Ah 5.0Ah 100A 185Wh 2 2 2 5 3.0Ah 6.0Ah 100A 222Wh 4 5 1 2 5.0Ah 5.0Ah 100A 185Wh 5 5 2 2 3.0Ah 6.0Ah 120A 222Wh 10

The two-battery configuration was chosen. Due to availability 25C batteries were purchased, giving an maximum safe discharge rate of 125A.

18 3.3. DRIVELINE

3.3.3 Parking brake

The major technical challenge with the parking brake was how the brake should engage. If constructed incorrectly the brake might accidently stop the board while at speed. If this happens quickly the user can be thrown off the board.

A servo was chosen to actuate a small metallic wire. The wire interlocks in one of the front wheel’s hub, this locks the wheel and immobilizes the board. See Fig- ure 3.4. An image of the parking brake can be found in Appendix I.

Figure 3.4. Cutaway drawing of the parking brake assembly. Servo arm in green, the metal wire in blue and wire guide in red. Made with Autodesk Fusion 360 and Adobe Photoshop.

While the wire is dimensioned to lock the wheel when stationary the wire is soft enough to be bent if actuated while the board is moving.

3.3.4 Power distribution

The board has two different power systems since several components utilize a lower voltage than the motor system. A power distribution was made to safely distribute the power and convert the high voltage from the batteries to the lower voltage suit- able for some of the board’s components. The structure is shown in Figure 3.5.

19 CHAPTER 3. DEMONSTRATOR

Figure 3.5. Diagram of the board’s two voltage systems. Drawn in Adobe Illustra- tor.

Originally an IC was chosen to convert the voltage, but was ommited due to a thec- nical mishap. Two converter modules were purchased, connected, and calibrated for the 5V needed for the low voltage components. These modules are capable of converting up to 3A each [42].

Even though the batteries can handle up to 100A continuous discharge the board should not be able to consume that much. A high voltage automotive 50A fuse is implemented on the power distribution board. A kill switch strap is also imple- mented, by pulling a cord the user can quickly cut the power to the ESC’s. See Appendix F for the power distribution board’s layout and schematic.

3.3.5 ESC Benjamin Vedder’s VESC was chosen for its availability and ease of use. One was used per motor. Each VESC is specified for a continuous power output of 50A at 60V [43]. The VESC has several different methods for controling, monitoring, and powering the motor. The control and power methods were configured using the VESC Tool software [44].

The control methods are:

PID Speed – The controller simply sets the desired speed and the ESC tries to match it.

Current – The controller sets the desired current.

Duty cycle – The controller sets the desired switching duty cycle, the higher the duty cycle the higher the voltage.

20 3.4. CONTROL

Early tests demonstrated the current control method most intuitive. Both PID speed control and duty cycle control would accelerate quickly and then freewheel, jolting the user, back and forwards. While this can be fixed by changing ramping variables, these control methods provided no overwhelming advantage over cur- rent control. Current control gives a similar experience to an accelerator and brake, needing a little extra input to get the board going and to hold the speed going uphill.

The power methods are:

BLDC – As noted in section 2.2 this method powers the motor as a BLDC.

FOC – Stands for “Field Orientation Control” this method powers the motor as a BLAC.

DC – This method is for DC motors and is therefore not applicable. The chosen motors had a sinusoidal back EMF, therefore the FOC setting was cho- sen. Tests with BLDC settings resulted in much louder electrical noise from the motors.

For FOC the possible monitoring methods are:

Sensorless – As described in section 2.2.

Hall Sensors – As described in section 2.2.

Encoder – For external encoders.

Since the motors already have built-in Hall effect sensors, this method was used. VESC Tool software has a built-in detection mode that was used to find the posi- tions of the hall effect sensors. The rest of the settings were set up according to the motors’ and batteries’ specifications.

3.4 Control

3.4.1 Hand controller and receiver To control the board, a controller and receiver was needed. Maytech’s MTSKR1712 receiver/controller combination was chosen. It utilizes two-way 4GHz communica- tion between the controller and receiver and swaps channel automatically to mini- mize the risk of interference [45]. The signal that the receiver sends was found to be a PWM signal. The VESC was therefore configured in PPM mode (which accepts PWM signals) to properly receive the signal.

21 CHAPTER 3. DEMONSTRATOR

By moving a spring-loaded lever back or forth the user can control the board. Pressing the lever forward the board accelerates. Letting the lever spring back to center lets the board roll freely and pulling the lever backwards applies the brakes. The signal is analog. This means that the user can set the level at which the board would accelerate/brake.

Since an AW-dev was needed, a buzzer with internal oscillator was purchased. The buzzer, Mallory MSO206NR, works with voltages between 2 and 6V [46]. A sim- ple circuit board connects the buzzer directly to the battery with a push-button to activate the buzzer. See Appendix H for the buzzer circuit board’s layout and schematic. Since the included battery is quite small an 18650 cell was added to improve the controller’s battery life.

To fit all the parts within the controller a new 3D-printed shell was designed. An exploded view of the controller design can be seen in Figure 3.6. See Appendix J for images of the hand controller. See Appendix K for a 3D model of the handcon- troller.

Figure 3.6. Exploded view of the hand controller. The 3D-printed shell is in blue, the 18650-battery in pink, the controller circuit board in grey and black, the buzzer circuit board in green and the buzzer is the black hexagon. Made with Autodesk Fusion 360.

22 3.5. STRUCTURE

3.5 Structure

3.5.1 The Deck Since the board has multiple components that need to be housed and protected from the environment, a custom deck was designed and built. The board has three main compartments, one for each battery and one for the main electronics. The compartments are shown in Figure 3.7. The deck utilizes modern materials and

Figure 3.7. Placement of the three compartments. Battery compartments in blue and the main compartment in orange. Drawn in Adobe Illustrator construction methods to keep the weight low. The deck’s structure is shown in Figure 3.8. Note how the printed parts mesh with the foam through dovetail joints. See Appendix L for a simplified 3D model of the board. See Appendix I for images of the completed board. The whole board without any components weighs about 2000g this is comparable to similarly wooden sized boards [47].

The board also has mounts and electrical conduits to allow the headlights and taillights to be mounted at the front/back of the board. On the right side of the board a 3D-printed holder for the kill switch cord is present.

To allow the LED matrix to be seen, a patch on the top of the board has been constructed in translucent materials. See Appendix I for images of the matrix lit through the board.

23 CHAPTER 3. DEMONSTRATOR

Figure 3.8. Exploded view of the deck’s structure. Made with blender and Adobe Illustrator

24 3.5. STRUCTURE

3.5.2 Trucks and wheels To allow the back wheels (motors) to be mounted, a special truck was needed. Normal trucks are designed to let the wheels spin freely while the motors need to have the stator locked. Maytech MTSKT1614B that lock the stators was used for the back truck and Maytech MTSKT1614F for the front. For the front wheels Maytech MTSKW1614 were chosen to match the diameter of the back wheels.

3.5.3 Lids Two lids were made, one to cover and hold the batteries and one to cover the electronics. The lid that covers the electronics also has momentary push button with a LED built-in. A render of the electronics lid can be seen in Figure 3.9. They were made by vacuum forming, a process where a heated plastic sheet is pulled down on a form using vacuum. The sheet is allowed to cool and harden. Then the excess plastic is removed.

Figure 3.9. Render of the main lid. The push-button is seen as black and red on the top of the lid. Made in Autodesk fusion 360.

25 CHAPTER 3. DEMONSTRATOR

3.5.4 Lenses Two lenses were designed and constructed out of a transparent plastic. They incor- porate simple spherical lenses to direct the light. A render of the front lens can be seen in Figure 3.10.

Figure 3.10. Render of the front lens. Note the 6 divots for the LED. Designed in Autodesk Fusion 360 rendered in blender.

3.6 Software

The final part of the board was the software. The software is responsible of con- trolling the lights, LED matrix, parking brake, monitoring the batteries and con- trolling/monitoring the board’s power output.

To read the signal from the receiver, the MCU utilizes a simple interrupt func- tion. When the PWM signal changes state, e.g. goes from a low to a high voltage, a timer starts. Next time the signal changes the timer stops. The time taken is the length of the pulse and therefore proportional to the analog signal value. To send the signal to the VESCs, the MCU simply sends a high pulse with a corresponding length to the desired throttle/power output.

Switching between modes is done by pressing and holding the push-button while connecting the battery, this is to minimize the risk of changing modes unintention- ally. While in “Race mode” the LED matrix displays a checkered race flag symbol.

In the “Race mode” the board simply forwards the in-signal to the ESCs, this is called “Normal throttle” since no conversion occurs.

During “Street mode” the MCU checks the in-signal and, depending what mode the throttle is in, it goes in to one of three functions. If the in-signal is outside a specified value range the LED matrix displays an error symbol.

26 3.6. SOFTWARE

If the throttle is neutral the board runs a “Neutral function”. If the throttle is left in neutral position for a set number of cycles the board enters into monitoring mode. This is only done in “Street mode”. During monitoring mode, the board checks the battery voltages. If a cell is outside the normal voltage range the matrix shows an error symbol indicating which cell. All error symbols can be found in Appendix I.

If the throttle is less than neutral the MCU runs the “Brake function”, in this function the board forwards the in-signal to the ESCs.

Lastly if the throttle is forward the MCU runs the “Power check functions”, these functions monitor and controls the board’s power continuously. The monitoring of the power output is done by the MCU communicating with one VESC.

Four power control methods were tested:

Simple power limiting – here each VESC was set for a maximum power out- put of 125W. This was done with the board in “Race mode”.

Running average cutoff - here the Arduino monitored the board’s output and cut off the power if the running average exceeded 250W. The function’s flowchart can be seen in Figure 3.11.

Running average - here the Arduino monitored the board’s power and limited the power if the running average exceeded 250W. The function’s flowchart can be seen in Figure 3.12.

Average - here the Arduino monitored the board’s power and limited the power if the average over a certain period exceeded 250W. The function’s flowchart can be seen in Figure 3.13.

Turning on and off the lights is done by pressing the push-button after startup. When the throttle is set to brake, the taillight turns on or is set to a higher level to indicate that the board is applying its brakes.

The flowchart of the main program is Figure 3.15 and the push-buttons interrupt function flowchart is Figure 3.14.

The code was written as two files, one with the main program and functions and one with the variables needed. See Appendix A for the code.

27 CHAPTER 3. DEMONSTRATOR

Figure 3.11. Flowchart for the ”Running average cutoff” function. Made with draw.io and Adobe Illustrator.

Figure 3.12. Flowchart for the ”Running average cutoff” function. Made with draw.io and Adobe Illustrator.

28 3.6. SOFTWARE

Figure 3.13. Flowchart for the ”Average” function. Made with draw.io and Adobe Illustrator.

Figure 3.14. Flowchart for the push-button interrupt function that changes between light states. Made with draw.io and Adobe Illustrator.

29 CHAPTER 3. DEMONSTRATOR

Figure 3.15. Program main flowchart. Made with draw.io and Adobe Illustrator

30 Chapter 4

Experiments

To compare the power control methods and verify the prototype board a few ex- periments were conducted.

4.1 Acceleration and retardation test

To test the different power control methods the board was tested over an 80m stretch. A 65kg rider started from standstill. The rider began by setting the control to fully forward, and then set the control to full brake to stop at the 80m mark. This was done at least 4 times per mode alternating direction each time. A cellphone with a K6DS3TR Acceleration Sensor was held horizontal during the test. The acceleration data was logged. Lastly the data for acceleration in the horizontal plane was calculated and filtered in Matlab. See Appendix C for the Matlab code.

4.2 Range test

The board was used twice for commutes. The distance and time were logged. At the end of the ride the batteries voltages were written down. Also, the elevation gain and loss were noted. From the battery voltages an estimate of the used energy was made. This combined with the time made calculation of the average power consumption possible.

4.3 Light pattern measurements

The board’s headlight/taillight was placed 600mm from a flat wall. A measuring pattern was drawn on the wall. The measurement pattern has 9 points, both on the vertical and horizontal axis as well as above the horizontal axis. The measuring pattern can be seen in Figure 4.1. The lights were turned on at a known strength. A cellphone with an AMS AG TMD49XX RGB sensor was used to measure the illuminance at each point. The test was repeated with Lezyne Hecto Drive 300XL

31 CHAPTER 4. EXPERIMENTS bicycle headlight and a Lezyne Strip Drive bicycle taillight. Lastly the data was loaded into Matlab and the whole field was interpolated using a cubic method.

Figure 4.1. Test pattern for the lights. Drawn in Adobe Illustrator.

4.4 Light strength test

A straight piece of road was used to measure at which point the lights could not be seen. The board’s lights were set to 25% and then 100%. The board’s were run in both directions and as far as could be seen.

4.5 Parking brake test

A simple servo actuation program was uploaded to the MCU. The board was placed on an MDF sheet with the parking brake applied. One edge of the sheet was slowly lifted and when the board started moving the angle was noted. The failure mode was also noted: sliding or mechanical failure. The tests were done twice, initially with the board’s direction facing the top of the sheet and a second time with the board’s direction facing down. The test was repeated with the grip tape facing down onto the MDF sheet.

32 Chapter 5

Findings

5.1 Acceleration and retardation

Only one result per mode is shown in Table 5.1. See Appendix B for all the accel- eration graphs.

The acceleration and retardation tests showed that the “Simple power limiting” and “Average” control methods were the fastest to cover the 80m. Both the “Run- ning average” methods proved to have jerky acceleration where the board would accelerate intermittently. “Simple power limiting” method was the quickest. While data shows that the board decelerated at a rate of above 3.0m/s2 during most tests, the slower tests did not reach this retardation goal.

33 CHAPTER 5. FINDINGS

Table 5.1. Acceleration data from the different power modes.

Simple power limiting: Running average cutoff:

Running average: Average:

34 5.2. RANGE

5.2 Range

The result of the two tests are shown in Table 5.2. Some things were noted during the range tests: During hill climbs and when going against the wind the board needed more throttle input. During the first ride the parking brake got accidently applied while moving. While the wire, described in section 3.3.3, went into the wheel it did not lock the wheel, instead it bent as supposed, allowing it to be bent straight later.

Table 5.2. Noted data from the range test.

Ride # Length Time Climb Battery Battery Used Average [km] [min] and Fall 1 [V] 2 [V] battery power con- [m] power sumption [Wh] [W] 1 8.5 34 52/54 18.5 19.0 ˜95 ˜170 2 14.5 53 111/123 14.2 17.7 ˜150 ˜175

35 CHAPTER 5. FINDINGS

5.3 Light pattern

The interpolated data is shown in Figures 5.1 to 5.4. The actual measurements are shown in the Matlab code as Appendix D.

Figure 5.1. Measured light pattern for the board’s headlight, generated in Matlab.

Figure 5.2. Measured light pattern for the board’s taillight, generated in Matlab.

36 5.3. LIGHT PATTERN

Figure 5.3. Measured light pattern for Lezyne Hecto Drive 300XL, generated in Matlab.

Figure 5.4. Measured light pattern for Lezyne Strip Drive, generated in Matlab.

The test shows that the bicycle headlight has a more condensed light pattern and that the bicycle provides more light straight forward. The light from the taillight of the board is instead more condensed and brighter than that of the bicycle light.

37 CHAPTER 5. FINDINGS

5.4 Light strength

The light range test showed that the board can be seen with 25% or 100% light intensity from over 850m. This is beyond the required distance of 300m. At 100% light intensity the light was blinding but at 25% the blinding was minimal.

5.5 Parking brake

The noted data from the parking brake test can be seen in table 5.3.

Table 5.3. Measured angles and failures for the parking brake tests.

Test Angle [°] Failure Board facing up, uphill 5.2 Bent wire Board facing up, downhill 5.5 Bent wire Board facing down, uphill 20.7 Sliding Board facing down, downhill 23.1 Sliding

38 Chapter 6

Discussion and conclusion

6.1 Discussion

The biggest challenge with the construction was fitting all the board’s components. While the final board can house everything, working on the board leaves a lot to be desired in terms of space. The lids’ ability to keep dust out of the compartments was underwhelming.

The numbers read from the VESC did not match the ones read from the VESC Tool. The implemented fix was a simple converting factor that was calculated from a few readings, this combined with the slow sampling rate might give inaccurate values. By only looking at the power output of one VESC, the power output may over/undershot the allowed power.

For the acceleration/retardation tests the user’s ability to hold the cellphone stable may have influenced the results. If the cellphone was not completely horizontal the earth’s gravitational acceleration may have raised the calculated acceleration. This may have contributed to the variations between tests. The stopping point was not always perfect. This along with human reaction times can have influenced the measured time for each test. The lower retardation rate at lower speeds is probably a result of the motors’ not being able to generate the same amount of power. This is because of the lower generated voltage.

Since the legal power output is so low, electric vehicle companies might not want to include stronger motors, this would hinder the vehicle’s performance. If the motor power is too low the vehicle cannot use EMF to brake and would have to rely on mechanical brakes. Mechanical brakes add to the amount of particulates in the air which can be a health concern [48].

While the range tests monitored the final battery voltages, continuous monitor- ing would be desired. Climbing hills and going against the wind seemed to use a lot

39 CHAPTER 6. DISCUSSION AND CONCLUSION more current and therefore power, but without continuous monitoring, it is hard to confirm. Calculating used energy from the battery voltages is not the most exact way of monitoring the used energy. The VESC has built-in energy drawn monitor- ing but this was not read after the tests.

While the monitoring of the power output worked, the rate at which it did was quite slow. This may have contributed for the overshoots during the “running av- erage” and “running average cutoff” tests.

For the light tests, more test points might give a better picture over the total light pattern, specially more points under the horizontal axis. The parking brake tests would probably be different on different surfaces. The law requiring a mechan- ical parking brake seems unnecessary for a vehicle of this size and weight. For the acceleration and light pattern tests, purpose-built sensors might have given more accurate readings.

6.2 Conclusion

From the list of personal goals this is what was achieved:

• Maximum speed (street mode): 20kmh, 5.56m/s. Not implemented, however the average speed of both commutes were under this limit.

• Maximum continuous motor power (street mode): 250w. Implemented and working.

• The board must be able to brake at 3m/s2. The braking system should be functionally safe during normal operating conditions. Worked at higher speeds.

• The board should have a parking brake that can keeps the board stationary on a 15° incline, even without electrical power. This brake should not be a danger to the user if accidentally engaged. The parking brake was not able to hold the board. Flipping the board over proved more than adequate.

• The board should have white lights forward and red lights backwards that can be clearly seen from 300m. The lights cannot be blinding or must be able to be dimmed quickly. Implemented and working.

• The board should have an audible warning device (AW-dev). Implemented and working.

40 6.2. CONCLUSION

• The board should be able to monitor the batteries to allow safe usage. Partially implemented.

• The board should be able to run at full power (street mode) for at least half an hour. Technically possible more tests needed.

• The board’s components have to be protected from the environment. Needs improvement.

The project has shown several possibilities for a street-legal longboard. It shows the possibility of a dual-purpose vehicles and provides a method of giving feedback to the user. It shows that the law as it is written today is reasonable but could be improved for different sizes and types of vehicles.

41 Chapter 7

Further work

For further work a dual MCU system could be implemented, where one would han- dle the monitoring and feedback and one the power output. Having two MCUs could allow for continuous monitoring of the batteries voltages and temperatures. With more time a PID control method could be implemented, this might improve the jerkiness of “running average” control method.

An ambient light sensor could be implemented to control the brightness of the head and taillights. Adaptive brightness can minimize the risk of blinding and im- prove visibility and battery life.

Test on the board with purpose-built accelerometers could probably differentiate better between the different control modes.

The system can relatively easily be converted for other wheeled vehicles without swapping any components. By placing the motors(wheels) against one or several bigger wheels on a vehicle, the periphery force and speed would be the same, thus providing similar performance.

42 Bibliography

[1] Boosted Boards, “Electric skateboard — Boosted boards.” [Online]. Available: https://boostedboards.com/

[2] Woodbank Communications, “Electropaedia, Energy Sources and Storage and History of Technology.” [Online]. Available: http://www.mpoweruk.com/ index.htm

[3] T. Crompton, Battery reference book, 3rd ed. Linacre House Jordan Hill, Oxford, United Kingdom: Newnes, 2000.

[4] G. J. May, A. Davidson, and B. Monahov, “Lead batteries for utility energy storage: A review,” feb 2018. [Online]. Available: https: //www.sciencedirect.com/science/article/pii/S2352152X17304437

[5] I. Buchmann, “Basic to Advanced Battery Information from Battery University,” 2018. [Online]. Available: http://batteryuniversity.com/

[6] ——, “Battery Discharge Methods – Battery University,” 2018. [Online]. Available: http://batteryuniversity.com/learn/article/discharge methods

[7] OSRAM, “OSLON SSL 80 GW CS8PM1.PM — OSRAM OS.” [Online]. Available: https://dammedia.osram.info/media/resource/hires/ osram-dam-5537590/GWCS8PM1.PM EN.pdf

[8] ——, “OSLON Signal LJ CKBP — OSRAM OS.” [On- line]. Available: https://dammedia.osram.info/media/resource/hires/ osram-dam-2493850/LJCKBP EN.pdf

[9] “Hobbyking.com,” 2018. [Online]. Available: https://hobbyking.com/

[10] L. Garfield, “Cities are going car-free around the world - Busi- ness Insider,” 2017. [Online]. Available: http://www.businessinsider.com/ cities-going-car-free-2017-2?r=US&IR=T

[11] Regeringskansliet, “Regeringen ger besked om milj¨ozoner.” [On- line]. Available: http://www.regeringen.se/pressmeddelanden/2018/03/ regeringen-ger-besked-om-miljozoner/

43 BIBLIOGRAPHY

[12] Transportstyrelsen, “Nya milj¨ozoner kan ge renare luft i st¨aderna,” 2018. [Online]. Available: https://www.transportstyrelsen.se/sv/Press/ Pressmeddelanden/nya-miljozoner-kan-ge-renare-luft-i-staderna/

[13] Sveriges Riksdag, “Lag (2001:559) om v¨agtrafikdefinitioner Svensk f¨orfat- tningssamling 2001:2001:559 t.o.m. SFS 2017:360 - Riksdagen.” [On- line]. Available: https://www.riksdagen.se/sv/dokument-lagar/dokument/ svensk-forfattningssamling/lag-2001559-om-vagtrafikdefinitioner sfs-2001-559

[14] Transportstyrelsen, “Transportstyrelsens f¨oreskrifterom cyklar, h¨astfordonoch sparkst¨ottingar,”2010. [Online]. Available: https://www.transportstyrelsen. se/TSFS/TSFS2009 31k.pdf

[15] Inboard technology, “Inboard Technology - M1 Premium Electric Skateboard.” [Online]. Available: https://www.inboardtechnology.com/

[16] S. Gordon, “Composite sports board such as a skateboard deck,” Patent, dec, 2003. [Online]. Available: https://patents.google.com/patent/US6648363B2/

[17] L. W. Docter, “Skateboard / longboard truck with improved mechanical advantage,” Patent, nov, 2014. [Online]. Available: https://patents.google. com/patent/US9199158

[18] SKF, “Loads calculations for roller bearings.” [Online]. Available: http://www.skf.com/uk/products/bearings-units-housings/ engineered-products/insocoat-bearings/loads/index.html

[19] H. Duane C, Brushless permanent magnet motor design, 2nd ed. Orono, ME: Magna Physics Publishing, 2006.

[20] P.-E. Lindahl, R. Meyer, H. Johansson, H. Grimheden, W. Sandqvist, and M. Paulson, Elektroteknik, 2013th ed., M. Paulson, Ed. Stockholm: Institu- tionen f¨ormaskinkonstruktion, Tekniska h¨ogsk., 2013.

[21] Acroname, “Back-EMF Motion Feedback blog post — Acron- ame,” 2011. [Online]. Available: https://acroname.com/blog/ back-emf-motion-feedback-blog-post

[22] P. Yedamale, “Brushless DC motor Fundamentals,” Chandler, AZ, Tech. Rep., 2003. [Online]. Available: http://ww1.microchip.com/downloads/en/ AppNotes/00885a.pdf

[23] M. Miyamasu and K. Akatsu, “Efficiency comparison between Brushless dc motor and Brushless AC motor considering driving method and machine design,” in IECON Proceedings (Industrial Electronics Conference). IEEE, nov 2011. [Online]. Available: http://ieeexplore.ieee.org/document/6119584/

44 BIBLIOGRAPHY

[24] K. Y. Nam, W. T. Lee, C. M. Lee, and J. P. Hong, “Reducing torque ripple of brushless DC motor by varying input voltage,” in IEEE Transactions on Magnetics, vol. 42, no. 4, apr 2006. [Online]. Available: http://ieeexplore.ieee.org/document/1608454/

[25] The Verge, “Inboard M1 electric skateboard review - YouTube.” [Online]. Available: https://www.youtube.com/watch?v=p6WkoK0zJJM

[26] MIT Electric Vehilce Team, “A Guide to Understanding Bat- tery Specifications,” Current, no. December, 2008. [Online]. Available: http://web.mit.edu/evt/summary battery specifications.pdf

[27] Concordia University, “Lead Acid Batteries,” 2005. [Online]. Avail- able: https://www.concordia.ca/content/dam/concordia/services/safety/ docs/EHS-DOC-146 LeadAcidBatteries.pdf

[28] T. Moynihan, “Why Lithium Ion Batteries Keep Exploding — WIRED,” 2017. [Online]. Available: https://www.wired.com/2017/03/ dont-blame-batteries-every-lithium-ion-explosion/

[29] M. Swider, “Here’s why the Samsung Galaxy Note 7 batteries caught fire and exploded — TechRadar,” 2017. [Online]. Available: https://www.techradar. com/news/samsung-galaxy-note-7-battery-fires-heres-why-they-exploded

[30] Federal Aviation Administration, “LITHIUM BATTERIES & LITHIUM BATTERY-POWERED DEVICES Aviation Cargo and Passenger Bag- gage Events Involving Smoke , Fire , Extreme Heat or Explosion Involving Lithium Batteries or Unknown Battery Types,” 2016. [On- line]. Available: https://www.faa.gov/about/office org/headquarters offices/ ash/ash programs/hazmat/aircarrier info/media/Battery incident chart.pdf

[31] I. Buchmann, “BU-304b: Making Lithium-ion Safe – Battery Uni- versity.” [Online]. Available: http://batteryuniversity.com/learn/article/ bu 304b making lithium ion safe

[32] ——, “Calculating the Battery Runtime - Battery University,” 2018. [Online]. Available: http://batteryuniversity.com/learn/article/discharge characteristics li

[33] C. Chan and K. Chau, Modern electric vehicle technology. Great Clarendon Street, Oxford, OX2 6DP, United Kingdom: oxford university press, 2001. [Online]. Available: https://global.oup.com/academic/product/ modern-electric-vehicle-technology-9780198504160?cc=se&lang=en&

[34] Y. Fujiwara, “Self-synchronizing pulse position modulation with error tolerance,” IEEE Transactions on Information Theory, vol. 59, no. 9, jan 2013. [Online]. Available: https://arxiv.org/abs/1301.3369

45 BIBLIOGRAPHY

[35] J. Mal´aˇsek, “Pololu - Servo control interface in detail.” [Online]. Available: https://www.pololu.com/blog/17/servo-control-interface-in-detail

[36] Texas Instruments Incorporated, “TL4242 Adjustable LED Driver — TI.com.” [Online]. Available: http://www.ti.com/product/TL4242

[37] Adafruit, “Adafruit-NeoPixel-8x8-Matrix.” [Online]. Available: https://github. com/adafruit/Adafruit-NeoPixel-8x8-Matrix

[38] Kjell & Company, “Luxorparts Adresserbar RGB LED-matris 64x LED.” [Online]. Available: https://www.kjell.com/se/sortiment/el-verktyg/arduino/ tillbehor/luxorparts-adresserbar-rgb-led-matris-64x-led-p90767

[39] Adafruit, “Adafruit NeoPixel NeoMatrix 8x8 - 64 RGB LED Pixel Matrix.” [Online]. Available: https://www.adafruit.com/product/1487

[40] Arduino, “Arduino Mega 2560 Rev3.” [Online]. Available: https://store. arduino.cc/arduino-mega-2560-rev3

[41] Maytech, “MTO9055-HBM-60-HA hub motor,” 2015. [Online]. Available: http://www.maytech.cn/en/mto91hbm-nh/8803.html

[42] Kjell & Company, “Luxorparts Variabel mini-sp¨anningsreg- ulator Switchad - Str¨omf¨ors¨orjning.” [Online]. Available: https://www.kjell.com/se/sortiment/el-verktyg/arduino/stromforsorjning/ luxorparts-variabel-mini-spanningsregulator-switchad-p90771

[43] B. Vedder, “VESC – Open Source ESC — Benjamin’s robotics.” [Online]. Available: http://vedder.se/2015/01/vesc-open-source-esc/

[44] ——, “VESC Tool.” [Online]. Available: https://vesc-project.com/vesc tool

[45] Maytech, “Maytech MTSKR1712 mini wireless re- mote.” [Online]. Available: http://www.maytech.cn/en/ maytech-mtskr1712-e--mini-wireless-remote/11032.html

[46] Mouser, “MSO206NR Mallory Sonalert.” [Online]. Avail- able: https://www.mouser.se/ProductDetail/Mallory-Sonalert/MSO206NR? qs=94V4QatVK%252bej6G6GKbjORw==

[47] Original , “Arbiter 36 DK Longboard by Original Skate- boards.” [Online]. Available: https://originalskateboards.com/product/ double-kick-arbiter-deck/

[48] A. Font and G. W. Fuller, “Did policies to abate atmospheric emissions from traffic have a positive effect in London?” Environmental Pollution, vol. 218, nov 2016. [Online]. Available: https://www.sciencedirect.com/science/article/ pii/S0269749116305966?via%3Dihub

46 Appendix A

Arduino code to control the board

A.1 The main code

1 /* Project name: Eboard 2 Author: Leo Sodergren 3 Date: 2018-05 4 School: KTH 5 Course: MX133X 6 Description: Code for controlling the electric board prototype 7 Configuration: 8 MCU: ATmega2560 9 Clock Speed: 16 MHz 10 Board: Arduino MEGA 11 Used pins: See config 12 */ 13 14 // Includes the needed libraries 15 #include 16 #include 17 #include 18 #include 19 #include 20 #include 21 #include 22 #include 23 #include 24 25 26 27 #include "config.h"//Includes the config.h file

47 APPENDIX A. ARDUINO CODE TO CONTROL THE BOARD

28 29 30 // ------Varible Initilization ------31 32 // Initilizes the volitile varibles 33 34 volatile int ThrottleIn = 0; // volatile, we set this in the Interrupt and read it in loop so it must be declared volatile 35 volatile unsigned long ulStartPeriod = 0; // set in the interrupt 36 volatile int state = 1; 37 38 39 // Initilizes varibles 40 41 int mode; 42 int timN=0; //times neutral 43 int Mfull = false; //defines the matrix empty 44 int BLS=0; //backligt base brightness 45 float motor_current = 0.0; //Measured motor current 46 float batvoltage = 35.0; //Measured battery voltage, starts at 47 float c_speed = 0.0; //Measured rpm 48 float power = 0.0; //Measured power 49 float avaragePWR; //Average power 50 unsigned long sum; //The sum of the poweroutput 51 int averagenum=0; //Number avarage samples starts at 0 52 int PWRarray[avragrot]; //Initilizes the avrrage array 53 int calulated_Throttle=0; //Starts the calculate throttle at 0 54 int index; 55 56 bool cellstate[]={false,false,false,false,false};// cell state. False means ok. 57 char cellstr[]={’1’,’3’,’5’,’8’,’X’};// cell str 58 59 60 struct bldcMeasure measuredValues; 61 62 // Matrix Initilization.

48 A.1. THE MAIN CODE

63 Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, Mpin, 64 NEO_MATRIX_TOP + NEO_MATRIX_LEFT + 65 NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, 66 NEO_GRB + NEO_KHZ800); 67 68 69 // ------Interrupt functions------70 void interrupt(){//Interrupt function for street mode 71 72 if(digitalRead(Siginpin) == HIGH){// if the signal pin is high, its the start of a high pulse. 73 ulStartPeriod = micros(); 74 } 75 else{ // if the pin is low calculate the passed time 76 ThrottleIn = (int)(micros() - ulStartPeriod); 77 ulStartPeriod = 0; 78 } 79 } 80 81 void racemodeinterrupt(){//Interrupt function for race mode 82 // if the signal pin is high, set the pin high 83 if(digitalRead(Siginpin) == HIGH){ 84 digitalWrite(Sigoutpin, HIGH); 85 ulStartPeriod = micros(); 86 } 87 else{// if the pin is low set the output low 88 digitalWrite(Sigoutpin, LOW); 89 ThrottleIn = (int)(micros() - ulStartPeriod); 90 ulStartPeriod = 0; 91 } 92 } 93 94 void cstate(){// Function to change state turn on off lights . 95 static unsigned long last_interrupt_time = 0; //Defines static function varible 96 unsigned long interrupt_time = millis(); 97 if (interrupt_time - last_interrupt_time > 200){ // If interrupts come faster than 200ms, assume it’s a bounce and ignore, source: [mikalhart forum.arduino.cc] 98 if(state==1){ 99 state=2; 100 analogWrite(BLpin,BLbr); //Turn on the lights with the

49 APPENDIX A. ARDUINO CODE TO CONTROL THE BOARD

brightness set in Config.h 101 analogWrite(FLpin,FLbr); 102 BLS=BLbr; //sets the backlight base brightness to the configured brightness. 103 } 104 else{ 105 state=1; 106 digitalWrite(FLpin,LOW); //Turns off the lights 107 digitalWrite(BLpin,LOW); 108 BLS=0; //sets the backlight base brightness 0; 109 } 110 111 } 112 last_interrupt_time = interrupt_time; 113 } 114 115 116 // ------SETUP------117 void setup() { 118 pinMode(Pbutpin, INPUT_PULLUP); //Set push-button as input with internal pullup 119 pinMode(Siginpin, INPUT_PULLUP); 120 121 //Set various outputs 122 pinMode(Sigoutpin, OUTPUT); 123 pinMode(Servopin, OUTPUT); 124 pinMode(BLpin, OUTPUT); 125 pinMode(FLpin, OUTPUT); 126 pinMode(PBled, OUTPUT); 127 128 analogWrite(PBled,20); 129 130 for(int index=0; index<=avragrot; index++){ //Sets up an average array, if not used comment out 131 PWRarray[index]=0; 132 } 133 134 //Starts matrix 135 matrix.begin(); 136 matrix.setTextWrap(false); 137 matrix.setBrightness(Mbr); //Sets the brightness of the matrix acording to that set in Config.h 138 matrix.fillScreen(matrix.Color(0, 0, 0)); //Starts the screen black

50 A.1. THE MAIN CODE

139 matrix.show(); 140 141 //Serial begin 142 Serial1.begin(115200); 143 //Serial.begin(115200); //debug serial over usb not needed for normal use. 144 145 146 if (digitalRead(Pbutpin) == HIGH){ // Checks if push- button pressed at start if so goes into race mode 147 attachInterrupt(digitalPinToInterrupt(Siginpin), interrupt,CHANGE); 148 attachInterrupt(digitalPinToInterrupt(Pbutpin),cstate, FALLING); 149 mode=1; 150 } 151 else{ 152 raceM(); 153 attachInterrupt(digitalPinToInterrupt(Siginpin), racemodeinterrupt,CHANGE); 154 attachInterrupt(digitalPinToInterrupt(Pbutpin),cstate, FALLING); 155 mode=2; 156 } 157 158 delay(500); //Delay 500ms to be shure to have an first interrrupt 159 } 160 161 // ------MAIN------162 void loop() { 163 if (mode==2){ // 164 racemode(); 165 } 166 else{ 167 streetmode(); 168 } 169 } 170 171 //------Mode functions------172 void streetmode(){ 173 brakelights(); 174 175 if(ThrottleIn>(Max_Throttle+Throttle_fault)) {//Signal too

51 APPENDIX A. ARDUINO CODE TO CONTROL THE BOARD

high error 176 timN=0; 177 neutralThrottle(); 178 errorM(); 179 } 180 else if(ThrottleIn<(Min_Throttle-Throttle_fault)){//Signal too low error 181 timN=0; 182 neutralThrottle(); 183 errorM(); 184 } 185 else if ((ThrottleIn>=Neutral_Throttle-Deadband_Throttle) &&(ThrottleIn<=Neutral_Throttle+Deadband_Throttle)){// Neutral throttle 186 if(timN>=neutraltimes){ //If enough neutral has been enough times switch to monitoring mode 187 voltcheck(); 188 batteryerror(); 189 neutralThrottle(); 190 } 191 else{ 192 normallThrottle(); 193 timN++; 194 } 195 } 196 else{ //Normal throttle 197 timN=0; 198 clearM(); 199 readvesc();// Tries to read the VESC 200 // Here the wanted power limiting method is set. 201 //PWRavarage(); // "Running average" mode 202 //PWRavaragecutoff(); //"Running average cutoff" mode 203 PWRavarageclocks(); //"Average" 204 } 205 } 206 207 void racemode(){ 208 brakelights(); 209 } 210 211 //------Power mode functions------212 void PWRavaragecutoff(){ 213 if (ThrottleIn<=Neutral_Throttle-Deadband_Throttle){//if braking do no conversion

52 A.1. THE MAIN CODE

214 averagenum++; 215 avaragePWR=sum/averagenum; 216 } 217 else{ 218 long sum= sum+power; 219 averagenum++; 220 avaragePWR=sum/averagenum; 221 } 222 if (avaragePWR<=maxpower||ThrottleIn<=Neutral_Throttle- Deadband_Throttle){ 223 normallThrottle(); 224 } 225 else{ 226 neutralThrottle(); 227 } 228 } 229 230 void PWRavarage(){ 231 if (ThrottleIn<=Neutral_Throttle-Deadband_Throttle){//if braking do no conversion 232 averagenum++; 233 avaragePWR=sum/averagenum; 234 } 235 else{ 236 sum= sum+power; 237 averagenum++; 238 avaragePWR=sum/averagenum; 239 } 240 calulated_Throttle=maxpower/(auS*batvoltage)+ Neutral_Throttle+Deadband_Throttle; 241 if (avaragePWR<=maxpower || ThrottleIn<= Neutral_Throttle- Deadband_Throttle){ 242 normallThrottle(); 243 } 244 else if(ThrottleIn>=calulated_Throttle){ 245 calculatedThrottle(); 246 } 247 else{ 248 normallThrottle(); 249 } 250 } 251 252 void PWRavarageclocks(){ //https://www.arduino.cc/en/ Tutorial/Smoothing

53 APPENDIX A. ARDUINO CODE TO CONTROL THE BOARD

253 sum =(float) sum - PWRarray[index];// subtract the last reading: 254 PWRarray[index] = power; // read the power output: 255 sum = sum + PWRarray[index];// add the reading to the total: 256 index = index + 1;// advance to the next position in the array: 257 if (index >= avragrot) { // if we’re at the end of the array... 258 index = 0; // ...wrap around to the beginning: 259 } 260 261 // calculate the average: 262 avaragePWR = (float) sum / avragrot; 263 calulated_Throttle=maxpower/(auS*batvoltage)+ Neutral_Throttle+Deadband_Throttle; 264 if (avaragePWR<=maxpower || ThrottleIn<= Neutral_Throttle- Deadband_Throttle){ 265 normallThrottle(); 266 } 267 else if(ThrottleIn>=calulated_Throttle){ 268 calculatedThrottle(); 269 } 270 else{ 271 normallThrottle(); 272 } 273 } 274 275 //------Random Functions------276 void neutralThrottle(){ 277 digitalWrite(Sigoutpin, HIGH); 278 delayMicroseconds(Neutral_Throttle-neutralcomp); 279 digitalWrite(Sigoutpin, LOW); 280 delayMicroseconds(frequen); 281 } 282 283 void normallThrottle(){ 284 digitalWrite(Sigoutpin, HIGH); 285 delayMicroseconds(ThrottleIn-neutralcomp); 286 digitalWrite(Sigoutpin, LOW); 287 delayMicroseconds(frequen); 288 } 289 290 void calculatedThrottle(){

54 A.1. THE MAIN CODE

291 digitalWrite(Sigoutpin, HIGH); 292 delayMicroseconds(calulated_Throttle-neutralcomp); 293 digitalWrite(Sigoutpin, LOW); 294 delayMicroseconds(frequen); 295 } 296 297 void brakelights(){ 298 if(ThrottleIn<=Neutral_Throttle-Deadband_Throttle){//If signal under neutral(braking) turn on back lights 299 analogWrite(BLpin, (BLS+Bbr)); 300 } 301 else{ 302 analogWrite(BLpin, BLS); 303 } 304 } 305 306 void voltcheck(){ 307 static float voltage; 308 batvoltage=analogRead(voltagepin[0])*Vconv/Vfact[0]*10.0; 309 for(int cell=0 ; cell<=4 ; cell++) 310 { 311 float voltage=( analogRead(voltagepin[cell])*Vconv/Vfact [cell]); 312 if (voltage <= Uvolt*cellnum[cell] || voltage >= Ovolt* cellnum[cell]) 313 { 314 cellstate[cell]=true; 315 } 316 else 317 { 318 cellstate[cell]=false; 319 } 320 } 321 } 322 323 void batteryerror(){ 324 for(int cell=0 ; cell<=4 ; cell++) 325 { 326 if (cellstate[cell]==true) 327 { 328 batteryM(cellstr[cell]); 329 delay(1000); 330 } 331 else{

55 APPENDIX A. ARDUINO CODE TO CONTROL THE BOARD

332 clearM(); 333 } 334 } 335 } 336 void readvesc(){ //Function to read values from VESC and calculate power 337 if (VescUartGetValue(measuredValues)) { 338 c_speed= (measuredValues.rpm); 339 motor_current= measuredValues.avgInputCurrent/80000; 340 power=(float)motor_current*batvoltage; 341 } 342 } 343 344 345 //------Matrix pattern functions ------346 347 void clearM(){ //Clear matrix function. 348 if (Mfull) //checks if screen actually is filled to minimize cycles spent uppdating 349 { 350 matrix.fillScreen(matrix.Color(0, 0, 0)); 351 matrix.show(); 352 Mfull=false; 353 } 354 } 355 356 void raceM(){//Function to draw raceflag 357 { 358 matrix.drawLine(0, 0, 7, 7, matrix.Color(255, 255, 255)); 359 matrix.drawLine(2, 0, 7, 5, matrix.Color(255, 255, 255)); 360 matrix.drawLine(4, 0, 7, 3, matrix.Color(255, 255, 255)); 361 matrix.drawLine(6, 0, 7, 1, matrix.Color(255, 255, 255)); 362 matrix.drawLine(0, 2, 5, 7, matrix.Color(255, 255, 255)); 363 matrix.drawLine(0, 4, 3, 7, matrix.Color(255, 255, 255)); 364 matrix.drawLine(0, 6, 1, 7, matrix.Color(255, 255, 255)); 365 matrix.show(); 366 Mfull=true; 367 } 368 } 369 370 void batteryM(char cell){ //Function to show battery error 371 matrix.fillScreen(0); 372 matrix.drawRect(1, 1, 6, 7, matrix.Color(255, 0, 0));

56 A.2. CONFIG CODE

373 matrix.drawFastHLine(2, 0, 4, matrix.Color(255, 0, 0)); 374 matrix.setCursor(1, 0); 375 matrix.print(cell); //Displays which cell is outside the critera. 376 matrix.show(); 377 Mfull=true; 378 } 379 380 void errorM(){ //Function to show error 381 matrix.fillScreen(0); 382 matrix.fillRect(2, 0, 4, 5, matrix.Color(255, 0, 0)); 383 matrix.drawRect(3, 6, 2, 2, matrix.Color(255, 0, 0)); 384 matrix.show(); 385 Mfull=true; 386 delay(500); 387 } A.2 Config code

1 //Config.h 2 /*Configuration file for Eboard 3 * Leo Sodergren 2018 4 */ 5 6 //Defining controllable varibles 7 #define Min_Throttle 1000 //[us] Minimum throttle time. 8 const int Neutral_Throttle=1500; //[us] This is the duration in of neutral throttle pulse. 9 #define Max_Throttle 2000 //[us] Maximum throttle. 10 #define Throttle_fault 500//[us] Margin for to long/short pulses. 11 #define frequen 200000 //[us] Duration between pulses. 12 #define Deadband_Throttle 25//[us] The deadband for which the controll is accepted neutral(+-) 13 #define FLbr 25 //Brightness of the front light (255 for 6W) 14 #define BLbr 20 //Brightness of the back light (255 for 8W) 15 #define Mbr 20 //Brightness of the LED matrix (100 for 100%) 16 #define Bbr 50 //extra brightness for braking 17 #define neutraltimes 300 //Times before entering neutral mode. 18 #define neutralcomp 200 //[us]

57 APPENDIX A. ARDUINO CODE TO CONTROL THE BOARD

19 #define maxpower 125 //[W] Max power output per motor 20 #define avragrot 100 //Number ov values to calculate average 21 #define maxspeed 20 //[kmh] maximum speed 22 23 const float Ovolt=4.35; //[V] Overvoltage 24 const float Uvolt=3.2; //[V] Undervoltage 25 const float maxA=22.0; //[A] Maximal ampere 26 27 //Defining calculation varibles 28 const float Vconv =(5.0/1023.0); //defines the voltage constant 29 const float Vfact[]={1.0,0.39324,0.220765,0.14651,0.11665}; //defines the voltage factors for all measured cells. Optimized for low volatage 30 31 //Defining random varibles 32 const int cellnum[]={1,3,5,8,10}; 33 34 const float auS=maxA/(Max_Throttle-Neutral_Throttle); // Ampere per micro second 35 36 const float wheeldia=0.09; //[m] wheeel diameter 37 const int erpm=6; // Factor omega elec/omega mech 38 const float rpmconv=wheeldia*6.28*60/(1000*erpm); 39 40 41 //------Output Input ------42 43 //Defining ouputs 44 #define Mpin 8 //Matrix pin 45 #define BLpin 9 //Backlight pin 46 #define FLpin 10 //Headlight pin 47 #define Servopin 11 //Servo (parking brake) pin 48 #define Sigoutpin 46 // Signal out pin 49 #define PBled 13 // Push button LED pin 50 51 //Defining digital inputs 52 #define Siginpin 20 //Signal interrupt 1 53 #define Pbutpin 21 //Push-button interrupt 0 54 55 //Defining analog inputs 56 const int voltagepin[]={0,1,2,3,4};

58 A.2. CONFIG CODE

57 //cell 1, cell 3, cell 5, cell 8, cell 10

59 Appendix B

Acceleration tests graphs

B.1 Average mode

Test graphs for ”average” mode:

60 B.2. RUNNING AVERAGE CUTOFF

B.2 Running average cutoff

Test graphs for ”Running average cutoff” mode:

61 APPENDIX B. ACCELERATION TESTS GRAPHS

B.3 Running average

Test graphs for ”Running average” mode:

62 B.4. SIMPLE POWER LIMITING

B.4 Simple power limiting

Test graphs for ”Simple power limiting” mode:

63 APPENDIX B. ACCELERATION TESTS GRAPHS

B.5 Race mode

Test graphs for ”Race mode” mode:

64 Appendix C

Matlab code to convert accelerometer data

1 %% Filename: acceleration.m, Autor: Leo Sodergren, Date :2018-05-20 2 % Accepts .tsv file in format " counter timestamp[ms] x[m/s ˆ2] y[m/sˆ2] 3 % Z[m/sˆ2]" and calculates/plots the absolue accelaration in x and y axis. 4 5 6 7 8 clc 9 clf 10 clear all 11 close all 12 13 file =’race42.tsv’ 14 accM = tdfread(file); % Creates a struct of the .tsv file 15 names = fieldnames(accM); % Finds the structs fields names and creates a cell 16 timeN =[’accM.’ names{2}]; % Creates a sting of the time variable 17 XN=[’accM.’ names{3}]; % Creates a sting of the X variable name 18 YN=[’accM.’ names{3}]; % Creates a sting of the Y variable name 19 timecode=eval(timeN); % Creates vector of the timecodes 20 timecode=timecode/1000; % Converts the timecode from ms to s 21 timestart=timecode(1); % Finds the first time

65 APPENDIX C. MATLAB CODE TO CONVERT ACCELEROMETER DATA

22 time = zeros(length(timecode),1); %Creates empty time vector 23 for ii = 1:length(timecode) % Loops through the timecodes 24 time(ii)=timecode(ii)-timestart; % Calculates the passed time from start 25 end 26 X=eval(XN); % Creates vector of x accelerations 27 Y=eval(YN); % Creates vector of y accelerations 28 tot=sqrt(X.ˆ2+Y.ˆ2); % Calculates the combined vector length 29 tott=smooth(tot,20); % Creates a smoothed dataset 30 average=ones(length(timecode),1)*sum(tot)/length(timecode); %creates vector with average acceleration 31 32 figure(’pos’,[1 50 1600 700]) %Designates where the plot will display 33 hold on 34 plot(time,average,’--k’,’Linewidth’,2) % Plots the average 35 hold on 36 plot(time,tot,’.’,’color’,[1,0.4,0.2],’markers’,15) % Plots the sampled data 37 hold on 38 plot(time,tott,’Linewidth’,4,’color’,[0,0,1]) % Plots the sampled data 39 hold on 40 legend({’Average’,’Sampled data’,’Smoothed data’},’FontSize’ , 15) 41 xlabel(’time’,’FontSize’, 20) 42 ylabel(’m/sˆ2’,’FontSize’, 20) 43 xlim([0 time(length(timecode))]) 44 set(gca,’fontsize’,15) 45 file=[file ’.png’]; 46 fig = gca; 47 print (’-dpng’,figure(1),file,’-r200’)

66 Appendix D

Matlab code to analyze light measurements

1 clc 2 clear all 3 X=[-20 0 20]; 4 Y=[0 10 20]; 5 Z=[190 300 173; %Light measurements for the board’s front lights 6 120 240 125; 7 86 150 85]; 8 Z=Z*255/25; %Conversion rate because the lights were not at full power 9 10 ZR=[70 120 73; %Light measurements for the board’s back lights 11 64 101 58; 12 56 54 50]; 13 ZR=ZR*255/20; %Conversion rate because the lights were not at full power 14 15 Z2=[734 4500 636; %Light measurements for the Lezyne Hecto Drive 300XL 16 402 1400 387; 17 280 374 265]; 18 19 ZR2=[82 83 73; %Light measurements for the Lezyne Hector Strip. 20 70 73 69; 21 64 70 60]; 22

67 APPENDIX D. MATLAB CODE TO ANALYZE LIGHT MEASUREMENTS

23 [xx yy] = meshgrid(-20:0.1:20,0:0.1:20); %Makes a grid with 1mm spacing 24 ZZ=interp2(X,Y,Z,xx,yy,’cubic’); %Cubic interpolation of the measurements 25 ZZR=interp2(X,Y,ZR,xx,yy,’cubic’); 26 ZZ2=interp2(X,Y,Z2,xx,yy,’cubic’); 27 ZZ2R=interp2(X,Y,ZR2,xx,yy,’cubic’); 28 29 figure(1) 30 contourf(xx,yy,ZZ,100,’LineColor’ , ’flat’,’DisplayName’,’ Lux’) %Makes a contour plot of the interpolated data 31 axis equal %Sets the axis to equal scale. 32 set(gca,’fontsize’,15) 33 c=colorbar; 34 c.Label.String = ’Lux’; 35 36 figure(2) 37 contourf(xx,yy,ZZR,100,’LineColor’ , ’flat’,’DisplayName’,’ Lux’) 38 axis equal 39 set(gca,’fontsize’,15) 40 c=colorbar; 41 c.Label.String = ’Lux’; 42 43 figure(3) 44 contourf(xx,yy,ZZ2,100,’LineColor’ , ’flat’,’DisplayName’,’ Lux’) 45 axis equal 46 set(gca,’fontsize’,15) 47 c=colorbar; 48 c.Label.String = ’Lux’; 49 50 figure(4) 51 contourf(xx,yy,ZZ2R,100,’LineColor’ , ’flat’,’DisplayName’,’ Lux’) 52 axis equal 53 set(gca,’fontsize’,15) 54 c=colorbar; 55 c.Label.String = ’Lux’; 56 57 print (’-dpng’,figure(1),’Boardw.png’,’-r200’) 58 print (’-dpng’,figure(2),’BoardR.png’,’-r200’) 59 print (’-dpng’,figure(3),’cykelw.png’,’-r200’) 60 print (’-dpng’,figure(4),’cykelR.png’,’-r200’)

68 Appendix E

Layout and schematic for the LED board

Figure E.1. LED module circuit board layout. Made in Autodesk Eagle

Figure E.2. LED module circuit board layout. Made in Autodesk Eagle

69 Appendix F

Layout and schematic for the power distribution board

Note this includes the IC voltage regulator that was not used in the final board.

Figure F.1. Power distribution circuit board top. Made in Autodesk Eagle

70 Figure F.2. Power distribution circuit board bottom. Made in Autodesk Eagle

Figure F.3. Power distribution battery connection circuit schematic. Made in Autodesk Eagle

71 APPENDIX F. LAYOUT AND SCHEMATIC FOR THE POWER DISTRIBUTION BOARD

Figure F.4. Power distribution voltage regulation circuit schematic. Made in Au- todesk Eagle

Figure F.5. Power distribution VESC connection circuit schematic. Made in Au- todesk Eagle

72 Appendix G

Layout and schematic for the voltage divider board

Figure G.1. Voltage divider circuit board layout. Made in Autodesk Eagle

73 APPENDIX G. LAYOUT AND SCHEMATIC FOR THE VOLTAGE DIVIDER BOARD

Figure G.2. Voltage divider circuit schematic. Made in Autodesk Eagle

74 Appendix H

Layout and schematic for the buzzer board

Figure H.1. Buzzer circuit board layout. Made in Autodesk Eagle

Figure H.2. Buzzer circuit schematic. Made in Autodesk Eagle

75 Appendix I

Images of the completed board

Figure I.1. The completed board

76 Figure I.2. The underside of the completed board

Figure I.3. Lid over battery compartment

77 APPENDIX I. IMAGES OF THE COMPLETED BOARD

Figure I.4. The main compartment lid with the push-button.

Figure I.5. The front of the board with the headlight.

78 Figure I.6. The parking brake as seen from underneath the board. Note that the wire guide is missing.

Figure I.7. The LED matrix displaying a battery cell error for cell 8.

79 APPENDIX I. IMAGES OF THE COMPLETED BOARD

Figure I.8. The LED matrix displaying an in-signal error.

Figure I.9. The LED matrix displaying a checkered flag.

80 Figure I.10. The board with its head and taillights lit.

81 Appendix J

Images of the completed hand controller

Figure J.1. Side view of the hand controller.

Figure J.2. Front view of the hand controller. Note the push-button to activate the AW-dev

82 Figure J.3. Top view of the hand controller.

Figure J.4. The hand controller in a hand.

83 Appendix K

3D model of the hand controller

A 3D model of the hand controller. Use a compatible PDF viewer to view 3D files.

84 Appendix L

3D model of the board

A simplified 3D model of the board. Use a compatible PDF viewer to view 3D files.

85 TRITA ITM-EX 2018:72

www.kth.se