Back to homeTechnology · Secondary Year 3 · Change subject
Start for free
Secondary 3 · Technology
Computational thinking and robotics · Control systems

Simulation and Verification of Control Systems

Before you start, make sure you know: Control systems (Secondary Year 2)

Ximena's team built an irrigation system for the school garden. They connected it right away, without testing it, and the solenoid valve got stuck open: the garden woke up flooded and a component burned out. How could they have avoided this without spending a single part? By testing first in a simulation and with a test plan. At the end of the page we come back to their case.

Why Simulate Before Building

A physical prototype costs money, takes time to assemble, and can be damaged by the first mistake. A model on the computer screen cannot.

The same control program runs in a simulator, with a virtual robot and obstacle, and on the real prototype, with a physical robot and obstacle. control program (identical in both) simulator (no risk) real prototype

A typical case: the LED without a resistor

Some simulators let you connect an LED directly to a pin on the board and show it lit with no warning at all. In the real world it burns out. Ohm's law explains why and lets you calculate the resistance that protects it.

Without a resistor, only the wire remains (in the simulation, an ideal model that allows an enormous current, such as $115\ \text{mA}$). That is far more than the $20\ \text{mA}$ the LED can take and the $40\ \text{mA}$ the pin can handle: in reality both would be damaged.

Practice★☆☆Not started
Explain what a circuit or robotics simulator is and give two advantages of testing on it before building the physical assembly.

Explain what a circuit or robotics simulator is and give two advantages of testing on it before building the physical assembly.

Solve
Practice★☆☆Not started
Explain the difference between simulating a circuit on a computer and building it on a real breadboard: what is gained and lost with each method.

Explain the difference between simulating a circuit on a computer and building it on a real breadboard: what is gained and lost with each method.

Solve
Practice★☆☆Not started
Some simulators allow you to "speed up time". Explain the advantage of this when testing a thermostat's behavior over a full day.

Some simulators allow you to "speed up time". Explain the advantage of this when testing a thermostat's behavior over a full day.

Solve
Practice★★☆Not started
In the simulator, your program works perfectly, but in the actual build, the motor does not rotate. Give three possible causes that a simulator does not detect and…

In the simulator, your program works perfectly, but in the actual build, the motor does not rotate. Give three possible causes that a simulator does not detect and explain how you would check each one on the workbench.

Solve
Practice★★☆Not started
In the simulation, the LED blinks with perfect timing, but in the actual build, it blinks irregularly. Give two electrical causes that the simulator idealises (resistor…

In the simulation, the LED blinks with perfect timing, but in the actual build, it blinks irregularly. Give two electrical causes that the simulator idealises (resistor tolerances, loose breadboard contacts) and explain how to troubleshoot each one.

Solve
Practice★★★Not started
In a simulator such as Tinkercad, a student directly connects a red LED between a 5.0 V digital output pin of a programmable board and ground (GND), without placing any…

In a simulator such as Tinkercad, a student directly connects a red LED between a 5.0 V digital output pin of a programmable board and ground (GND), without placing any resistor. On the screen, the simulator shows the LED turned on with a current of 115.0 mA and displays no error message.

  1. a) If the LED manufacturer sets its maximum continuous current at 20.0 mA and a forward voltage drop of 2.0 V, and the board has a limit of 40.0 mA per pin, predict what will happen to the real components if you assemble that physical circuit and what unrealistic mathematical simplification the simulator is making.
  2. b) Calculate the standard commercial value (E12 series) of the resistor you must insert so that the LED operates safely at a current of 15.0 mA.
Solve

Designing Test Cases

Verifying a program is not "testing it a little to see if it works." It means comparing, case by case and with a written plan, what the system does with what it should do.

A logic gate is the simplest example: with two inputs there are only four combinations, and testing them all exhausts the possibilities.

Threshold with hysteresis

When a sensor reading fluctuates right around the threshold, a simple rule makes the actuator turn on and off nonstop. Imagine a blind with the rule "if light ≥ 800 lx, lower; otherwise, raise," and readings like 805, 795, 812, 798: the motor would receive a command at every change, causing wear and wasting energy.

When testing it, your cases must include readings that oscillate within the zone between the two thresholds and check that the actuator does not change.

Practice★☆☆Not started
Write two test cases for a program that sounds an alarm when a door opens: specify the input simulated and the expected output in each case.

Write two test cases for a program that sounds an alarm when a door opens: specify the input simulated and the expected output in each case.

Solve
Practice★★☆Not started
A program must switch on a fan when the temperature exceeds $26\ ^\circ\text{C}$. Define three test cases (input value and expected result) to verify it, including the…

A program must switch on a fan when the temperature exceeds $26\ ^\circ\text{C}$. Define three test cases (input value and expected result) to verify it, including the boundary value of $26\ ^\circ\text{C}$, and justify why this boundary case is important.

