Carrera Racetrack Experiment Daniel Richter Embedded Operating - - PowerPoint PPT Presentation

carrera racetrack experiment
SMART_READER_LITE
LIVE PREVIEW

Carrera Racetrack Experiment Daniel Richter Embedded Operating - - PowerPoint PPT Presentation

Carrera Racetrack Experiment Daniel Richter Embedded Operating Systems Operating Systems & Middleware Group Carrera Digital 132 2 Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018 Basics lanes (scale


slide-1
SLIDE 1

Carrera Racetrack Experiment

Daniel Richter

Embedded Operating Systems Operating Systems & Middleware Group

slide-2
SLIDE 2

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

2

Carrera Digital 132

slide-3
SLIDE 3

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

3

Basics

▪ lanes (scale 1:24) ▪ car models (scale 1:32) ▪ central control station

▪ Control Unit ▪ Black Box

▪ handset control (cable/wireless)

▪ set the speed ▪ turn the light on/off ▪ change the lane

slide-4
SLIDE 4

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

4

Control Unit & Controllers

slide-5
SLIDE 5

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

5

Our T ask: Change of Control

Race Track Control Unit/ Black Box Handset Control Board Position Sensor Position Sensor Position Sensor Position Sensor Position Sensor Anti-Collision S. Sensor Management Board PC Actuators Sensors (Lane Sensor)

USB USB

slide-6
SLIDE 6

Designing Hardware

Change of Control: Part 1

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018 6

slide-7
SLIDE 7

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

7

Emulation of Handset Controls

Data Format & Block Diagram

slide-8
SLIDE 8

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

8

Emulation of Handset Controls

Printed Circuit Board

8

slide-9
SLIDE 9

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

9

Emulation of Handset Controls

Linearity of D-A-Converters

slide-10
SLIDE 10

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

10

Sensors

Position Sensors

▪ detect the pulsed identification signal of each car ▪ photo sensors

slide-11
SLIDE 11

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

11

Sensors

Position Sensors

slide-12
SLIDE 12

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

12

Sensors

Anti-collision Sensors

▪ deactivates the lane change if another car is within the security region at the other lane ▪ at each switch point

slide-13
SLIDE 13

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

13

Sensors

Lane Sensor

▪ detect the Manchester encoded control signal at the lane ▪ generated by the Control Unit or Black Box

slide-14
SLIDE 14

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

14

Sensors

Sensor Management Board

slide-15
SLIDE 15

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

15

Sensors

Car ID Signal Timing

slide-16
SLIDE 16

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

16

Sensors

Lane Signal Timing

slide-17
SLIDE 17

Writing Firmware for Microcontrollers

Change of Control: Part 2

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018 17

slide-18
SLIDE 18

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

18

AVR XMEGA A3 Microcontroller + Sensor Management Board

An Electrical Engineer’s View

▪ 8/16-bit AVR XMEGA A3 microcontroller

[XMEGA A [MANUAL] 3 8077I–AVR–11/2012]

slide-19
SLIDE 19

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

19

AVR XMEGA A3 Microcontroller + Sensor Management Board

A Software Engineer’s View

Concept: ▪ Ports & Pins

▪ port A…F: 8 pins ▪ port R: 2 pins

[AVRxmegaA3 Datasheet 8068U–AVR–06/2013]

slide-20
SLIDE 20

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

20

AVR XMEGA A3 Microcontroller + Sensor Management Board

Hello World Microcontroller

slide-21
SLIDE 21

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

21

Hello World (Debug Pins)

Scenario

▪ board has 4 pins for debug purposes ▪ turn one pin on and off ▪ oscilloscope output:

Debug Pin 3 Debug Pin 2 Debug Pin 1 Debug Pin 0

slide-22
SLIDE 22

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

22

Hello World (Debug Pins)

Ports & Pins – Debug Pins

slide-23
SLIDE 23

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

23

Hello World (Debug Pins)

Preparation

▪ Atmel Studio 6 (uses Microsoft Visual Studio 2012 Shell) ▪ create project “User Board XMEGA A”, device “ATXmega128A3”

slide-24
SLIDE 24

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

24

Hello World (Debug Pins)

Approach

Approach: ▪ memory mapped IO

▪ ports, port configuration, etc = registers (8 bit)

▪ debug pins: port B, pins 4..7

  • 1. define pins as output

▪ DIR – Data Direction register

  • 2. write to data out register

▪ OUT – Data Output Value register

slide-25
SLIDE 25

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

25

Hello World (Debug Pins)

Port Base Address

[XMEGA A [MANUAL] 3 8077I–AVR–11/2012]

slide-26
SLIDE 26

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

26

Hello World (Debug Pins)

Port Register Offsets

[XMEGA A [MANUAL] 3 8077I–AVR–11/2012]

slide-27
SLIDE 27

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

27

Hello World (Debug Pins)

Code!

#include <asf.h> int main (void) { // define port B’s pins 4..7 as output (*(volatile uint8_t *) 0x0620) |= 0b11110000; while (true) { // turn pin 7 on (*(volatile uint8_t *) 0x0624) |= 0b10000000; // turn pin 7 off (*(volatile uint8_t *) 0x0624) &= ~(0b10000000); } }

slide-28
SLIDE 28

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

28

Hello World (Debug Pins)

Simplifications…

▪ iox128a3.h ▪ sfr_defs.h

/* PORTB - Port B */ #define PORTB_DIR _SFR_MEM8(0x0620) #define PORTB_DIRSET _SFR_MEM8(0x0621) #define PORTB_DIRCLR _SFR_MEM8(0x0622) #define PORTB_DIRTGL _SFR_MEM8(0x0623) #define PORTB_OUT _SFR_MEM8(0x0624) #define PORTB_OUTSET _SFR_MEM8(0x0625) #define PORTB_OUTCLR _SFR_MEM8(0x0626) #define PORTB_OUTTGL _SFR_MEM8(0x0627) #define PORTB_IN _SFR_MEM8(0x0628) …

#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr) #define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))

slide-29
SLIDE 29

#include <asf.h> int main (void) { // define port B’s pins 4..7 as output (*(volatile uint8_t *) 0x0620) |= 0b11110000; while (true) { // turn pin 7 on (*(volatile uint8_t *) 0x0624) |= 0b10000000; // turn pin 7 off (*(volatile uint8_t *) 0x0624) &= ~(0b10000000); } }

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

29

Hello World (Debug Pins)

Code!

#include <asf.h> int main (void) { // define port B’s pins 4..7 as output PORTB_DIR |= PIN4_bm | PIN5_bm | PIN6_bm | PIN7_bm; while (true) { // turn pin 7 on PORTB_OUT |= PIN7_bm; // turn pin 7 off PORTB_OUT &= ~(PIN7_bm); } }

slide-30
SLIDE 30

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

30

Hello World (Debug Pins)

Result!?

slide-31
SLIDE 31

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

31

Hello World (Debug Pins)

Meh…

▪ JTAG: IEEE Standard 1149.1-1990 Standard Test Access Port and Boundary-Scan Architecture

// disable JTAG interface (uses upper 4 pins of port B) CCP = CCP_IOREG_gc; // Configuration Change Protection MCU_MCUCR = MCU_JTAGD_bm;

slide-32
SLIDE 32

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

32

Hello World (Debug Pins)

Result!

slide-33
SLIDE 33

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

33

Hello World (USB)

Scenario

▪ manual USB with FTDI chip

[Future Technology Devices International Ltd. FT245R USB FIFO IC]

slide-34
SLIDE 34

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

34

Hello World (USB)

Code: Writing to USB

PORTB_DIR |= PIN0_bm|PIN1_bm; // output (USB RD, USB WR) PORTB_DIR &= ~(PIN2_bm|PIN3_bm); // input (USB RXF, USB TXE) PORTR_DIR &= ~(PIN1_bm); // input (USB PWREN) while (true) { unsigned char data = 255; while (PORTR_IN & PIN1_bm); // wait for PWREN (1=off) while (PORTB_IN & PIN3_bm); // wait for TXE (1=off) PORTA_DIR = 0xFF; // port A as output (USB DATA) PORTB_OUT |= PIN1_bm; // enable WR PORTA_OUT = data; // enable DATA PORTB_OUT &= ~PIN1_bm; // disable WR PORTA_DIR = 0x00; // port A as input }

slide-35
SLIDE 35

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

35

AVR XMEGA A3 Microcontroller + Sensor Management Board

Interrupts

▪ per port:

▪ 2 interrupt service routines ▪ interrupt level

▪ per pin:

▪ which ISR ▪ trigger (falling, rising, both edges)

▪ global:

▪ enable/disable all existing interrupts ▪ enable/disable interrupt levels

slide-36
SLIDE 36

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

36

AVR XMEGA A3 Microcontroller + Sensor Management Board

Interrupts

int main (void) { PORTR_INT0MASK = PIN0_bm; PORTR_INTCTRL |= PORT_INT0LVL_MED_gc; PORTR_PIN0CTRL |= PORT_ISC_FALLING_gc; PMIC_CTRL |= PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm; sei(); while (true); } ISR (PORTR_INT0_vect) { DBG_OUT(PIN3_bm,0xff); DBG_OUT(PIN3_bm,0x00); }

slide-37
SLIDE 37

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

37

AVR XMEGA A3 Microcontroller + Sensor Management Board

Timers

▪ various timers ▪ 16 bit ▪ prescalers for frequency ▪ interrupts

▪ overflow ▪ compare

slide-38
SLIDE 38

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

38

AVR XMEGA A3 Microcontroller + Sensor Management Board

Sensor Management Board

▪ Lane Sensor

▪ detect and decode lane signals (Manchester code)

▪ Position Sensor

▪ detect the pulsed identification signal of each car ▪ match pulse-width to car ID

▪ Anti-Collision Sensor

▪ detect cars inside critical sections

▪ don’t miss important events ▪ send results via USB

slide-39
SLIDE 39

Connecting Actuators & Sensors

Change of Control: Part 3

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018 39

slide-40
SLIDE 40

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

40

Connecting Sensors & Actuators

Recap: Big Picture

Race Track Control Unit/ Black Box Handset Control Board Position Sensor Position Sensor Position Sensor Position Sensor Position Sensor Anti-Collision S. Sensor Management Board PC Actuators Sensors (Lane Sensor)

USB USB

slide-41
SLIDE 41

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

41

Connecting Sensors & Actuators

USB Protocol

▪ Handset Control Board ▪ Sensor Management Board

USB Data Package

7 6 5 4 3 2 1

MAGIC

1

TYPE R R R LENGTH

2

TIMER HIGH

3

TIMER LOW

#LENGTH

PAYLOAD TYPE Value Description 00 Lane Sensor 01 Junction Sensor 10 Position Sensor 11 Other

slide-42
SLIDE 42

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

42

Connecting Sensors & Actuators

T estbed PC Application

sensorStream .OfType<LaneSensorPacket>() .Where(lsp => lsp.ControllerID<6) .Subscribe(psp => this.Handsets[psp.ControllerID] .Refresh(psp.Speed,psp.ButtonPressed)}); sensorStream .OfType<PositionSensorPacket>() .GroupBy(psp => psp.CarId) .SelectMany(g => g.Throttle(TimeSpan.FromMilliseconds(10))) .Where(psp => psp.CarId<6) .Subscribe(psp => this.Handsets[psp.CarId].LapCompleted());

