Object Tracking / Driving to an Object
Last updated
Last updated
Prerequisites
Our turret module provides a tutorial on object tracking as well as a codebase where object tracking is implemented (be sure to also look at the case study section in the linked module):
Implement the following algorithm:
Detect the object and store its bounding box (refer to the Machine Learning Toolchain module)
Determine the distance from the object to the camera (refer to the Object Distance Estimation module). You will only need the distance on the z and x axis for this.
You now have the hypotenuse (distance on the z-axis) and one side length (absolute value of the distance on the x-axis) of a right triangle! Solve for the other side length through the Pythagorean theorem. This second side is your y distance!
Add the x (horizontal) and newly calculated y distance to your robot's current position, this is the object's real-world position. Note that you have to account for the robot's orientation!
Plug the position into your autonomous movement functions (refer to the autonomous movement sections)
This video tutorial shows you how to drive to a detected object:
The FTC samples also give an excellent tutorial on driving to a detected object:
FTC Team Hazen Robotics has implemented code that can drive to a game element: