Exercises — Hardware-in-the-Loop (HIL) simulation — real hardware, simulated plant
5.5.21 · D4· Coding › Embedded Systems & Real-Time Software › Hardware-in-the-Loop (HIL) simulation — real hardware, simul
Notation jo hum baar-baar use karenge (ek baar yahan define ki gayi hai)
Kisi bhi problem se pehle, aao har symbol ko earn karein taaki baad mein kuch bhi surprise na kare.
L1 — Recognition
Exercise 1.1 (L1)
In mein se kaunsa HIL ki defining feature hai jo ise Software-in-the-Loop (SIL) se alag karti hai? (a) Plant simulated hota hai। (b) Controller real target hardware par run karta hai। (c) Ek PID loop use hoti hai। (d) Test automated hota hai।
Recall Solution
(b). SIL aur HIL dono mein plant simulated hota hai (isliye (a) dono par true hai — distinguishing feature nahi hai)। PID aur automation kai test styles mein aate hain। HIL ki unique signature ye hai ki production ECU/microcontroller real firmware execute karta hai, real electrical signals exchange karte hue। Ladder compare karo: Model-in-the-Loop (MIL) (sab model), Software-in-the-Loop (SIL) (code on PC), Processor-in-the-Loop (PIL) (target CPU par code, real I/O nahi), phir HIL (target + real I/O)।
Exercise 1.2 (L1)
Ek HIL simulator par run karta hai। Milliseconds mein uska time step kya hai?
Recall Solution
L2 — Application
Exercise 2.1 (L2)
ECU battery par ek motor mein duty cycle command karta hai। HIL plant model kaunsa voltage apply karta hai?
Recall Solution
Kyun: PWM ka average delivered voltage duty cycle times supply hota hai — ye exactly woh pehla step hai jo simulator ECU ki PWM pin read karne par karta hai।
Exercise 2.2 (L2)
Aage jaari rakhte hain: motor resistance , back-EMF constant , current shaft speed । Quasi-static current equation use karke current nikalo।
Recall Solution
Kyun quasi-static: humne inductance term drop ki kyunki wo ke comparison mein tiny hai, jisse simulator ke andar finish ho sakta hai।
Exercise 2.3 (L2)
Torque constant । Woh current kaunsa motor torque produce karta hai?
Recall Solution
L3 — Analysis
Exercise 3.1 (L3)
Upar se lo। Load torque , damping , inertia , current , step । nikalne ke liye ek Euler update karo।
Recall Solution — figure follow karo
Parent note se Euler update: Net torque: Acceleration step: Kaisa dikhta hai: figure mein shaft speed thodi upar nudge hoti hai kyunki net torque positive hai — ek par woh tiny slope segment।
Exercise 3.2 (L3)
aur updated dono ko RPM mein convert karo।
Recall Solution
Exercise 3.3 (L3)
Ek step mein par laga। Budget ka kaunna fraction use hua, aur kya rig real-time-valid hai?
Recall Solution
Kyunki hai, law hold karta hai — valid hai, lekin sirf headroom ke saath। Kaafi close hai: ek slower branch (jaise ek fault-injection path) deadline blow kar sakti hai। Dekho Real-time Operating Systems (RTOS)।
L4 — Synthesis
Exercise 4.1 (L4)
Ek engine-idle HIL test ko plant par run karna hai। Har step mein teen tasks run hoti hain: combustion model , crankshaft dynamics , aur I/O generation (encoder pulses + CAN Bus Protocol frames) । (a) Total compute? (b) Valid hai? (c) Is workload ke saath maximum update rate kya hai?
Recall Solution
(a) Total: (b) → valid, headroom ()। (c) Sabse fast step jo tum sustain kar sakte ho usmein hoga, isliye Isse upar, compute step overrun karta hai aur ECU frozen sensors dekhta hai।
Exercise 4.2 (L4)
Words mein ek fault-injection test plan sketch karo (+ figure reference karo) jo verify kare ki ECU safely limp karta hai jab ek throttle-position sensor open-circuit read kare। Closed-loop cycle aur PASS criterion list karo।
Recall Solution — loop figure dekho
Plan (ye Fault Injection Testing hai HIL par layered):
- Plant model mein engine ko steady idle par lao।
- Fault inject karo: I/O box ke DAC ko command karo ki TPS line ko par drive kare (ya float kare) — ek broken sensor wire simulate karte hue।
- ECU ka diagnostic ek implausible/out-of-range TPS read karta hai।
- ECU ko ek fault code set karke limp-home mein enter karna chahiye (fixed safe throttle map)।
- Plant respond karta hai; engine speed aur throttle-motor PWM measure karo। PASS criterion: injection ke ke andar ECU (a) diagnostic flag raise kare aur (b) engine speed ek safe band mein rakhe (na stall, na runaway)। Figure closed loop ko red fault-injection tap ke saath dikhata hai jo sensor path mein cut karta hai। Kyun SIL nahi balki HIL: fault electrical signal path mein rehta hai (open circuit, wrong voltage)। Sirf real I/O hardware hi wo reproduce kar sakta hai; ek pure-software Software-in-the-Loop (SIL) rig wire nahi tod sakta।
L5 — Mastery
Exercise 5.1 (L5)
Full idle-control loop। Start: । Motor params: , , , , , , । Ek PID Control loop sirf proportional term ke saath setpoint ki taraf speed error se duty cycle drive karta hai: Pehle do Euler steps compute karo: har step par , , , do। (Quasi-static current use karo, negative current ko par clip karo।)
Recall Solution — step by step
Step k = 0 ():
- Error । (saturated)।
- ।
- ।
- ।
- ।
- ।
Step k = 1 ():
- Error । (abhi bhi saturated)।
- ।
- ।
- ।
- ।
- ।
Isko padhna: shuruaat mein error bahut bada hai, isliye P-controller duty cycle ko ceiling par slam karta hai (, saturated)। Shaft rest se dheere-dheere upar crawl karta hai — realistic hai, kyunki inertia sudden speed ka resist karti hai। Sirf bahut baad (jab ) rail se neeche aayega aur loop settle hoga।
Exercise 5.2 (L5)
Mastery synthesis question (concept + arithmetic): Tumhe ek stiff electrical sub-model (fast dynamics) add karna hai jisko stability ke liye chahiye, lekin tumhara current mechanical loop par khush hai। Har electrical step compute cost karta hai; mechanical step cost karta hai lekin sirf har mein run karna chahiye। (a) Agar sab kuch fast rate par chale, to us slice ka worst-case compute per slice kya hoga jo mechanics bhi karta hai, aur kya ye valid hai? (b) Architectural fix aur ek hardware option batao।
Recall Solution
(a) Unlucky slice par dono run karte hain: , lekin slice budget sirf hai। Kyunki hai, ye overrun karta hai — invalid। Sirf electrical slices bhi theek hain (); mechanical burst hi use maarta hai। (b) Multi-rate / multi-tasking simulation: electrical model ko fast task mein aur mechanical model ko slower task mein run karo, separate cores par ya hard-real-time scheduler (Real-time Operating Systems (RTOS)) se, taaki heavy mechanical work kabhi ek single fast slice mein na aaye। Hardware option: stiff, deterministic electrical ODE ko ek FPGA for Real-Time Simulation par offload karo jo parallel mein sub-microsecond rates par run kare, CPU ko free kare। Exactly isliye FPGAs high-end HIL rigs mein appear karte hain।
Recall Self-test — one-line recalls
SIL ke comparison mein HIL ki defining feature ::: controller real target hardware par real I/O ke saath run karta hai Real-time validity law ::: Max sustainable update rate ::: rad/s ko RPM mein convert karo ::: se multiply karo Stiff fast sub-model jo overrun kare uska fix ::: multi-rate scheduling aur/ya ek FPGA co-processor Back-EMF kyun subtract karni chahiye ::: current sirf leftover voltage feel karta hai