Worked examples — Software-in-the-Loop (SIL) simulation — all software, simulated hardware
5.5.22 · D3· Coding › Embedded Systems & Real-Time Software › Software-in-the-Loop (SIL) simulation — all software, simula
Shuru karne se pehle, ek promise: har symbol use se pehle earn kiya jaata hai. Yeh hain sirf ingredients, ek baar define kiye gaye:
Scenario matrix
Har SIL simulation jo tum kabhi run karoge woh in cells mein se ek mein aata hai. Neeche ke examples cell ke saath labelled hain jo woh cover karte hain.
| Cell | Case class | Kya special banata hai | Covered by |
|---|---|---|---|
| A | Nominal, (bahut slow) | Happy path: upar converge karna | Example 1 |
| B | Sign flip, (bahut fast) | Command negative jaani chahiye | Example 2 |
| C | Zero input, | Degenerate: kuch nahi hilna chahiye | Example 3 |
| D | Degenerate hardware model () | Instant plant — limiting behaviour | Example 4 |
| E | Numerical instability ( bahut bada) | Solver diverge karta hai — ek simulation bug, code bug nahi | Example 5 |
| F | Real-world word problem | Braking-distance stopping question | Example 6 |
| G | Exam-style twist | "SIL pass hua lekin hardware fail hua" — abstraction error | Example 7 |
Running examples ke liye (jab tak koi cell override na kare) hum fix karte hain: , s, s.
Figure s01 — closed SIL loop. Layout ka sketch: left par ek lavender rounded box jis par likha hai "Software under test — ", aur right par ek mint rounded box jis par likha hai "Simulated plant — ". Ek coral arrow right ki taraf point karta hai software se plant ki taraf "command " carry karte hue; ek lavender arrow neeche loop karta hai, left ki taraf plant se software ki taraf point karta hua "sensed speed " carry karte hue. Ek chhota butter-coloured arrow software box mein upar se drop karta hai, " = target enters here" mark kiya hua. Neeche caption padhta hai: software kabhi nahi jaanta ki plant fake hai — woh bas read karta hai. Jab tum har example padho, trace karo ki numbers kis arrow se travel karti hain.

Example 1 — Cell A: nominal, motor bahut slow hai
Step 1 — Error compute karo. Yeh step kyun? Controller tab tak act nahi kar sakta jab tak woh jaane "kitna off hai". Error software ka single input hai.
Step 2 — Controller command compute karta hai.
Yeh step kyun? Yeh literally production code ki woh line hai jo test ho rahi hai: u = K * (v_ref - v). Positive error → positive push. Sahi hai.
Step 3 — Plant ek Euler step aage badhta hai. Yeh step kyun? Yeh simulated hardware react kar raha hai. Plant command directly use karta hai (extra nahi) — dhyan karo software kabhi yeh equation nahi dekhta, woh sirf resulting next tick par dekhta hai. Yahi "in-the-loop" feedback hai.
Answer: rev/s.
Recall Kya tumhara forecast sahi tha?
Yeh sirf se upar jata hai, 10 ke paas nahi ::: Sahi — chhote ke saath Euler gently nudge karta hai; convergence mein bahut saare ticks lagte hain, isliye hum simulate karte hain instead of eyeball karne ke.
Verify: Sign check — motor bahut slow tha (), aur increase hua (). Units check: rev/s mein hai, dimensionless hai (s/s), toh increment rev/s hai. ✓
Example 2 — Cell B: sign flip, motor bahut fast hai
Step 1 — Error ab negative hai. Yeh step kyun? Hume reader ko woh case dikhana hai jahan input ka sign flip hota hai — parent contract demand karta hai har sign. Negative error matlab "bahut fast".
Step 2 — Command sign flip karta hai.
Yeh step kyun? Ek sahi proportional controller automatically apna push reverse karta hai. Agar tumhare code mein koi abs() ya unsigned type bug hota, SIL use yahin pakad leta — sim accelerate karta rehta braking ke bajaaye.
Step 3 — Plant step. Yeh step kyun? Negative command ko neeche drag karta hai. Target ki taraf motion confirm hua.
Answer: , rev/s.
Verify: Symmetry sanity check Example 1 ke against — Ex 1 mein error tha; yahan hai, toh command exactly negate hua ( vs ). ✓ Aur decrease hua, "bahut fast" ke liye sahi. ✓
Example 3 — Cell C: zero / degenerate input
Step 1 — Error zero hai. Yeh step kyun? Degenerate input woh hai jahan do inputs cancel hote hain. Hume confirm karna hai ki software exactly form karta hai yahan — ek subtraction bug ya floating-point residue ek tiny nonzero error ke roop mein dikhega, aur yahi jagah hum use pakdenge.
Step 2 — Command zero hai.
Yeh step kyun? Zero error matlab zero push hona chahiye. Yeh degenerate input hai jo har controller ko handle karna chahiye. Ek divide-by-error bug ya NaN yahan surface hoga.
Step 3 — Plant step. Yeh step kyun? Hum plant ko advance karte hain even though command zero hai, precisely yeh reveal karne ke liye ki "no command" ka matlab no motion nahi hai — drag term phir bhi act karta hai. Yahi example ka poora point hai, isliye hum step run karte hain instead of assume karne ke ki kuch nahi hota.
Answer: rev/s (yeh target se neeche drift karta hai).
Verify: True equilibrium plug karo: stay karne ke liye humein chahiye with , i.e. . Solve karne par: . Toh loop par settle hota hai, 10 par nahi — offset confirm karta hai. ✓
Example 4 — Cell D: degenerate hardware, (instant motor)
Step 1 — Ratio inspect karo. Jaise , yeh ratio ho jaata hai. Yeh step kyun? Poora update se scale hota hai. Ek limiting input ko symbolically inspect karna chahiye, sirf numerically nahi.
Step 2 — Command restate karo, phir ek concrete chhota lo. Pehle controller output exactly waise hi recompute karo jaise Example 1 mein, kyunki hum same state se start karte hain: Ab shrunken time constant ke saath ek plant step run karo: Yeh step kyun? Hume dikhana chahiye, assume nahi karna, ki kahan se aata hai — yahi controller line hai Example 1 se. Ek concrete degenerate value phir danger dikhata hai explode hone se pehle: ek step already target tak jump kar deta hai aur true continuous answer ko overshoot kar dega.
Step 3 — Failure mode pehchano. Jab hota hai, ek Euler step true continuous answer ko overshoot karta hai, aur jab yeh 2 tak pahunchta hai simulation oscillating aur blow up karne ki edge par hoti hai. Ek "faster" (chhota ) motor ko accurate rehne ke liye chhota chahiye.
Answer: Jaise , discrete plant unstable ho jaata hai unless sath mein shrink ho; "instant motor" ek degenerate model hai jise SIL time step refine kiye bina faithfully simulate nahi kar sakta.
Verify: Euler ki stability for require karti hai , i.e. . par: — exactly unstable boundary par. ✓
Example 5 — Cell E: numerical instability, ek simulation bug nahi code bug
Step 1 — Growth factor compute karo. Yeh step kyun? Example 4 se hum jaante hain matlab unstable hai. Hum deliberately cliff ke past hain, toh hum expect karte hain agale steps diverge karein.
Step 2 — Tick 1. Yeh step kyun? Hum oversized ratio ke saath pehla Euler step lete hain yeh dekhne ke liye ki ek single update kitna badly overshoot karta hai — already sensible resting value se blast off ho jaata hai.
Step 3 — Tick 2. Yeh step kyun? Overshot ko back feed karte hain. Kyunki usne overshoot kiya, correction term sign flip karta hai aur over-correct karta hai, ko negative fling karta hai. Yeh dikhata hai ki divergence bad step size ka ek feedback effect hai, one-off nahi.
Step 4 — Tick 3. Yeh step kyun? Ek baar aur repeat karne par dikhta hai ki swing growing hai (), settle nahi ho raha. Teen ticks minimum hain yeh prove karne ke liye ki amplitude increase ho rahi hai instead of lucky bounce ke.
Figure s02 — stable vs unstable Euler. Layout ka sketch: ek set of axes, horizontal axis "tick number ", vertical axis "simulated speed (rev/s)". Ek mint curve with round markers smoothly climb karti hai aur 5 ke paas level off hoti hai — yeh safe run hai (, ratio ). Ek coral curve with square markers violently zig-zag karti hai: uske points par hain (tick 1), phir (tick 2), phir (tick 3), har swing pehle se bada — yeh divergent run hai (, ratio ) jo humne abhi haath se compute kiya. Ek legend "stable" (mint) aur "diverges" (coral) distinguish karta hai. Dhyan karo coral markers exactly hamare teen computed numbers par land karte hain.

