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
Copy file name to clipboardExpand all lines: course/measuring_distance/locate_object.rst
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,76 @@ Instead, the robot should remember the heading it faces when detecting *both* ed
83
83
between those edges, and thus the center of the object. We can store each edge angle in variables, naming them :code:`firstAngle`
84
84
and :code:`secondAngle`.
85
85
86
+
We're already quite familiar with turning until an edge is detected. Now, we'll need to detect *both* edges. However, it would be
87
+
quite unwieldy and error-prone to just copy the edge detection code, so let's make a function to generalize this. Note that the existing
88
+
code detects a sudden *decrease* in distance, but we want to handle sudden *increases* in distances too.
89
+
90
+
How can we support both behaviors in a single function? We can pass in a parameter to specify whether we want to detect an increase
91
+
or decrease in distance! We can call this parameter :code:`isIncrease` and pass in a boolean (true or false) value.
92
+
93
+
If :code:`increase` is :code:`True`, then we want to detect an increase in distance, which is when :code:`currentDistance - previousDistance > changeThreshold`.
94
+
95
+
If :code:`increase` is :code:`False`, then we want to detect a decrease in distance, which is when :code:`previousDistance - currentDistance > changeThreshold`.
96
+
97
+
For more flexibility, let's also have a parameter for the maximum distance, and a parameter for the change threshold.
0 commit comments