Simulate ball following with PrintingMotion
-
Open
main.py
. This file contains an example implementation of the image processor and motion classes. For this task in case of questions, ask an instructor. -
There should be a main loop that processes every camera frame and outputs a
ProcessedResults
object that contains information about objects detected in the frame. -
Use the return data to find if there are any balls in the frame.
-
If there are balls in the frame, find the largest balls Object.
-
Find the X and Y coordinates of the ball. Take into consideration that the zero coordinates of the frame are in the upper left corner.
-
Using these coordinates calculate the rotation for the robot to turn towards the ball. Use
PrintingMotion
and its move method print the direction the robot is turning. If the directiction is opposite to what you expect, you can set thepolarity
variable to -1 to invert it. Teh default is 1. Write code so that the robot centers the ball horizontally. Don’t only use constant speeds since it leads to jerky motion. Try to implement a proportional system where the robot turns faster when the ball is further away from the center and slower when closer, stopping when centered. -
Demo your solution to the instructors. Iterate on the solution in case deficiencies are brought up by instructors.
-
If everything works, continue to the next task.