De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag Gelinkte lijsten Finite State.

Verwante presentaties


Presentatie over: "Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag Gelinkte lijsten Finite State."— Transcript van de presentatie:

1 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag Gelinkte lijsten Finite State Machine (Eindige Toestands Machine)

2 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 2 Lijst operaties 1.Voeg toe achteraan (enqueue) 2.Haal weg vooraan (dequeue, pop) 3.Voeg toe vooraan (push) 4.Haal weg achteraan (?) 5.Voeg toe in ‘t midden 6.Haal weg in ‘t midden

3 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 3 Singly linked, double linked

4 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 4 Ending, circular

5 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 5 Insert, delete (singly linked)

6 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 6 Insert, delete (double linked)

7 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 7 Sentinels Sentinel ( ~ wachter ): dummy queue element dat er altijd is. 1 bij circulaire lijsten, 2 bij ‘eindigende’ lijsten. Voordeel: geen apart geval meer in de code voor begin of einde van de lijst. Nadeel: extra geheugen nodig voor de sentinel. Sentinel == zelfde type als lijst elementen, dus als een lijstelement ‘groot’ is kan dit kostbaar zijn.

8 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 8 lijsten LinkVormSentinels EnkelEindigNeeEenvoudig concept EnkelEindigJaCode voor lege lijst en laatste element eenvoudiger EnkelCirculairNeeGeen aparte ‘first’ en ‘last’ pointers nodig EnkelCirculairja DubbelEindigNeeDelete kan met alleen pointer naar het element DubbelEindigJa DubbelCirculairNee DubbelCirculairjaIngewikkeld concept, maar de eenvoudigste code, zonder if’s

9 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 9 Finite State Machine (= Eindige Toestands Machine) states (toestanden) events (gebeurtenissen, boodschappen, triggers) actions (wat je programma doet) Diverse notaties in gebruik, schrik niet als je een iets andere notatie tegenkomt.

10 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 10 FSM voorbeeld : knipper LED op 1/2 Hz States : –LED is aan –LED is uit Events : –1 seconde timer tick Actions : –LED aanzetten –LED uitzetten

11 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 11 knipper LED op 1/2 Hz : FSM diagram LED is uitLED is aan init LED uitzetten 1s timer tick LED aanzetten 1s timer tick LED uitzetten

12 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 12 knipper LED op 1/2 Hz : State-Transistion diagram Event State 1s timer tick LED is uitLED aanzetten LED is aan LED uitzetten LED is uit

13 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 13 FSM voorbeeld : knipper LED op 1/2 Hz // states #define knipper_state_init 0 #define knipper_state_uit 1 #define knipper_state_aan 2 // events #define knipper_event_tick 100 // current state int knipper_state = knipper_state_init; // acties void Zet_LED( int led, int x ){... } void fsm_knipper( int & state, int led, int event ){ if( *state == knipper_state_init ){ Zet_LED( led, 0 ); *state = knipper_state_uit; } if( *state == knipper_state_uit ){ if( event == knipper_event_tick ){ Zet_LED( led, 1 ); *state = knipper_state_aan; return; } if( *state == knipper_state_aan ){ if( event == knipper_event_tick ){ Zet_LED( led, 0 ); *state = knipper_state_uit; return; }

14 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 14 FSM voorbeeld : Toegangspoort 1

15 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 15 FSM voorbeeld : Toegangspoort 2

16 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 16 FSM voorbeeld : Toegangspoort 3

17 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 17 FSM voorbeeld : Toegangspoort 3 Event State CoinPassResetReady LockedUnlock() Unlocked Alarm() ViolationLocked UnlockedThankyou() Unlocked Lock() LockedUnlocked Violation ResetAlarm() Violation Lock() ResetAlarm() Locked

18 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 18 // states #define poort_state_init 0 #define poort_state_locked 1 #define poort_state_unlocked 2 #define poort_state_violation 3 // events #define poort_event_coin 100 #define poort_event_pass 100 #define poort_event_reset 100 // current state int poort_state = poort_state_init; // actions void poort_thankyou( void ); void poort_lock( void ); void poort_unlock( void ); void poort_start_alarm( void ); void poort_stop_alarm( void ); void fms_poort( int event ){ if( state == poort_state_init ){ poort_lock(); state = poort_state_locked; } if( state == poort_state_locked ){ if( event == poort_event_coin ){ poort_unlock(); state = poort_state_unlocked(); } if( event == poort_event_pass ){ poort_alarm(); state = poort_state_violation(); } return; }... }

19 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 19 knipper LED op X Hz : State-Transistion diagram Event State 1ms timer tick LED is uit n++; if( n == 500/x ){ LED aanzetten n = 0; state = LED is aan } LED is aan n++; if( n == 500/x ){ LED uitzetten n = 0; state = LED is uit }

20 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 20 FSM voorbeeld : knipper LED op X Hz void fsm_knipper( int & state, int led, int X, int *n, int event ){ if( *state == knipper_state_init ){ Zet_LED( led, 0 ); *state = knipper_state_uit; *n == 0; return; } if( *state == knipper_state_uit ){ if( event == knipper_event_tick ){ *n++; if( *n == 500/x ){ Zet_LED( led, 1 ); *n = 0; *state = knipper_state_aan; } return; } if( *state == knipper_state_aan ){ if( event == knipper_event_tick ){ *n++; if( *n == 500/x ){ Zet_LED( led, 0 ); *n = 0; *state = knipper_state_uit; } return; }

21 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 21 FSM voorbeeld : knipper diverse LEDs while( 1 ){ wait_1ms(); fsm_knipper( &state1, l, 10, &n1, knipper_event_tick ); fsm_knipper( &state2, 2, 12, &n2, knipper_event_tick ); fsm_knipper( &state3, 3, 300, &n3, knipper_event_tick ); fsm_knipper( &state4, 4, 5, &n4, knipper_event_tick );... }

22 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 22 Rotary encoder (quadrature encoder) Sensor voor het bijhouden van de draaiing van een as. Toegepassingen: –user interface (afstemknop) –computermuis –motorsturing

23 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 23

24 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 24 Opdracht ”rotary encoder” Een rotary encoder FSM moet in de stand van een rotary encoder bijhouden. Bij een click naar rechts +1, bij een klick naar links -1. Er moet rekening gehouden worden met denderen en ‘halve bewegingen’ (= effect is hetzelfde als denderen).

25 vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 25 Opdracht ”rotary encoder” Stel de lijst van states (4), events (4) en acties (2), op voor een rotary encoder FSM -Maak het State Transition Diagram (er zijn ‘fysiek-logisch onmogelijke’ events, die hoef je niet te laten zien) -Vertaal je STD naar C code


Download ppt "Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag Gelinkte lijsten Finite State."

Verwante presentaties


Ads door Google