When working with machines, which also include robots, we often face the problem of controlling them in a way that a particular measured variable complies as well as possible with a predetermined value (the target value or set point). For example, the cruise control in a car should keep a predetermined speed even when the car drives on a slope or an incline. To do this, a control system with a sensor needs to determine the current speed (the actual value) and then adjust the power of the motor accordingly with an actuator, so in a way it needs to operate the gas pedal.
Other examples of technical regulation systems:
Many human activities can be considered as regulatory processes. Some examples:
Driving is a complex control process with many input signals that affect the driver not only visually, but also tactually (forces on the body). The mental processing of these signals leads to the driver's behavior (rotation of the steering wheel, pressing the pedals, etc.).
In the future,vehicles will be able to drive themselves without a human, even in complex traffic situations. Several research groups around the world are working on this problem, and it is possible that you might even participate in this interesting research at some point. You can already try out some of your skills here in a highly simplified situation.
Schematically, you can represent this process in a control loop. The light sensor measures the current light value (actual value) and delivers it to the controller, which compares it to the desired value (target value) on the green road. The controller calculates the control quantity for the chassis, meaning that the two motors are switched accordingly, using a control algorithm invented by you, which takes decisions based on the difference between the target and actual values.
As you can see, this scheme is indeed a "loop", from the vehicle sensor to the regulatory system, and then back again to the vehicle engines.
You are using an obvious control algorithm in your program: If the actual value is larger than the target value, the vehicle is in the yellow area and has to make a right turn. If the actual value is less than the target value, the vehicle is in the black area and has to make a left turn. Otherwise, it can move straight ahead.
The regulation works well in the simulation mode, but not in the real mode. You probably realize why this is: The measured values of the sensor vary, even when the sensor is located on an uniformly colored area. But then this can be expected since the brightness, even on the same surface, never remains exactly the same due to the differences in lighting, and also because of measurement errors from the sensor. Try to find a solution for this problem! The curve radius at leftArc() or rightArc() is a sensitive parameter. A smaller value leads to smaller "outliers" away from the street, but to an unsettled oscillating behavior [more...Controller oscillations are a typical error of control processes and can lead to failure of the control (instability)], while a larger value results in a calmer movement, but with less precise guidance on the street. Confirm this through some trials with varied curve radiuses.