Answer: — divergent oscillation solver ki wajah se, SUT ki nahi.
Verify: Upar teen values, aur instability predict karta hai. ✓
Example 6 — Cell F: real-world word problem
Step 1 — Stopping-distance formula recall karo. Yeh step kyun? Hum use karte hain kyunki yeh exactly jawaab deta hai "constant deceleration ke under zero speed tak pahunchne mein kitna door?" — energy se derive kiya gaya: car ko kinetic-energy-per-mass per metre ki rate par shed karna hai.
Step 2 — Plug in karo (units: m/s aur m/s²). Yeh step kyun? Actual numbers substitute karna abstract formula ko concrete distance mein turn karta hai jise hum gap ke against compare kar sakte hain. Units: . ✓
Step 3 — Gap se compare karo. m lekin obstacle m par hai. Margin m. Yeh step kyun? Margin tab hi meaningful hai jab (available gap) minus (needed distance) ho; negative result unambiguous "collision" signal hai.
Answer: Nahi — car ko 75 m chahiye lekin sirf 50 m available hai; woh 25 m se fail karti hai. Controller ko pehle ya zyada hard brake karna chahiye.
Verify: 50 m par maximum safe speed solve karo: m/s. Kyunki , collision confirm. ✓
Example 7 — Cell G: exam twist ("SIL pass hua, hardware fail hua")
Step 1 — SIL command (fresh data ). Yeh step kyun? SIL ne zero delay model kiya, toh woh current true speed use karta hai — yeh "ideal" command hai jis par code verify kiya gaya.
Step 2 — Hardware command (stale data ). Yeh step kyun? Real ADC 2-tick-old data deta hai. Wahi code line run hoti hai, lekin uska input stale hai, toh hum ki jagah ke saath recompute karte hain yeh dekhne ke liye ki hardware actually kya karta hai.
Step 3 — Dono commands compare karo. Yeh step kyun? Subtract karne se delay ka pure effect isolate hota hai — ek full unit extra, unwanted push — jo woh number hai jo abstraction error quantify karta hai.
Answer: SIL kehta hai ; real hardware kehta hai . Extra unit woh invisible timing bug hai jo SIL miss kar gaya.
Verify: Difference , aur hardware SIL ne predict kiya usse double push karta hai. ✓
Wrap-up: matrix, filled
Recall Kis example ne kaunsa cell cover kiya?
A→Ex1, B→Ex2, C→Ex3, D→Ex4, E→Ex5, F→Ex6, G→Ex7 ::: Har cell of the scenario matrix ab ek fully worked, verified example ke saath hai.
Parent topic par wapas jao.