Solve
Practice★★☆Not started
Explain what a "boundary case" (or edge case) is when verifying a program and why they are so important. Give an example using a program that decides whether a mark…

Explain what a "boundary case" (or edge case) is when verifying a program and why they are so important. Give an example using a program that decides whether a mark passes from 5 upwards.

Solve
Practice★★☆Not started
A program counts people entering a room (sensor A) and leaving it (sensor B). Design three test cases intended to catch typical errors: two people walking in together,…

A program counts people entering a room (sensor A) and leaving it (sensor B). Design three test cases intended to catch typical errors: two people walking in together, someone entering and leaving immediately, and a sensor triggering twice due to contact bounce.

Solve
Practice★★☆Not started
Explain what a "stress test" is for a control system and propose one for a parking lot program: state what extreme conditions you would simulate and what correct…

Explain what a "stress test" is for a control system and propose one for a parking lot program: state what extreme conditions you would simulate and what correct behavior you expect.

Solve
Practice★★☆Not started
A team verifies their program only on the "happy path", that is, when everything goes right. Explain what error cases are and write two for a toy cash machine (invalid…

A team verifies their program only on the "happy path", that is, when everything goes right. Explain what error cases are and write two for a toy cash machine (invalid card, insufficient balance).

Solve
Practice★★☆Not started
Design a verification table for a pedestrian traffic light: states (red, green, flashing amber), inputs (button pressed, time elapsed), and expected output for each…

Design a verification table for a pedestrian traffic light: states (red, green, flashing amber), inputs (button pressed, time elapsed), and expected output for each state transition.

Solve
Practice★★★Not started
A mobile robot uses a front ultrasonic sensor (usable range: 2.0 cm to 400.0 cm) and must stop and turn if it detects an obstacle closer than 20.0 cm. Design a test…

A mobile robot uses a front ultrasonic sensor (usable range: 2.0 cm to 400.0 cm) and must stop and turn if it detects an obstacle closer than 20.0 cm. Design a test matrix to verify the code in the simulator before transferring it to the real robot. Your plan must contain at least 4 different test cases that include boundary values and reading anomalies. For each case, you must indicate: simulated numeric input value, expected behavior of the motors, and technical justification of why it is essential to check that specific case.

Solve
Practice★★★Not started
A greenhouse has two independent irrigation zones (Zone A: delicate seedbed; Zone B: general crop) managed by a microcontroller that receives data from two soil moisture…

A greenhouse has two independent irrigation zones (Zone A: delicate seedbed; Zone B: general crop) managed by a microcontroller that receives data from two soil moisture sensors, a digital rain sensor, and a flow sensor in the main pipe. Design a verification plan to simulate the system before commissioning. You must define 5 comprehensive test cases that include priority conflict situations and supply failures. For each case, detail: exact simulated inputs, expected state of the solenoid valves and alarms, and what material or agronomic damage that test prevents.

Solve

Reading a Flowchart and Detecting Faults

To find a fault, it helps to read the program the way the computer does, following the flowchart with concrete values.

There are also faults that only appear when the simulator models time. An irrigation system that reads the moisture, opens the valve for 10 seconds, and reads again can repeat endlessly if the water takes minutes to seep down to the sensor: the program "doesn't see" the effect of its own action. That's why it's a good idea to simulate with the real delay of the environment.

Practice★☆☆Not started
The flowchart in the figure controls an automatic light depending on a sensor (LDR), but the contents of one block are missing. State what that block should do and…

The flowchart in the figure controls an automatic light depending on a sensor (LDR), but the contents of one block are missing. State what that block should do and describe what the system does when the sensor reading is 150 and when it is 800.

Start Read LDR Is LDR < 200? yes ? no Turn off LED
Solve
Practice★☆☆Not started
What is a bug or glitch in a control program? Give two simple examples (a condition written backwards, an incorrectly set threshold) and the effect each would have.

What is a bug or glitch in a control program? Give two simple examples (a condition written backwards, an incorrectly set threshold) and the effect each would have.

Solve
Practice★★★Not started
In the simulation of an irrigation system for a school garden bed, you have programmed this control loop: REPEAT FOREVER: humidity = read_sensor() IF humidity < 30 %…

In the simulation of an irrigation system for a school garden bed, you have programmed this control loop:

REPEAT FOREVER:

humidity = read_sensor()

IF humidity < 30 % THEN:

activate_solenoid_valve()

wait(10 seconds)

deactivate_solenoid_valve()

END REPEAT

When running it in a simulator that models the physical absorption of water with an infiltration delay of 2 minutes, the solenoid valve opens and closes non-stop for dozens of consecutive cycles, waterlogging the soil.

  1. a) Justify why the program generates this behavior in the simulation despite including an explicit deactivation instruction.
  2. b) Redesign the algorithm (in pseudocode or a flowchart) to solve the problem without removing the sensor reading or changing the solenoid valve.
