ELT1130: Robotics 1
Students apply the fundamentals of robotics systems and basic robotics functions.
Safety Reminder
Robotics systems include moving parts and electrical power. Always:
- Keep fingers and hair away from motors and gears
- Power off robots before rewiring
- Secure robots before testing
- Follow all lab safety rules
- Be aware of others working nearby
Theory
Answer the following questions on paper.
- Identify and explain the main subsystems of a robot:
- Power system
- Controller (microcontroller or processor)
- Sensors
- Actuators
- Structure/chassis
- Describe how sensors provide inputs to a robot.
- Explain how a controller processes these inputs.
- Describe how actuators create outputs.
- Draw a block diagram showing signal flow in a simple robot.
- Choose three different sensors commonly used in robotics (e.g., ultrasonic, line sensor, button, light sensor) and explain:
- What each sensor measures
- What kind of signal it produces
- How the robot can use that information
- How are DC motors different from servos?
- Why motor drivers are needed between controllers and motors?
- Explain what could happen if:
- A motor stalls
- A sensor is miswired
- Power polarity is reversed
- Identify two real-world robotic applications (industry, healthcare, transportation, exploration, etc.) and explain what sensors and actuators those robots likely use.
Practice - Object-Tracking Webcam
In this project, you are building a system with two main “brains” that talk to each other:
- The Big Brain (Your Computer): Uses Python, OpenCV, and your webcam to “see” the world, find a face or a ball, and calculate where it is on the screen.
- The Muscle (microcontroller such as a Raspberry Pi Pico): Uses MicroPython to listen for commands from the computer and physically move the pan (left/right) and tilt (up/down) servos.
- The Nervous System (USB Serial): A USB cable connecting the two, sending text-based commands from the computer to the microcontroller.
Materials
- Raspberry Pi Pico (or similar microcontroller)
- USB cable for microcontroller
- 2 9g micro servos
- breadboard
- 6 m-m jumper wires
- 3D printed pan-tilt camera brackets (such as this)
- USB webcam
- computer with Thonny installed
Assembling the System
Standard hobby servos (like the common blue SG90 micro servos) have three wires. They are usually color-coded like this:
- Brown or Black: Ground (GND)
- Red: Power (Usually 5V)
- Yellow or Orange: Signal (PWM)
- Connect the Grounds: Connect the Brown/Black wires from both servos to any of the GND pins on your microcontroller.
- Connect the Power: Connect the Red wires from both servos to the VBUS pin. This pin takes the 5V directly from your computer’s USB port.
- Connect the Signals: Connect the Yellow/Orange wire from each servo to a different General Purpose Input/Output (GPIO) pin. (For example, GP15).
- Use a USB cable to connect the microcontroller to the computer.
- Connect the USB webcam to your computer.
Note: Moving two servos at the same time can use a lot of electrical current. If your microcontroller suddenly disconnects or restarts when the servos move, you will need to power the servos using a separate external 5V source. Remember to connect the ground of the battery pack to the ground of the microcontroller.
Programming the Muscle
Your first goal is to make the Pico move the servos based on text commands. You will use Thonny and Google Gemini for this.
- Initialize the Hardware: Set up your two servo pins using Pulse Width Modulation (PWM). You’ll need to research how to set the correct frequency (usually 50Hz for servos) and duty cycle to move them.
- Create a Command Listener: Write a loop that constantly checks for incoming data over the USB serial connection. You can use standard input reading commands (like reading a line of text) in MicroPython.
- Parse the Data: Decide on a format for your commands. For example, your computer might send “X90 Y45\n”. Your Pico needs to read that string, split it up, and understand that the pan servo goes to 90 degrees and the tilt servo goes to 45 degrees.
- Move the Servos: Map those numbers to the correct PWM duty cycles and update the servos.
- Test: Before connecting the computer’s Python script, use Thonny’s shell to manually type in commands (like “X90 Y90”) and press Enter to see if your servos move correctly.
Programming the Brain
Write (or vibe-code) a Python script on your computer to process the video feed.
- Capture the Video: Use OpenCV to access your webcam and start reading frames in a continuous while loop.
- Find the Object: Look up OpenCV’s Color Masking (converting the image to HSV color space and finding contours).
- Calculate the Center: Once OpenCV finds your object, it will give you a bounding box (X, Y, Width, Height). You need to calculate the exact (x, y) center coordinate of that box.
Communicating from the Brain
The computer needs to tell the microcontroller what to do based on where the object is.
- Open a Serial Connection: Use the pyserial library in Python to open a connection to the COM port (Windows) or /dev/tty port (Mac/Linux) that your Pico is plugged into.
- Calculate the Error: Find the center of your webcam’s overall video frame (e.g., if your camera is 640x480, the center is 320, 240). Compare the object’s center to the frame’s center. If the object is at X=400, it’s too far to the right!
- Generate the Command: Write logic that says: “If the object is too far right, decrease the pan angle. If it’s too high, increase the tilt angle.”
- Send the Command: Format your new angles into the string format you decided on in Step 1 (e.g., “X85 Y50\n”) and send it over the serial port.
Tuning and Refinement
Your camera will probably track the object, but it might jitter wildly or overshoot! Welcome to the world of control systems.
- Deadbands: Don’t tell the servos to move if the face is almost in the center. Create a “deadband” or a safe zone in the middle of the screen where the servos do nothing.
- Proportional Movement: Instead of moving the servo by a fixed 1 degree every frame, make it move proportionally! If the face is really far from the center, move the servo by 5 degrees. If it’s only slightly off-center, move it by 1 degree.
Demonstration
Once you are satisfied with how your system performs, demonstrate it to some classmates and your teacher.
Reflection
- How does this robot arm resemble industrial automation systems or commercially available products?
- What skills here apply to CNC machines or drones?
- What was challenging?
- What worked well?
- Explain how the skills learned here prepare you for:
- advanced robotics learning
- future robotics or technology careers