Mushroom Kingdom Raceway
Intro to Robotics and Mechatronics
The Project:
Teach your robot to recognize 7 objects and use these objects to navigate a maze.
Details:
All turns will be 90 degrees
At the last object, do something fun
You must turn when the object is 6 inches from your camera
You will learn which direction to turn 10 minutes prior to the demos (you will have 10 minutes in class for this)
You will not know ahead of time the orientation of the objects
You may not use hot glue or tape
Camera and Ultrasonic Sensor Setup:
We used maker beams to create a structure that holds two ultrasonic sensors, a Pi camera, and the Pi securely on top of the Create3. We needed the ultrasonic sensors to be in the front down low to sense the objects. We also decided to use two ultrasonic sensors to sense the objects because some objects were very low to the ground while others were larger and we wanted to be able to detect all objects no matter their size. We needed the Pi camera higher and angled to be able to see all the different sized objects.
Code:
Explanation of the Code:
Functions:
measure_distance(trigger, echo)
: Measures the distance using an ultrasonic sensor connected to specified GPIO pins.measure_both()
: Measures distances using both high and low ultrasonic sensors and returns the minimum distance.find_object()
: Captures an image from the camera, performs object recognition using a loaded deep learning model, and returns the recognized object and confidence score.turn_direction(obj, conf_score)
: Determines the direction the robot should turn based on the recognized object and confidence score.
Drive functions:
MovePublisher
: ROS Node class for controlling robot movement. It publishes twist messages for controlling linear and angular velocity. It also has a timer callback function for continuous operation.
Main function:
Initializes ROS, creates a
MovePublisher
instance, and spins the ROS node to handle messages and callbacks. It also handles cleanup operations during shutdown.
The Create3 robot from iRobot uses ROS2 programing language. We used VNC Viewer to log into the Raspberry Pi in the create3 and ran the code from there.