Solve
Practice★★★Not started
The light sensor of an automatic blind records these values over a 6-minute period during an afternoon with broken clouds: t = 0 min: 780 lx t = 1 min: 805 lx t = 2 min:…

The light sensor of an automatic blind records these values over a 6-minute period during an afternoon with broken clouds:

  • t = 0 min: 780 lx

  • t = 1 min: 805 lx

  • t = 2 min: 795 lx

  • t = 3 min: 812 lx

  • t = 4 min: 798 lx

  • t = 5 min: 815 lx

  • t = 6 min: 820 lx

The system is programmed with the simple rule: "If light ≥ 800 lx, lower blind; if light < 800 lx, raise blind".

  1. a) Determine how many movement commands the motor receives in that interval and justify what mechanical and energy consequences this operation entails.
  2. b) Design a solution based on a dual threshold (hysteresis) by defining specific numerical values for the lower and raise commands, and demonstrate step by step how your solution responds to the same data series.
Solve

Verifying and Validating: Two Different Questions

Verifying and validating are part of "monitoring and evaluating" a plan: you test during development, compare against the criteria set at the start, and adjust whatever is needed.

Diagram with three blocks: the real need is compared with the design or specification through validation, and the design is compared with the code through verification. real need design / specification validate? verify? code does the design solve the real problem?
Practice★☆☆Not started
In your own words, explain what it means to verify a program and how it differs from "just testing it briefly to see if it works".

In your own words, explain what it means to verify a program and how it differs from "just testing it briefly to see if it works".

Solve
Practice★★★Not started
A team simulates a black line follower robot: on screen, the algorithm reacts in 0.02 s, the motors respond instantaneously, and the robot completes the circuit at 1.2…

A team simulates a black line follower robot: on screen, the algorithm reacts in 0.02 s, the motors respond instantaneously, and the robot completes the circuit at 1.2 m/s without any errors. However, when uploading the same program to the real robot with the same sensors, it oscillates sharply from side to side and ends up losing the line on the first curve.

  1. a) Identify and justify three real-world factors that the simulator omitted or idealized and that explain this discrepancy.
  2. b) Propose two technical modifications (one in the control software parameters and another in the physical assembly) to compensate for these real effects without replacing the sensors.
Solve
Practice★★★Not started
A team programs a transport robot for a warehouse. When running the test plan in the simulator, the robot avoids 100% of the obstacles and brakes in front of any person,…

A team programs a transport robot for a warehouse. When running the test plan in the simulator, the robot avoids 100% of the obstacles and brakes in front of any person, but the algorithm always resolves obstacle avoidances by reversing, driving down aisles against the warehouse workflow. The teacher states: "The software is perfectly verified, but the system is not validated".

  1. a) Technically justify the teacher's statement by applying the operational definitions of verification and validation to this specific case.
  2. b) Reformulate the robot's technical requirements specification to ensure that a future verification also ensures its proper validation in the working environment.
Solve

Systematic Debugging

In a simulator you can debug by running the program step by step and watching the value of the variables at each instruction.

Flowchart of debugging: after a test fails, isolate the faulty part, fix the error, and repeat all the previous test cases. test fails isolate the fix repeat ALL the previous test cases
Practice★☆☆Not started
Explain what debugging a program means and name a simple technique for doing it in a simulator (stepping through code line by line, monitoring variable values).

Explain what debugging a program means and name a simple technique for doing it in a simulator (stepping through code line by line, monitoring variable values).

Solve
Practice★★★Not started
A line-tracking robot stops erratically after operating properly for about five minutes. To diagnose the fault, serial port logging is enabled, and these key lines are…

A line-tracking robot stops erratically after operating properly for about five minutes. To diagnose the fault, serial port logging is enabled, and these key lines are extracted prior to the stop:

  • t = 295.0 s | Distancia: 35.0 cm | Temp_driver: 50.0 °C | Vbatería: 7.4 V | Estado: AVANZAR

  • t = 298.5 s | Distancia: 34.0 cm | Temp_driver: 78.0 °C | Vbatería: 7.2 V | Estado: AVANZAR

  • t = 300.0 s | Distancia: 35.0 cm | Temp_driver: 92.0 °C | Vbatería: 6.1 V | Estado: PARADA_EMERGENCIA

  1. a) Interpret the log data to determine the physical cause of the fault, refuting the team's initial report which claimed the fault was due to a defective ultrasonic sensor.
  2. b) Design what additional variables or early warning conditions you should include in the log and in the control code to manage this issue progressively without reaching an abrupt shutdown.
Solve

Back to the beginning: Ximena's team would have written normal, boundary, and error cases for their irrigation system (moisture right at the threshold, a disconnected sensor), would have run them in the simulator with the water delay, and would have discovered that the valve stayed open before the garden got wet.

Summary

See all the exercises in this section