Materiały dotyczące budowy niemieckiego Segway: Opisy, płytki PCB, oprogramowanie.
praxis
e-fahrzeuge
ElektorWheelie
ZZZZOOM - die Elektronik
des Elektro-Zweirads
der besonderen Art
Von Christof Krohne (D)
Im ersten Artikel über den Selbstbau des sich selbst balancierenden einachsigen Elektro-Rollers stellen
wir die kompakte Elektronik-Baugruppe vor. Ein ATmega32 verarbeitet die Steuer- und Sensordaten und
regelt über die Leistungsstufen der beiden Motoren die Fahrtrichtung, die Fahrgeschwindigkeit und die
Balance des elektrischen Stehrollers - vom Stillstand bis zu einer Geschwindigkeit von 18 km/h.
Die Elektronik des ElektorWheelie
verarbeitet die Signale eines Steuerpotis, eines Beschleunigungssensors
und eines Winkelsensors und steuert abhängig davon mittels PWM und
MOSFETs die Drehrichtung und das
Drehmoment der beiden Motoren.
Dadurch bleibt der einachsige Roller über den gesamten Geschwindigkeitsbereich in Balance. Dabei ist es
auch möglich, praktisch auf der Stelle
zu drehen.
Eigenschaften
•
•
•
•
•
•
•
•
•
•
2 x 500-W-DC-Getriebemotoren
2 x 12-V-Blei-Vlies-Akkus (AGM) mit 9 Ah
2 x 14 Zoll luftbereifte Kunststoffräder
H-Brücken-PWM-Motorsteuerung mit bis zu 25 A
Automatische Abschaltung beim Absteigen
Fail-safe-Notabschaltung
Akku-Ladestandsanzeige
Max. Geschwindigkeit 18 km/h
Reichweite: ca. 8 km
Gewicht ca. 35 kg
Der Antrieb des ElektorWheelies
besteht aus zwei 500-W-GleichstromGetriebemotoren. Die Stromversorgung übernehmen zwei 12-V-BleiAGM-Akkus. Die Elektronik besteht
im Wesentlichen aus einer Steue-
Sensoren
• Gyroskop Invensense IDG300 (IDG500)
• Beschleunigungssensor Analog Devices ADXL 320
• Stromsensor Allegro ACS 755-SCB 100
Mikrocontroller
• AtMega32 (Motorsteuerung)
• ATtiny25 (Stromüberwachung)
Compiler
• BASCOM-AVR (Basic-Compiler)
elektor - 7-8/2009
Balancieren, lenken, bremsen
Entscheidend für das erfolgreiche Balancieren des Stehrollers ist, dass die Sensorik zuverlässige Informationen über den Neigungswinkel der
Stehplattform und die Geschwindigkeit der Winkeländerung liefert - und natürlich auch, dass Regelung, Motorsteuerung und Motoren in geeigneter Weise dimensioniert sind.
Das Balancieren selbst ist dann relativ einfach. Neigt der Fahrer sich nach vorne, kippt die Plattform und die Motoren werden so beschleunigt, dass
der Schwerpunkt des gesamten Systems wieder in Balance kommt. Das heißt, die Füße des Fahrers werden unter dem Schwerpunkt des Gesamtsystems (Fahrer plus Roller) nach vorne beschleunigt, so dass der Fahrer etwas nach hinten kippt und sich der Neigungswinkel wieder verringert.
Das ganze System neigt damit zu einem Aufschwingen, dem mit einem entsprechend stabilen Gehäuse und einer empirisch angepassten Filterfunktion begegnet wird. Die „Härte“ des Filters liegt also kurz vor der Schwingneigung des Systems.
Das Lenken erfolgt durch unterschiedlich starkes Beschleunigen beziehungsweise Abbremsen der Motoren. Zu berücksichtigen ist dabei, dass bei
höheren Geschwindigkeiten die Lenkbewegung aus Sicherheitsgründen begrenzt werden muss. Der ElektorWheelie wird bei schnellen Richtungsänderungen so schnell nicht umkippen - dem Fahrer sind hingegen schon früher Grenzen gesetzt.
Irgendwann ist auch der schönste Motor mit seiner Leistung am Ende. Im Falle des ElektorWheelie hätte es aber fatale Folgen für den Fahrer, wenn
die Motoren keine Leistung mehr haben, um eine Störung der Balance auszugleichen. Aus diesem Grund werden die Motoren nur mit einer maximalen Leistung von ca. 70 % belastet. Es muss immer eine Leistungsreserve bestehen, die es ermöglicht, den Fahrer auch beim Erreichen der
Maximalgeschwindigkeit noch durch eine zusätzliche Beschleunigung soweit nach hinten zu “werfen”, dass eine automatische Verringerung der Geschwindigkeit erfolgt um den Fahrer auszubalancieren. Nach hinten lehnen bremst den Wheelie ab, nach vorne neigen beschleunigt ihn.
rungs-Platine mit darauf aufgesetzter
Sensorplatine.
Die Steuerung funktioniert nach dem
Prinzip der dynamischen Stabilisierung. Ähnlich dem menschlichen
Gleichgewichtssinn steuert der Roller
mit Hilfe von Sensoren die Balance der
Stehplattform. Droht diese nach vorne
oder nach hinten zu kippen, beschleunigt der Roller proportional entgegen der Kippbewegung die beiden
Motoren. Durch ein unterschiedlich
starkes Ansteuern der Motoren lässt
sich der Roller lenken.
Nennstromes von fast 25 A und initiiert damit eine dynamische Anpassung des PWM-Signals.
Die Steuerinputs erhält der Mega32
über seinen A/D-Wandler (ADC) von
dem Gyroskop und dem Beschleunigungssensor der Sensorplatine sowie
von einem hochzuverlässigen Steuerpoti, das mit dem Steuerhebel des
ElektorWheelie verbunden ist. Die
2x 12V 9Ah
AGM-Bleiakku
Notstoppunterbrecher
Prinzipschaltung
Kern der in Bild 1 im Blockschaltbild dargestellten Lageregelung und
Motorsteuerung ist ein ATmega32
von Atmel. Dieser steuert über zwei
PWM-Ausgänge und zwei MOSFETH-Brückenschaltungen die beiden
24-V-DC-Motoren. Über einen Halleffekt-Stromsensor überwacht ein
zweiter Mikrocontroller, ein ATtiny25
von Atmel, den Motorstrom. In einer
Überstromsituation mit einem Strom
von fast 80 A (Kurzschluss) entzieht
der ATtiny über den Enable-Pin des
15-V-Spannungsreglers den Treiberschaltungen der H-Brücken die
Betriebsspannung. Für den Fall eines
Kurzschlusses mit Totalausfall der
Motorelektronik wird über eine rein
elektromechanische Notstoppvorrichtung der Akkustrom unterbrochen, um
ein „Durchgehen“ des Rollers unter
allen Umständen auszuschließen.
Stromsensor
ATtiny25
Batterieanzeige
Power-H-Brücke
24V DC
Motor A
PWM OC1B
Fußtaster
Spannungsregler
15V
mit
“enable-Pin”
PWM OC1A
Spannungsregler
5V
Power-H-Brücke
24V DC
Motor B
ATmega32
ADC
Invensense
Gyro
Accelerometer
ADXL 320
Poti/
Lenkstange
090248 - 13
Bewegt sich der Strom in den normalen Grenzen, meldet der Tiny25 dem
Mega32 eine Überschreitung des
7-8/2009 - elektor
Bild 1. Die Motorsteuerung im Blockschaltbild.
praxis
e-fahrzeuge
Daten des ADC werden
ca. 100 Mal pro Sekunde
ausgelesen.
(LED1…3) für die
Akkuanzeige direkt
treibt.
VCC
14
29
34
Die Sensorplatine ist
K2
K1
Als weiteres Sicherheitsüber K2 mit der SteuAREF (3V)
IC1
32
17
feature ist ein Fußkonerung verbunden
VREF
CPOUT
R3
takt (Fußtaster) mit dem
und liefert die X- und
28
23
Y-RATE OUT
YAGC
75R
GYRO-Y
IDG-300
ATmega32 verbunden.
Y-Signale der beiGYRO-X
R4
3
8
X-RATE OUT
XAGC
75R
ADXL-X
Wird dieser Taster nicht
den Lagesensoren an
ADXL-Y
betätigt, weil der Fahrer
die A/D-Wandlereinabgestiegen (oder sogar
gänge ADC2…5 des
2 22 25 38 39 40
C11
C12
C9
C2
C10
abgesprungen) ist, schalATmega32, der an Pin
+5V
1u
1u
220n 220n 100n
tet der Mikrocontroller
32 (AREF) auch 3 V
nach zwei Sekunden den
vom SpannungsregVCC
+5V
Motorstrom ab. Somit wird
ler des Sensor-Boards
verhindert, dass der Roller
erhält. Diese 3 V lieIC3
1
5
VIN
VOUT
unbemannt weiterfährt.
gen über K3 auch am
LP2980
3
Die Akkuspannung wird
Steuer-Poti an, dessen
ON/OFF
2
ebenfalls über den A/DSchleifer wiederum
14
15
VCC
VS
VS
Wandler des ATmega32
eine von der Posi10
IC2 YOUT
ausgewertet, der abhäntion des Steuerhebels
ADXL320
12
gig davon eine Anzeige der
abhängige Spannung
XOUT
C1
C14
C15
C16
COM
ST
C4
C3
verbleibenden Betriebszeit
an den ADC6-Eingang
2µ2
2
3 5 6 7
100n 100n 4u7
16V
2n2
2n2
6V
mit drei LEDs steuert.
des ATmega32 liefert.
090248 - 12
Der A/D-Wandlereingang ADC0 misst über
Sensorik und dynamische
den Spannungsteiler
Bild 2. Die Schaltung der Sensorplatine mit Gyroskop und Beschleunigungssensor.
Stabilisierung
R10/R11 die AkkuspanDie Lagesensoren sind auf
nung, während ADC7
einer eigenen kleinen Platine unterüber K3 mit dem Fußschalter verbunder Plattform bestimmen zu können.
gebracht, die auf die Hauptplatine
den ist. Als weiteren Input erhält der
Der Wert des Beschleunigungssender Steuerung aufgesteckt wird. In
ATmega an Pin 16 (INT0) noch ein
sors wird daher über einen längeren
Überstrom-Signal (CURRFLAG) von der
Zeitraum integriert, um ein geglätBild 2 ist die Schaltung der Sensorplatine zu sehen. Neben dem 2-AchsenStromüberwachung mit dem ATtiny
tetes Signal zu erhalten. Hierzu wird
Gyroskop IDG300 [1] von Invensense
(IC10), der wiederum das Signal vom
nun der Spannungswert des Gyrosbefindet sich auch der 2-AchsenbeStromsensor IC5 auswertet. IC5 ist ein
kops addiert. Die Gewichtung wurde
schleunigungssensor ADXL-320 [2]
integrierter Halleffekt-Stromsensor von
hierbei empirisch angepasst und optivon Analog Devices auf dem Board.
Allegro MicroSystems, der in einem
miert. Der nötige BeschleunigungsDer Spannungsregler IC3 versorgt die
Bereich von 100 A linear arbeitet.
wert ergibt sich dann als Summe aus
Sensoren mit der erforderlichen SpanCURRFLAG wird bei einem Strom von
der Winkeldifferenz (ist–soll) und der
Winkelgeschwindigkeit, mit der sich
nung von 3 Volt, die gleichzeitig auch
fast 25 A gesetzt und begrenzt über
als Referenzspannung für den A/Ddie PWM-Steuerung den Motorstrom,
die Plattform neigt - mit unterschiedWandler des Mega32 auf der Hauptwomit wir bei den Ausgangssignalen
licher Gewichtung dieser beiden Gröplatine dient.
des ATmega angelangt wären.
ßen. Grundsätzlich gilt: Je größer die
Das Gyroskop liefert eine Spannung
Winkelabweichung und je höher die
Das Ergebnis der Verarbeitung der
proportional zur Drehrate (WinkelgeWinkelgeschwindigkeit, desto gröaufgeführten Eingangssignale sind
schwindigkeit). Neigt sich die Plattßer ist die zur Stabilisierung nötige
die Signale an den vier Ausgangspins
form schnell, erhält man eine große
Motorbeschleunigung.
18 bis 21, nämlich PWM-L/R und CW/
Spannungsänderung innerhalb einer
CCW-A´/B´. CW/CCW-A´ und CW/
gegebenen Zeitperiode. Im RuhezuCCW-B´ sind über Logikschaltungen
Motorsteuerung
stand liefert das Gyroskop eine Span(IC8 und IC9) mit den PWM-Ausgangsnung, die etwa der halben VersorDie Schaltung der Hauptplatine in
signalen PWM-L und PWM-R verknüpft
gungsspannung entspricht.
Bild 3 umfasst die gesamte Steueund steuern jeweils die Drehrichtung
Der Beschleunigungssensor misst in
rung des ElektorWheelie inklusive
des gesteuerten Motors, während die
der waggerechten Lage die ErdbeLeistungselektronik. Lediglich die
PWM-Signale über H-Brücken (Vollschleunigung. Wird der Sensor geneigt,
beiden Lagesensoren sind wie zuvor
brücken) den Motorstrom steuern. Für
so ändert sich der Winkel, unter dem
beschrieben auf einer separaten Plajeden Motor gibt es also zwei Steuerdie Kraft der Erdbeschleunigung wirkt.
tine untergebracht.
signale und eine H-Brückenschaltung.
Der Beschleunigungssensor funktioDie im Blockschaltbild angegebenen
Jede H-Brücke besteht aus zwei Halbniert somit als Winkelsensor und lieFunktionsgruppen lassen sich relabrücken-Treiber-ICs vom Typ IR2184
fert einen Wert proportional zum Neitiv leicht indentifizieren. Im Mittelgungswinkel der Plattform.
punkt steht der mit 16 MHz getaktete
Um eine bestmögliche Stabilisierung
ATmega32, der über eine 10-polige
zu erreichen, ist es erforderlich, zu
Programmierschnittstelle (ISP-ConBild 3. Die Schaltung der Hauptplatine umfasst die gesamte
Steuerung inklusive Leistungselektronik.
jedem Zeitpunkt den exakten Winkel
nector K4) verfügt und die drei LEDs
10
VDD
VDD
GND
GND
GND
GND
GND
GND
VDD
VCC
elektor - 7-8/2009
+15V
C7
4u7
100V
+24V-BATT
C3
D1
1N4936
+5V
C26
IC8
14
C27
1
IC9
100n
100n
7
IN
4u7
100V
1N4936
8
IC3
IR2184
MA+
R25
K5
T6
4R7
MOTOR A–
MA–
IN
IC8.D
≥1
13
IR2184
LO
SD
≥1
13
2x
IRF1405
11
3
IC8.A 3
≥1
IC9.D
12
6
≥1
5
2
IC8.C
8
10
≥1
9
4k7
+15V
C4
C1
D3
4u7
100V
1N4936
VB
IN
2
1u 63V
HO
R29
K6
T2
4R7
USHUNT
6
8
+5V
+5V
C22
R12
100n
IC10
10k
1
100n
3
5
CURRFLAG
8
VCC
PB5(RESET)
PB3(ADC3)
PB4(ADC2)
PB1(MISO)
PB0(MOSI)
PB2(SCK)
IC6
7
+5V
10
14
15
16
17
PWM-L
C12
100n
100n
47u
63V
20
CW/CCW-B'
C10
19
CW/CCW-A'
C11
18
PWM-R
150R
21
+5V
R15
+5V
10k
1
2
3
K4
+15V
4
2
GND
8
BATT–
(GND)
9 MISO
ISP
R7
6k8
R6
R8
(SCL)PC0
PD1(TXD)
(SDA)PC1
PD2(INT0)
(TCK)PC2
PD3(INT1)
(TMS)PC3
PD4(OC1B)
(TDO)PC4
PD5(OC1A)
(TDI)PC5
PD6(ICP1)
(TOSC1)PC6
PD7(OC2)
(TOSC2)PC7
IC7
PB0(XCK/T0)
(ADC0)PA0
PB1(T1)
(ADC1)PA1
PB2(INT2/AIN0)
(ADC2)PA2
PB3(OC0/AIN1)
(ADC3)PA3
PB4(SS)
(ADC4)PA4
PB5(MOSI)
(ADC5)PA5
PB6(MISO)
(ADC6)PA6
PB7(SCK)
(ADC7)PA7
AREF
XTAL1
11
13
22
23
24
25
26
27
+5V
28
29
40
K2
UBATT
XTAL2
38
ADXL-Y
37
ADXL-X
36
GYRO-X
GYRO-Y
35
34
C14
33
C20
100n
32
GND
12
K1
39
100n
ATMEGA32-PDIP
RST
GND
R9
AVCC
31
X1
FOOTDETECT
K3
AREF
C21
4u7
63V
100n
8
9
4k7
R4
2k2
C30
7 SCK
10
R5
3
7
30
VCC
PD0(RXD)
240R
4u7
100V
6
5 RST
240R
1
3
240R
ADJ
C25
5
6
R2
100k
10k
MIC2941
5
1 MOSI
4
IC11
C15
100n
6
4
ATTINY25PDIP
15R
C28
100n
2
GND
7805
1
10
≥1
9
C13
SHTDWN
IC9.A 3
IC9.C
UBATT
68k
OUT
3
2
4k7
R10
IN
2
≥1
R1
K8
SD
5
100n
2
2
IR2184
LO
2x
IRF1405
C24
R16
R20
COM
GND
R11
1
VS
4
4R7
IN
IC2
LED3 LED2 LED1 C17
100n
C18
27p
16MHz
C19
C16
27p
100n
R14
4k7
POT
R13
4k7
1k
ACS755-SCB
-100
IP–
4
HO
6
R27
T4
VCC
≥1
R17
3
VOUT
R3
MOTOR B–
MB–
3
IC9.B 4
VCC
IC5
(Allegro)
5
MB+
5
VB
COM
IP+
(+24V)
1N4936
7
4R7
MOTOR B+
4
LO
R28
M
4R7
6
IR2184
SD
1
4
4u7
100V
8
VS
4k7
C23
C5
100n
2x
IRF1405
R30
7
IC1
R22
+5V
D4
C36
T3
8
VCC
100n
T1
4k7
5
1
C31
100n
470n
470u 63V
C9
C2
470u 63V
C37
C29
4u7
100V
+24V-BATT
BATT+
1
11
R18
K7
2
COM
3
IC8.B 4
R19
VS
COM
12
1
IC4
4
4R7
VCC
HO
6
R23
T8
5
VB
7
4R7
MOTOR A+
4
LO
SD
R24
M
4R7
6
VS
2
C8
100n
2x
IRF1405
R26
7
HO
R21
4k7
7
VB
D2
C33
T7
8
VCC
100n
T5
4k7
5
14
C34
100n
470n
470u 63V
C6
4u7
100V
IC8, IC9 = 4001N
C35
C32
ENABLE
090248 - 11
7-8/2009 - elektor
11
praxis
e-fahrzeuge
ler vom Typ MIC2941 (IC11) mit 15 V
versorgt. Dieses IC verfügt über einen
Shutdown-Eingang (Pin 2), der mit dem
Enable-Signal der Stromüberwachung
(Pin5 des ATtiny IC10) verbunden ist.
Dieses Signal schaltet bei Überstrom
den Spannungsregler und damit die
Brückentreiber-ICs ab, so dass die
MOSFETs sperren und den Motorstrom
unterbrechen.
Alle anderen ICs erhalten über den
Standard-Regler IC6 ihre Betriebsspannung von +5 V.
Kompakte Baugruppe
Bild 4. Auf der Unterseite des Metallchassis sind die Akkus und der Elektronikblock befestigt.
und vier MOSFETs vom Typ IRF1405.
Für den linken Motor sind dies IC1
und IC2 sowie T1…T4, für den rechten
Motor IC3 und IC4 sowie T5…T8.
Die MOSFET-Brückenschaltungen lie-
gen über den Stromsensor IC5 an der
24-V-Spannung der beiden in Reihe
geschalteten 12-V-AGM-Bleiakkus.
Die Halbbrücken-Treiber-ICs werden
über einen eigenen Spannungsreg-
Der auf der Unterseite der Plattform
(Metall-Chassis Bild 4) montierte
Elektronik-Block (Bild 5) besteht aus
der Hauptplatine mit der aufgesetzten
Sensorplatine.
Die acht MOSFETs befinden sich in
einer Reihe an der Rückseite der Hauptplatine und werden durch einen speziellen Kühlkörper gemeinsam gekühlt.
Der Kühlkörper ist mit der Platine verschraubt und mit den MOSFETs über
Klemmfedern verbunden. Eine selbstklebende Wärmeleitfolie zwischen
den Transistoren und den Kühlkörpern
sorgt für elektrische Isolation.
Die Hauptplatine ist im Gegensatz zur
SMD-bestückten Sensorplatine vollständig mit bedrahteten Bauteilen aufgebaut. Die Platinen-Layouts im PDF-Format stehen wie immer auf der Webseite
zum Projekt [3] als Gratis-Download zur
Verfügung. Dort sind auch die Stücklisten zu den Platinen zu finden.
Software
Die Firmware beider Controller wurde
mit BASCOM-AVR erstellt. Bild 6 gibt
einen Überblick über die wichtigsten
Funktionen der Motorsteuerung, die
im Folgenden noch kurz beschrieben
werden.
Funktion Init:
Initialisierung und Konfiguration von Timer0, Timer1/PWM,
Variablen-Initialisierung,
Kalibrierung für Gyroskop,
Beschleunigungssensor und
Lenkstangenpotentiometer.
Bild 5. Die kompakte Elektronik besteht aus der Hauptplatine mit Kühlkörper und aufgesetzter Sensorplatine.
12
Funktion Get_Angle:
Die Funktion liest die Werte der A/DKanäle (Gyro, ADXL320, Poti, Akkuspannung, Fußtaster).
Für Gyro, ADXL320 und Akkuspannung werden die Werte über
einen Zeitraum von 50 Durchläufen
integriert.
elektor - 7-8/2009
7-8/2009 - elektor
13
praxis
e-fahrzeuge
Winkelrate(Angle_Rate) und absoluter Winkel(Tilt_angle) werden
berechnet.
Poti-Stellung wird ausgelesen.
Function Init
Funktion Filter:
Berechnet nötige Differenzbeschleunigung der Motoren (Balance_Diff),
berechnet die Motorgesamtgeschwindigkeit (Drive_Speed).
-Variableninitialisierung
-Timer0 für Interrupt konfigurieren
-Timer1 als PWM konfigurieren
-Kalibrierungswerte lesen
-Interrupt aktivieren
Funktion process:
Berechnet auf Basis von Geschwindigkeit und Potistellung/Lenkstange
die Geschwindigkeitsanpassung der
Motoren, um eine entsprechende
Lenkbewegung zu erhalten. Prüft, ob
vom ATtiny eine „Überstromsituation“ gemeldet wurde und verringert
entsprechend die Motorgeschwindigkeit (Drive_speed). Signalisiert
durch Blinken der LEDs eine Warnmeldung („Überstromsituation“ oder
„Fußtaster-Alarm“).
Ruft die Funktion Get_speed_batt
auf.
Hauptroutine
Funktion Get_Speed_Batt:
Setzt eine zusätzliche
Winkelkorrektur(Angle_Correction)
beim Überschreiten der maximalen
Geschwindigkeit und setzt entsprechend der Akkuspannung die 3 LEDs.
Funktion PWM_OUT:
Setzt entsprechend der Beschleunigung für Motor A und Motor B die
PWM-Ausgänge und schaltet die
Ausgänge für die Drehrichtung der
Motoren.
Die Funktion begrenzt auch die maximale Leistung (PWM_MAX).
Funktion interrupt:
Wird vom Timer0 100 Mal pro
Sekunde aufgerufen, ruft die Funktionen Get_Angle, Filter, Process und
PWM_out auf.
Mechanik
Für die weniger elektronische Seite
des ElektorWheelies ist der zweite und
letzte Teil der Projektveröffentlichung
vorgesehen. Neben der Beschreibung
der mechanischen Konstruktion geben
wir auch einen Überblick über den
Zusammenbau und die Verdrahtung
und natürlich auch einige Tipps für
die Inbetriebnahme und Ideen für die
Praxis.
Mehr Informationen zum
ElektorWheelie-Kit:
www.elektor.de/wheelie
14
(090248)
Nichts zu tun, passiert alles in
der Interrupt-Routine....
Function Get_Angle
Function Interrupt
-AD-Channels lesen
-Winkelrate und Winkel berechnen
-Gyro-Wert integrieren
-ADXL-Wert integrieren
Interrupt deaktivieren
gosub Get_Angle
gosub Filter
gosub Process
gosub PWM_Out
Function Filter
Interrupt aktivieren
-Balancemoment berechnen
-Drive_Speed berechnen
Function Process
-Lenkbewegung berechnen
-Motorgeschwindigkeit berechnen
-Stromflag prüfen
-gosub Get_speed_batt
Function Get_speed_batt
Geschwindigkeit
& gt;
max_speed?
Ja
Winkelkorrektur aktivieren
Nein
Winkelkorrektur deaktivieren
Batteriestatus anzeigen
090248 - 14
Bild 6. Funktionen der Steuerungssoftware.
Warn-Hinweis und Enthaftungs-Klausel:
• Der ElektorWheelie ist ein „Open Development“ (eine offene Entwicklung). Der Käufer ist frei
in der Ausführung und kann Änderungen und Modifikationen der Hardware und Software des
ElektorWheelie-Kits vornehmen.
• Für die Verwendung des ElektorWheelie auf öffentlichen Wegen und/oder öffentlichen
Plätzen gelten nationale Gesetze sowie nationale und lokale Verordnungen und Bestimmungen. Es wurden keine Musterzulassungen beantragt. Eigentümer und Betreiber müssen für die
Verwendung außerhalb von eigenen privaten Grundstücken (oder privaten Grundstücken mit
Zustimmung des Grundstückseigentümers) die betreffenden nationalen und lokalen Bestimmungen beachten. Elektor kann hierfür keine Verantwortung übernehmen!
• Unter der Bedingung eines „Open Development“ (einer offenen Entwicklung) kann Elektor
International Media beziehungsweise die Elektor-Verlag GmbH für sämtliche Schäden und
Verletzungen, die durch den ElektorWheelie und seine Verwendung entstehen, keine Verantwortung übernehmen.
elektor - 7-8/2009
Wykaz elementówRezystoryR1,R6,R13,R14,R18...R22 = 4k7R2 = 100 k R3,R11,R15 = 10 kR4 = 2k2R5 = 6k8 R7...R9 = 240 OhmR10 = 68 kR12 = 15 OhmR16 = 150 Ohm (2 W)R17 = 1 k R23...R30 = 4,7 Ohm KondensatoryC1...C3 = 470 u/ 63 VC4...C9,C25 = 4u7/100 VC10,C21 = 47 u/63 V C11...C17,C20,C22,C24,C26..C34,C36 = 100 n C18,C19 = 25 pC23 = 1 u/63 VC35,C37 = 470 nDiody układyD1...D4 = 1N4936IC1...IC4 = IR2184 (International Rectifier)T1...T8 = IRF1405 (International Rectifier)IC5 = ACS755 SCB-100 (Allegro Microsystems)IC6 = 7805IC7 = ATMEGA32 PDIP (Atmel)IC8,IC9 = 4001N IC10 = ATTINY25-PDIP (Atmel)IC11 = MIC2941 (Micrel)LED1 = LED, 3mm, grünLED2 = LED, 3mm, gelb LED3 = LED, 3mm, rot PozostałeX1 = 16-MHz-Quarz K1,K2 = Buchsenleiste, 5-mm-hoch, 2,54-mm-RasterK3 = Stiftleiste 5 pol., 2,54-mm-Raster K4 = Stiftleiste 2x5 pol., 2,54-mm-Raster MA,MB = Anschlussklemme 2 pol., 6,35-mm-Raster
projects
electric vehicle
ElektorWheelie
The electronics behind
a rather special kind
of vehicle
Chris Krohne (Germany)
In this first article describing our DIY self-balancing single-axle vehicle we look at the electronics
modules. An ATmega32 processes the controls and sensor data and drives the two electric motors via
power driver stages. It keeps the vehicle balanced and can drive it in any desired direction at any
desired speed from stationary to about 11 mph.
The electronics in the ElektorWheelie
processes input signals from a control
potentiometer, an acceleration sensor and an inclination sensor. It con-
trols the magnitude and direction of
the torque applied to the wheels via
two motors using PWM signals and
MOSFET drivers. The sensors provide
Characteristics
•
•
•
•
•
•
•
•
•
•
66
Two 500 W DC drive motors
Two 12 V lead-acid AGM batteries, 9 Ah
Two fourteen-inch wheels with pneumatic tyres
H-bridge PWM motor control up to 25 A
Automatic power off on dismount
Fail-safe emergency cutout
Battery charge status indicator
Maximum speed approx. 11 mph (18 km/h)
Range approximately 5 miles (8 km)
Weight approximately 35 kg
enough information to allow the vehicle to maintain its balance over its full
range of speeds, and it can even spin
on the spot.
Sensors:
• Invensense IDG300 (or IDG500) gyroscope
• Analog Devices ADXL320 accelerometer
• Allegro ACS755SCB-100 current sensor
Microcontrollers:
• ATmega16 (motor control)
• ATtiny25 (current monitoring)
Compiler:
• BASCOM-AVR Basic compiler
elektor - 7-8/2009
A delicate balance
For the vehicle to be able to balance successfully it is essential that the sensors provide reliable information about the inclination of the platform
and its angular velocity. This is in addition, of course, to ensuring that the control system, motor drivers and motors themselves are properly
designed.
Balancing itself is relatively straightforward. If the rider leans forwards the platform tilts and the motors are driven so as to bring the whole system (vehicle plus rider) back towards balance. That means that the rider’s feet are pushed forwards under the centre of gravity of the whole system, opposing the rider’s leaning and reducing the tilt angle.
The system therefore tilts as a whole, which requires both a strong mechanical construction and a carefully designed and experimentally tested
filter function. The damping characteristic of the filter is set just short of the point where the system starts to become unstable.
Steering is performed by applying differential acceleration or braking to the two motors. Note that at higher speeds the tightness of the turning
circle has to be limited. In the ElektorWheelie the limit is set so that the rider cannot overturn the vehicle by trying to change direction suddenly.
No motor has an infinite amount of power. In the case of the ElektorWheelie there is the potential for serious consequences for the rider if a motor does not have enough power headroom to allow for balance to be maintained. For this reason the motors are normally only driven up to
approximately 70 % of their maximum power. This keeps a little in reserve so that, when top speed is reached, the wheels can be given a small
extra acceleration. This throws the rider back slightly, which automatically leads to a reduction in speed. Leaning back slows the vehicle down,
leaning forwards speeds it up.
The drive train is based on two
500 watt DC electric motors, with
power being provided by two 12 V
AGM (absorbed glass mat) lead-acid
batteries. Most of the electronics is
located on a control board, with a sensor board mounted on it.
The control system uses dynamic stabilisation. The vehicle senses the attitude of its platform in an analogous
way to the human sense of balance. If
the platform starts to tilt forwards or
backwards, the vehicle makes a proportional acceleration to oppose the
tilt using both motors. By applying
different amounts of drive to the two
motors, the vehicle can turn.
In normal operation the ATtiny25 will
also notify the ATmega32 when the
motor current exceeds a preset value
of around 25 A, which will cause the
2x 12V 9 Ah
AGM-Lead battery
emergency
stop breaker
current sensor
Block diagram
Central in the block diagram of the
attitude control and motor drive
unit shown in Figure 1 is an Atmel
ATmega32 microcontroller. This has
two PWM outputs that are used to
drive the two 24 V DC motors via a
pair of MOSFET H-bridges. A second
microcontroller, an Atmel ATtiny25 this
time, monitors the motor current using
a Hall effect sensor. If an excessive current (over 80 A) should flow because
of a short circuit in the system, the
ATtiny25 interrupts the 15 V power
supply to the H-bridge driver circuitry
using the shutdown input of its regulator. In the event of a total failure of the
control electronics the battery current
can also be interrupted using a purely
electromechanical emergency stop
device, providing the ultimate protection against the vehicle running out of
control.
7-8/2009 - elektor
controller to attempt to reduce the current by limiting the range of the PWM
control signals.
The ATmega32 receives sensor inputs
ATtiny25
footswitch
battery
indicator
power H-bridge
24V DC
Motor A
PWM OC1B
power H-bridge
24V DC
Motor B
ATmega32
ADC
Invensense
gyroscope
voltage regulator
15V
with
‘enable pin’
PWM OC1A
voltage regulator
5V
ADXL320
accelerometer
pot / handlebar
090248 - 13
Figure 1. Block diagram of the motor controller.
67
projects
electric vehicle
nector K4 and to the
three LEDs, LED1 to
LED3, that show the
VCC
14
29
34
battery status.
K2
K1
The sensor board is
AREF (3V)
IC1
32
17
connected to K2 on
VREF
CPOUT
R3
the control board. The
28
23
Y-RATE OUT
YAGC
75R
GYRO-Y
IDG-300
X-axis and Y-axis outGYRO-X
R4
3
8
X-RATE OUT
XAGC
75R
ADXL-X
puts of the sensors
ADXL-Y
are connected to A/
D conver ter inputs
2 22 25 38 39 40
C11
C12
C9
C2
C10
ADC2 to ADC5 on
+5V
1u
1u
220n 220n 100n
the ATmega32, and
pin 32 (AREF) is fed
VCC
+5V
with 3 V from the voltage regulator on the
IC3
1
5
VIN
VOUT
sensor board. The 3 V
LP2980
3
supply is also taken
ON/OFF
2
to K3 where it pro14
15
VCC
VS
VS
vides power to the
10
IC2 YOUT
steering potentiomeADXL320
12
ter. The wiper of this
XOUT
C1
C14
C15
C16
COM
ST
C4
C3
potentiometer thus
2µ2
2
3 5 6 7
100n 100n 4u7
16V
2n2
2n2
6V
provides a voltage to
090248 - 12
analogue input ADC6
on the ATmega32
that depends on the
Figure 2. Circuit diagram of the sensor board with gyroscope and accelerometer.
position of the steering control. Analogue
input ADC0 measures the battery
is important to determine the attitude
voltage via the voltage divider comof the platform as accurately as posprising R10 and R11, and ADC7 monisible at each instant in time. The outSensors and stabilisation
tors the position of the footswitch via
put of the accelerometer is therefore
The attitude sensors are mounted on
K3. The fault detection signal (CURRintegrated over a relatively long time
their own small printed circuit board
period to obtain a smoothed signal. To
FLAG) is taken to pin 16 (INT0) of the
that plugs into the main control board.
ATmega32 from the ATtiny25 current
this smoothed result is added the outFigure 2 shows the circuit of the senmonitor IC10, which in turn is conput of the gyroscope, in proportions
sor board, which includes an Invennected to current sensor IC5. IC5 is an
that have been empirically optimised.
integrated Hall effect sensor from AlleThe acceleration signal delivered to
sense IDG300 [1] two-axis gyroscope
gro Microsystems offering linear operthe motor controller is calculated as a
and an Analog Devices ADXL320 [2]
two-axis accelerometer. Voltage regpreset linear combination of the attiation up to 100 A. CURRFLAG is set
if the current reaches approximately
tude error (the difference between the
ulator IC3 provides the required 3 V
supply for the sensors; this voltage
actual inclination angle and the tar25 A and causes the motor current to
also serves as the reference voltage
be limited by bounding the range of
get inclination angle) and the angular
for the ATmega32’s A/D converter on
velocity with which the platform is tipthe PWM drive signal.
the main board.
ping. In essence, the greater the attiWe now turn to the output signals of
The output of the gyroscope is a volttude error and the greater the angular
the ATmega32. The result of processage proportional to the rate at which
velocity, the greater the motor acceling the various inputs to the microconit is turning (its angular velocity). If
eration required for stabilisation.
troller appear as the signals on the four
the platform is tipping rapidly there
outputs PWM-L, PWM-R, CW/CCW-A
will be a large and rapid swing in the
and CW/CCW-B, on pins 18 to 21. CW/
Motor control
gyroscope’s output voltage. When staCCW-A and CW/CCW-B are logically
tionary the output voltage of the gyroThe circuit diagram of the main printed
combined with the PWM outputs PWMscope is approximately half its supply
circuit board in Figure 3 contains all
L and PWM-R in IC8 and IC9 is such
voltage.
of the control circuitry of the Elektora way that they determine the direcThe accelerometer measures the comWheelie, including the power driver
tion of rotation of the motors, while the
ponent of the acceleration due to
stages. Only the attitude sensors, as
PWM signals control the current delivgravity in its own plane. If the senmentioned above, are mounted on a
ered to the motors via the H-bridges.
sor is tilted this will affect the angle
separate board.
Each motor thus has two control sigat which gravity acts relative to the
It is fairly easy to identify the comnals and a complete H-bridge driver,
device, which therefore operates as an
ponents corresponding to the variinclination sensor, delivering an outous parts of the block diagram. In the
put depending on the attitude of the
centre is the ATmega32, clocked at
platform.
16 MHz. It is directly connected to 10Figure 3. Circuit diagram of the main board,
To obtain the best possible stability it
way in-system programming (ISP) conincluding control and power electronics.
68
VDD
VDD
GND
GND
GND
GND
GND
VDD
VCC
GND
using its ADC (analogue-todigital converter) from the
gyroscope and the accelerometer on the sensor board
and from the high-reliability potentiometer that is
mechanically connected to
the steering control of the
ElektorWheelie. The ADC
inputs are sampled around
100 times per second.
As a further safety feature a footswitch is connected to an input of the
ATmega32. If this switch
is not held down (because
the rider has dismounted)
the microcontroller will
interrupt the motor current
after two seconds. This
also helps to prevent the
vehicle from running away
on its own.
The batter y voltage is
also monitored by the
ATmega32 using its ADC,
and used to drive three
LEDs that indicate the
remaining available running time to the rider.
elektor - 7-8/2009
+15V
C7
4u7
100V
+24V-BATT
C3
D1
1N4936
+5V
C26
IC8
14
C27
1
IC9
100n
100n
7
IN
4u7
100V
1N4936
8
IC3
IR2184
MA+
R25
K5
T6
4R7
MOTOR A–
MA–
IN
IC8.D
≥1
13
IR2184
LO
SD
≥1
13
2x
IRF1405
11
3
IC8.A 3
≥1
IC9.D
12
6
≥1
5
2
IC8.C
8
10
≥1
9
4k7
+15V
C4
C1
D3
4u7
100V
1N4936
VB
IN
2
1u 63V
HO
R29
K6
T2
4R7
USHUNT
6
8
+5V
+5V
C22
R12
100n
IC10
10k
1
100n
3
5
CURRFLAG
8
VCC
PB5(RESET)
PB3(ADC3)
PB4(ADC2)
PB1(MISO)
PB0(MOSI)
PB2(SCK)
IC6
7
+5V
10
14
15
16
17
PWM-L
C12
100n
100n
47u
63V
20
CW/CCW-B'
C10
19
CW/CCW-A'
C11
18
PWM-R
150R
21
+5V
R15
+5V
10k
1
2
3
K4
+15V
4
2
GND
8
BATT–
(GND)
9 MISO
ISP
R7
6k8
R6
R8
(SCL)PC0
PD1(TXD)
(SDA)PC1
PD2(INT0)
(TCK)PC2
PD3(INT1)
(TMS)PC3
PD4(OC1B)
(TDO)PC4
PD5(OC1A)
(TDI)PC5
PD6(ICP1)
(TOSC1)PC6
PD7(OC2)
(TOSC2)PC7
IC7
PB0(XCK/T0)
(ADC0)PA0
PB1(T1)
(ADC1)PA1
PB2(INT2/AIN0)
(ADC2)PA2
PB3(OC0/AIN1)
(ADC3)PA3
PB4(SS)
(ADC4)PA4
PB5(MOSI)
(ADC5)PA5
PB6(MISO)
(ADC6)PA6
PB7(SCK)
(ADC7)PA7
AREF
XTAL1
11
13
22
23
24
25
26
27
+5V
28
29
40
K2
UBATT
XTAL2
38
ADXL-Y
37
ADXL-X
36
GYRO-X
GYRO-Y
35
34
C14
33
C20
100n
32
GND
12
K1
39
100n
ATMEGA32-PDIP
RST
GND
R9
AVCC
31
X1
FOOTDETECT
K3
AREF
C21
4u7
63V
100n
8
9
4k7
R4
2k2
C30
7 SCK
10
R5
3
7
30
VCC
PD0(RXD)
240R
4u7
100V
6
5 RST
240R
1
3
240R
ADJ
C25
5
6
R2
100k
10k
MIC2941
5
1 MOSI
4
IC11
C15
100n
6
4
ATTINY25PDIP
15R
C28
100n
2
GND
7805
1
10
≥1
9
C13
SHTDWN
IC9.A 3
IC9.C
UBATT
68k
OUT
3
2
4k7
R10
IN
2
≥1
R1
K8
SD
5
100n
2
2
IR2184
LO
2x
IRF1405
C24
R16
R20
COM
GND
R11
1
VS
4
4R7
IN
IC2
LED3 LED2 LED1 C17
100n
C18
27p
16MHz
C19
C16
27p
100n
R14
4k7
POT
R13
4k7
1k
ACS755-SCB
-100
IP–
4
HO
6
R27
T4
VCC
≥1
R17
3
VOUT
R3
MOTOR B–
MB–
3
IC9.B 4
VCC
IC5
(Allegro)
5
MB+
5
VB
COM
IP+
(+24V)
1N4936
7
4R7
MOTOR B+
4
LO
R28
M
4R7
6
IR2184
SD
1
4
4u7
100V
8
VS
4k7
C23
C5
100n
2x
IRF1405
R30
7
IC1
R22
+5V
D4
C36
T3
8
VCC
100n
T1
4k7
5
1
C31
100n
470n
470u 63V
C9
C2
470u 63V
C37
C29
4u7
100V
+24V-BATT
BATT+
1
11
R18
K7
2
COM
3
IC8.B 4
R19
VS
COM
12
1
IC4
4
4R7
VCC
HO
6
R23
T8
5
VB
7
4R7
MOTOR A+
4
LO
SD
R24
M
4R7
6
VS
2
C8
100n
2x
IRF1405
R26
7
HO
R21
4k7
7
VB
D2
C33
T7
8
VCC
100n
T5
4k7
5
14
C34
100n
470n
470u 63V
C6
4u7
100V
IC8, IC9 = 4001N
C35
C32
ENABLE
090248 - 11
7-8/2009 - elektor
69
projects
electric vehicle
the two lead-acid AGM batteries in
series via current sensor IC5.
The half-bridge driver ICs receive their
own 15 V supply from the MIC2941
voltage regulator IC11. This IC has
a shutdown input (pin 2) that is connected to the ‘enable’ output signal
from the current monitoring circuit
(pin 5 on IC10). When excess current
is detected this signal shuts down the
regulator and hence also the bridge
driver ICs. The MOSFETs then block
and the motor current is interrupted.
All the other ICs are powered with 5 V
from IC6, a standard regulator.
A compact module
Figure 4. The batteries and electronics module are mounted on the underside of the metal chassis.
and each H-bridge is composed of two
half-bridge driver ICs type IR2184 and
four IRF4105 MOSFETs. The left wheel
motor is driven by IC1, IC2 and T1
to T4, while the right wheel motor is
driven by IC3, IC4 and T5 to T8.
The MOSFET bridge circuits are powered from the 24 V supply derived from
Figure 4 shows the metal chassis of
the vehicle. The electronics module
(Figure 5), comprising the main board
(Figure 6) and the sensor daughter
board (Figure 7) is mounted on the
underside of the platform.
The eight MOSFETs are positioned
in a row on the reverse of the main
board and are cooled using a speciallydesigned common heatsink. The heatsink is bolted to the printed circuit
board and the MOSFETs are held on to
the heatsink using spring clips. A selfadhesive thermally conductive sheet
between the MOSFETs and the heatsink provides electrical isolation.
The main board contains only leaded
devices, in contrast to the SMD-populated sensor board. The printed circuit
board layouts are as usual available
for free download from the project web
pages [3] as PDFs, along with associated parts lists.
Software
The firmware for the two microcontrollers was written using BASCOM-AVR.
Figure 8 gives an overview of the main
functions involved in controlling the
motors, which will be described briefly
below.
Function Init:
This function initialises and configures
Timer0, Timer1 and the PWM outputs,
initialises variables and calibrates the
gyroscope, accelerometer and steering
potentiometer.
Figure 5. The compact electronics module comprises the main board with heatsink and sensor daughter board.
70
Function Get_Angle:
This function reads values from the
analogue inputs (gyroscope, ADXL320,
potentiometer, battery voltage and
footswitch). The gyroscope, ADXL320
and battery voltage readings are integrated over a period of fifty samples.
elektor - 7-8/2009
Then the angular velocity (Angle_Rate)
and absolute angle (Tilt_angle) are
calculated.
Function Filter:
This function calculates the change
in acceleration required of the motors
(Balance_Diff) and the overall motor
speed (Drive_Speed).
Function Process:
This function uses the current speed
and the position of the steering control
to calculate the necessary modification
to the speed of the motors to turn the
vehicle as requested. It checks to see if
the ATtiny25 has reported an overcurrent condition and reduces the motor
speed (Drive_speed) if needed. The
overcurrent condition and footswitch
alarm states are indicated by the LEDs
flashing.
The function calls Get_speed_batt.
Function Init
- variable initialization
- configure Timer0 for interrupt
- configure Timer1 as PWM
- read calibration values
- activate interrupt
Main routine
Idling… everything taking place
in the interrupt routine …
Function Get_Angle
Function Interrupt
- read A/D channels
- calculate angular rate and angle
- integrate gyro value
- integrate ADXL value
Function Get_speed_batt:
This function adds a value Angle_Correction in the case where the maximum speed is exceeded. It also sets
the state of the three LEDs according
to the battery voltage.
gosub Get_Angle
gosub Filter
gosub Process
gosub PWM_Out
Function Filter
Function PWM_Out:
This function configures the PWM
outputs according to the acceleration
required for motors A and B, and sets
the other outputs to reflect the desired
rotation direction.
The function also imposes a limit on the
maximum drive power (PWM_MAX).
deactivate interrupt
- calculate steering movement
- calculate motor speed
- check current flag
- gosub Get_speed_batt
Function interrupt:
This function is called 100 times per
second. In turn it calls Get_Angle, Filter, Process and PWM_Out.
activate interrupt
- calculate balance moment
- calculate Drive_Speed
Function Process
Function Get_speed_batt
speed & gt;
max_speed?
yes
activate angle correction
no
deactivate angle correction
display battery status
090248 - 14
Mechanics
In the second and final part of this
series we will look at the mechanics of
the ElektorWheelie. We will describe
the construction of the vehicle and outline how it is assembled and wired.
Finally we will give a few tips on how
to drive the vehicle and some further
practical suggestions.
(090248-I)
Internet links
[1] http://www.invensense.com/shared/pdf/
DS_IDG300.pdf
[2] http://www.analog.com/static/imported-files/data_sheets/ADXL320.pdf
[3] http://www.elektor.com/090248
7-8/2009 - elektor
Figure 6. Control software functions.
DISCLAIMER & CAUTIONS
• The ElektorWheelie vehicle is an Open Development. The buyer is free
to make changes and modifications to the hardware or software of the
ElektorWheelie kit, at his/her own risk.
• The use of ElektorWheelie on public roads or in public spaces may be illegal
and/or subject to legislation and type approval. No type approval has been
applied for and owners are advised to check local or national legislation for
any use other than on private land, or with the land owner’s permission.
Elektor International media BV accepts no responsibility in this respect
whatsoever.
• Under the terms of an Open Development Elektor International Media
cannot be held liable for any damages, penalties or injuries caused by, or
arising from, the use, ownership or assembly of the ElektorWheelie vehicle.
71
_____ _ _ _ _ _ _ _ _ _
| __| |___| |_| |_ ___ ___ | | | | |_ ___ ___| |_|___
| __| | -_| '_| _| . | _| | | | | | -_| -_| | | -_|
|_____|_|___|_,_|_| |___|_| |_____|_|_|___|___|_|_|___|
(c)2009 Elektor International Media B.V.
----------------------------------------------------------------------------
This archive contains the source code of the Elektor-Wheelie v2.4 firmware and
the current watcher firmware source code. It compiles with BASCOM AVR.
The targets are two Atmel microcontroller, one ATmega32 and one ATtiny25,
both featuring the AVR core.
Under Windows we are using BASCOM-AVR, we have been using v1.11.7.4
but it may work perfectly with other software versions, this information is only
informative.
The Intel HEX binary file are the compiled firmware you can use directly or as a reference.
They can be flashed with any Atmel compatible ISP tools.
projects
elektorwheelie
ElektorWheelie
Construction and driving
In the first instalment about the self-balancing single-axle electric ‘vehicle’ in the Summer
Circuits issue we explained the operation of the electronics. There is, of course, also some
mechanical construction required before the ElektorWheelie is ready to be used.
The ElektorWheelie is delivered as a kit containing all the necessary parts. The kit contains all electronic bits, the batteries,
the steel housing, the wheels, the motors, the control lever and
an economy battery charger. The printed circuit board comes
completely assembled and ready mounted in the housing, just
like the motors. In this article, with the help of a few photographs, we describe what remains to be done by you.
DIY tinkering
1. The main things you have to do yourself is mounting the
control lever and attaching the wheels.
2. We start with the control lever. For this you need the
64
brackets/bearing mounts and four bolts with matching
washers and nuts.
3. The mounting brackets/bearing mounts are attached
with the bolts to the middle of the base plate (between
the motors). The housing already has the mounting holes
for these. Tighten the bolts firmly so that they cannot come
loose due to vibrations.
4. Now you need to attach the coupling between the control
lever and the potentiometer. Start by adjusting the potentiometer to roughly the centre position. Make sure there is
sufficient free movement clockwise as well as anti-clockwise because the pot is used to determine the position of
the control lever.
elektor - 9/2009
5. Now turn to the cabling. The wiring diagram shows
the electrical connections effectively made. Note that some
cables may be a bit short for the next step and should be
connected afterwards.
6. You can now slide the cover at an angle over the control
lever and fasten it at the sides with four screws. After this you
attach the wheels and the two remaining parts of the control
lever. Make sure the large wheel nuts are fastened securely!
As already mentioned, the kit is supplied with a simple
charger. A complete battery charging cycle takes about
16 hours. An improved charger based on an earlier Elektor design is described elsewhere in this issue. This circuit
ensures that the batteries can be charged independently so
no imbalance can occur in respect of individual capacity.
Before the first trip it is a good idea to test whether the
ElektorWheelie functions properly. To do this, place the
Wheelie on a crate or box with the wheels off the ground.
Turn the Wheelie on and check whether it responds correctly to tilting forwards and backwards. Also check the
operation of the control lever.
The first trip
To allow you to drive the ElektorWheelie, you first need
to insert the double pin of the Safety Switch. The electronics can now be turned on with the Main Switch. Hold the
Wheelie upright, in the position in which you will drive it
(base plate as horizontal as possible). The electronics will
calibrate itself in this position and will attempt to maintain
this position when you are driving the Wheelie.
Now place your right foot on the Foot Switch built into the
9/2009 - elektor
base plate. This switch lets the electronics know that you have
stepped onto the Wheelie. You can now test the Wheelie by
leaning forwards or backwards a little and check whether the
Wheelie moves with it. The foot switch is part of the safety
for the Wheelie, a little more about that later.
Now put your other foot on the ElektorWheelie platform. It
is important that you stand fully upright and not bend your
knees! It also helps if you look straight ahead, not down.
You accelerate by moving your weight towards your toes.
Don’t push against the control lever, that doesn’t work well.
To slow down you move your weight towards your heels.
The electronics in the vehicle ensures that you will remain
balanced and that you can remain standing on the balancing two-wheeler as demonstrated in the ElektorWheelie
video on YouTube.
Steering is done with the control lever. Push it to the left
slightly and the left motor will turn a little slower, so that the
Wheelie will make a left turn. A small deflection to the right
and the Wheelie will veer to the right.
When the rider is no longer standing on the base plate, the
current to the motors is interrupted after a short delay (hysteresis), so that the Wheelie will not carry on and decide
for itself where to go. As an additional safety feature the
ElektorWheelie is fitted with an emergency stop (Safety
Switch). This works as follows: A pin is attached with a
cord to a strap around your arm. Should you fall unexpectedly then the pin will be pulled out by the cord, causing the
motors and electronics to be switched off instantly.
Tips
Make the first trip with the assistance of someone else! All
65
projects
elektorwheelie
sorts of things can go wrong. Helmet, knee and elbow protection are certainly recommended initially.
The software controlling the ElektorWheelie vehicle is
‘open’. That means that you can adapt and change the
firmware to your heart’s content, but at your own risk. However, the supplied software has passed thorough testing and
has had extensive development and is therefore very suitable without any further changes.
You are also invited to visit the ElektorWheelie forum on our
website at www.elektor.com/forum. There you can discuss
and gather ideas about the software and the hardware and,
of course, share your experiences with other Elektor readers.
(090249-I)
Notice
This article provides a brief overview of the assembly of a preproduction sample. Each ElektorWheelie kit supplied to customers
comes with an extensive construction manual. A pdf file of the manual will be available as a free download from www.elektor.com/
wheelie in due course. Photos, videos and impressions may be
found in the ElektorWheelie blog at http://ewheelie.blogspot.com.
MB
MA
Motor Left
Motor Right
Safety
Switch
O - I
Fuse
Main
Switch
Steering
Foot Switch
The wiring diagram
shows how all the parts are
to be connected together.
Pay careful attention
to the polarity of the
batteries and the
connections to the motors
(do not swap left and right).
66
12V
XLR
2
12V
1
3
Battery
Battery
090249 - 11
elektor - 9/2009
technik
e-fahrzeug
ZZZZOOM…
Hier kommt der ElektorWheelie!
Es muss ja nicht immer ein Prius sein, elektrisches
Fahrvergnügen gibt es auch eine Nummer kleiner.
Open-Air-Feeling wie beim Cabrio, eine Kurvenlage wie
bei einer 500er (na ja fast) – die neidischen Blicke der
Nachbarn und Bekannten sind dem Fahrer jedenfalls
sicher. Zwei kräftige Motoren, zwei Akkus, zwei Sensoren
und nicht zuletzt zwei kleine, aber leistungsfähige AVRMikrocontroller – fertig ist der ElektorWheelie!
ANTRIEB
Zwei bärenstarke 24-V-Gleichstrommotoren
beschleunigen den ElektorWheelie bis auf eine
Maximalgeschwindigkeit von 18 km/h. Die
Gesamtleistung von bis zu einem Kilowatt wird dabei
über ein Getriebe (rund 1: 7) auf die Achse gegeben.
Luftgefüllte 16-Zoll-Gummireifen sorgen für einen guten
Komfort und ein sicheres Fahren – sowohl draußen als
auch in Innenräumen.
AKKUS
Als Energiespeicher kommen zwei 12-V-Blei-Gel-Akkus
des deutschen Herstellers CTM zum Einsatz. Bei unserem
Prototypen haben wir die 12-Ah-Variante verwendet,
doch auch mit 9-Ah-Akkus kommt man recht weit. Je
nach Fahrweise kann man immerhin eine bis anderthalb
Stunden fahren, ehe der ElektorWheelie über die bequem
erreichbare Ladebuchse wieder aufgeladen werden muss.
18
elektor - 6/2009
Scho
n
A
E
mit d jetzt se usgabe lektorW
Au
i ver
n (El
h
em e
ekto eelie g Informa sführlic
in so raten:
h
ibt ’s
r 7-8
t
lche
/200
in d ionen zu e
s Ge Elektor
en
9
m
w
fähr
t in ird eine und Elek nächste
ein p
n Ba
n
tor 9
aar
u
Stun satz an /2009
den
b
mon ieten,
tiert
ist!
STEUERUNG
Wir haben es alle selbst ausprobiert: Das einachsige
Gefährt hält sich nahezu von selbst in der Balance.
Ein zweiachsiger Beschleunigungssensor von Analog
Devices und ein Gyro des Herstellers Invensense dienen
als Sensoren. Die Messwerte werden rund 100 Mal pro
Sekunde an einen ATmega32 gemeldet, der die Neigung
des ElektorWheelies ständig nachjustiert.
Von diesem Mikrocontroller werden auch die Befehle
des Steuerungshebels verarbeitet. Ein leichtes Vor und
Zurück, und der ElektorWheelie setzt sich vorwärts
oder rückwärts in Bewegung. Schwenkt man den
Steuerungshebel nach links oder rechts, ändert das
Elektro-Gefährt sanft die Richtung. Sogar das Umdrehen
auf der Stelle ist kein Problem!
SOFTWARE
Zur Lageregelung und Motorsteuerung wird ein
Mikrocontroller ATmega32 eingesetzt. Assistiert wird
er von einem kleinen ATtiny25, der den Motorstrom
überwacht. Die beiden AVR-Controller sind in BASCOM
programmiert. Die Programme sind ausgefeilt, aber von
überschaubarer Komplexität: Zusammen sind es knapp
800 Codezeilen.
MECHANIK
Der Fahrer steht auf einem stabilen Metallchassis, an
dem auch die Akkus und der kompakte Elektronikblock
befestigt sind. Nach unten wird das Ganze von einem
Metallgehäuse geschützt. Natürlich wurde auch an die
Sicherheit gedacht – ein Notschalter unterbricht im Fall
eines Falles sofort den Strom zwischen den Akkus und
Motoren.
6/2009 - elektor
19
non reflected
reflected
reflected
non reflected
reflected
projects
e-vehicle
ElektorWheelie
Elektor’s DIY self-balancing vehicle
Everyone agrees; the internal combustion engine is
coming to the end of its life cycle. However you don’t need
to go to the expense of a Prius or Tesla to experience
the future of transportation devices. If you would prefer
something more personal (and don’t mind turning a few
heads) why not build the astonishing ElektorWheelie?
First take two electric motors, two rechargeable batteries
and two sensors, now add two microcontrollers and the
ElektorWheelie is ready to transport you in style to your
destination.
The power train
Two sturdy 24 V DC electric motors power the
ElektorWheelie up to a maximum speed of 12 km/h
(7.5 mph). A combined power of up to 1 kW is delivered to
the two axles via a reduction (approximately 1:6) gearbox.
Two 16-inch air-filled road wheels ensure good ride
comfort and stability for both indoor and outdoor use.
Power source
Energy for the personal transporter is supplied by two
12 V rechargeable lead-acid gel cells from CTM in China.
Our prototype uses the 9 Ah variant but cells with 7 Ah
capacity also give an acceptable range. The range
depends on your driving style and road gradient. With
a full battery you can expect 1 hour to 1.5 hours of use
before you need to recharge from a power line outlet.
44
elektor - 6/2009
in t
Elek
20
cons
is
All
have that El 09 and he next torWhe
deta truction
ekto
two
Sept
elie
you
ils
iss
rw
wi
em
up a
nd r ill be o ber 20 ues (Ele ll be co of the
n
unn
ing ffering t 09). Wh ktor Jul tained
afte
at w
y/Au
his p
r jus
e
t a f roject a can sa gust
ew h
y
sak
ours
it th now
at w
asse
ill
mbly
time
!
Control
This vehicle which effectively has a single axle can almost
automatically maintain its balance. A 3-axis acceleration
sensor from Analog Devices and a gyro from Invensense
are the only sensors necessary to provide attitude
information to the controller. An ATmega32 samples
the sensor outputs at approximately 100 times a second
and continuously supplies commands to the motors to
maintain the correct inclination of the ElektorWheelie.
It also reads signals from the control lever. Control
is quite intuitive; a light forward pressure sets the
ElektorWheelie gliding ahead, while pulling back moves
it backwards. Left or right pressure changes the direction
of travel correspondingly. It’s wasteful of energy but
rotating on the spot is also no problem!
Software
Calculation of the vehicle’s positional attitude and
motor control are managed by an ATmega32 while
drive motor supply current is monitored by an ATtiny25
microcontroller. Both are programmed in BASCOM.
Despite the software sophistication the program size
ensures that its complexity is quite manageable:
altogether there are just 800 lines of code.
Construction
The driver stands on a rigid metal chassis which houses
the rechargeable cells and compact control electronics
in a protective metal casing. Safety has not been
overlooked; in the event of a fall an emergency switch
disconnects the motors from the batteries.
6/2009 - elektor
45