Lesson 2-7 · Finishing the Sensor Toolkit — Knowledge ChecksAnswer key
Why can get_left() use reflectance when it was never passed in as a parameter?
A name created at the top level of the file is visible inside every function. drivetrain has worked this way since Module 1; reflectance and THRESHOLD work the same way here.
Which condition detects an intersection (both sensors on the line)?
A cross means BOTH sensors are on black at once, so both comparisons must be true — that's and. or would fire during normal following too.
Both sensors read 0.2 with THRESHOLD = 0.5. What do is_at_cross() and is_either_on_line() return?
0.2 > 0.5 is False for both sensors. and needs both True; or needs at least one. Both come out False: the robot is off the line entirely.
Why does get_error() call get_left() instead of reflectance.get_left()?
Functions calling functions keeps each job in one place. get_error() means left minus right; how a reading is taken is get_left()'s business.
Why does set_threshold() need the global keyword when is_at_cross() does not?
Reading a global needs nothing. Assigning inside a function creates a local unless you declare global first — and the real THRESHOLD stays 0.5, with no error to tell you.