You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You'll notice that this code causes the robot to move back and forth, or oscillate, as the sonar distance continuously swaps between being greater than and less than 30 cm.
38
39
So what if we add a third case that tells the robot's motors to stop when sonar distance equals 30 cm?
@@ -47,10 +48,11 @@ So what if we add a third case that tells the robot's motors to stop when sonar
@@ -88,7 +92,14 @@ We can do this by creating a range in which our robot stops called a "deadband."
88
92
.. tab-item:: Blockly
89
93
90
94
.. image:: media/deadband.png
91
-
:width:300
95
+
:width:550
96
+
97
+
.. note::
98
+
Notice how, instead of hardcoding numbers such as 27.5 and 32.5, we used variables. This gives us two benefits:
99
+
100
+
1. We can easily change the desired distance and tolerance without having to change the code itself.
101
+
102
+
2. It's much easier to decipher what the code is doing, using "magic" numbers like 27.5 and 32.5 can be confusing to read because the user has to figure out what those numbers mean.
92
103
93
104
This code should allow the robot to stop when it senses a sonar distance of ~30 cm. Our issue now is that
94
-
there is a potential error of +- 2.5 cm from our desired following distance. Luckily, there is a solution to this called "proportional control."
105
+
there is a potential error of 2.5 cm from our desired following distance. Luckily, in the next section, we'll learn about something called "proportional control"...
0 commit comments