Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the optical flow sensor.
Drone Programming
optical_flow_sensor = OpticalFlowSensor([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong port number causes the sensor not to initialize.
✗ Incorrect
The optical flow sensor is connected to port 0 for indoor positioning.
2fill in blank
mediumComplete the code to read the optical flow data.
Drone Programming
flow_data = optical_flow_sensor.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
start() instead of read() does not return data.✗ Incorrect
The read() method retrieves the current optical flow data from the sensor.
3fill in blank
hardFix the error in the code to calculate displacement from flow data.
Drone Programming
displacement = flow_data.[1] * time_interval Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
distance attribute directly causes incorrect calculation.✗ Incorrect
The velocity attribute gives the flow velocity, which multiplied by time gives displacement.
4fill in blank
hardFill both blanks to update the drone's position using optical flow data.
Drone Programming
new_position = (current_position[0] + displacement[1], current_position[1] + displacement[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices causes position update errors.
✗ Incorrect
Displacement is a tuple; index 0 is x-axis, index 1 is y-axis displacement.
5fill in blank
hardFill all three blanks to filter optical flow data for valid movement detection.
Drone Programming
filtered_flow = {k: v for k, v in flow_data.items() if v[1] [2] and v[3] 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or values causes incorrect filtering.
✗ Incorrect
This filters values greater than -1 and less than 0 to detect valid negative movement.