What if a tiny delay in your code could cause a robot to crash or a heart to stop beating on time?
Hard real-time vs soft real-time in FreeRTOS - When to Use Which
Imagine you are controlling a robot arm that must stop immediately if it detects an obstacle. You try to check the sensor manually in your code without strict timing rules.
Without clear timing guarantees, your robot might react too late or inconsistently. This delay can cause accidents or damage because your code can't promise when it will respond.
Hard real-time systems guarantee that critical tasks finish within a strict deadline every time, while soft real-time systems aim to meet deadlines but allow occasional delays. This helps you design safe and reliable control programs.
while(true) { if(sensor_detects_obstacle()) { stop_robot(); } // no timing guarantees }
vTaskDelayUntil(&lastWakeTime, period); if(sensor_detects_obstacle()) { stop_robot(); } // guaranteed timing in hard real-time
This concept enables building systems that can reliably control machines or processes where timing is critical for safety and performance.
In a pacemaker device, hard real-time ensures the heart receives electrical pulses exactly on time to keep a steady heartbeat, preventing life-threatening delays.
Hard real-time means strict, guaranteed timing for critical tasks.
Soft real-time allows some timing flexibility but aims to be fast.
Choosing the right type helps build safe and efficient embedded systems.