slide-43
SLIDE 43

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

43

Connecting Sensors & Actuators

T estbed PC Application

slide-44
SLIDE 44

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

44

Carrera D132 Racetrack Experiment

Mobility-as-a-Service

traditional real-time control systems enhanced by remote (non real-time) backbone service ▪ analytic redundancy → cascaded processing stages each with own safety controllers ▪ hard real-time processing on embedded control units vs. soft real-time data acquisition

Cascade Stage 1

Safety Controller 1 Communication Channel 1

Cascade Stage 2

Safety Controller 2 Communication Channel 2

Cascade Stage 3

Safety Controller 3 Communication Channel 3

Cascade Stage n Real-Time Constraints Computation Smartness

slide-45
SLIDE 45

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

45

Carrera D132 Racetrack Experiment

Mobility-as-a-Service

Carrera Racetrack Experiment ▪ Race-Track Control Unit ▪ Sensor/Actuator Board ▪ PC Application ▪ Cloud Service

slide-46
SLIDE 46

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

46

Carrera D132 Racetrack Experiment

Mobility-as-a-Service

▪ Stage 3 - PC Application

▪ .NET application (written in C#) running on commodity PC hardware, no real-time guarantees; computes trajectories for a single car ▪ Communication Channel: HTTP / TCP/IP connections, no guaranteed response times can be specified. ▪ Safety Controller: keep the car moving at a steady, slow speed.

slide-47
SLIDE 47

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

47

Carrera D132 Racetrack Experiment

Mobility-as-a-Service

▪ Stage 2 - Sensor/Actuator Board

▪ custom made circuit board + microcontroller firmware, simulates handheld controllers (speed, brakes, turn switch points) & analyzes sensor signals. ▪ Communication Channel: custom USB format (neither real-time capable nor providing strict timing guarantees) ▪ Safety Controller: keep all cars within a safe state - send commands to stop all cars

slide-48
SLIDE 48

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

48

Carrera D132 Racetrack Experiment

Mobility-as-a-Service

▪ Stage 1 - Race-Track Control Unit

▪ off-the-shelf Carrera Digital 132 race-track including “Carrera control unit” extended with several additional position sensors ▪ Communication Channel: RS232 interface, four RJ-12 interfaces, standard Carrera D132 protocol commands ▪ Safety Controller: repeat creation of command packets based the last signal received

slide-49
SLIDE 49

Embedded Operating Systems | Lukas Pirl & Daniel Richter | November 15, 2018

49

Carrera D132 Racetrack Experiment

Current State