This project involves programming a lobster-shaped autonomous vehicle designed to navigate a model village, pick up blocks, and deposit them in the appropriate recycling centers based on their recyclability. The vehicle uses sensors and actuators to perform line following, object detection, block manipulation, and decision-making.
The system is implemented using two main files:
- IDP_lib.h: Contains class definitions, global variables, and function declarations for controlling the robot's hardware components and sensors.
- system.ino: Contains the main logic and control flow for the robot's navigation and block handling tasks.
This file includes necessary libraries and defines key components:
-
Libraries:
- Motor control (Adafruit Motor Shield)
- IMU sensors (LSM6DS3)
- Servo control
- Distance sensors (DFRobot_VL53L0X)
-
Sensors and Actuators:
- Hall effect sensors for magnet detection
- Line sensors for navigation
- Time-of-Flight distance sensor for block detection
- DC motors for movement
- Servos for claw control
- LEDs for status indication
-
Classes:
MainMotors: Controls the main drive motors, including speed and directional control.Servo_claws: Manages the servo-operated claws for picking up and releasing blocks.LED_indicator: Controls the status LEDs.
-
Functions:
- Sensor reading functions
- Line tracking functions
- Movement and turning functions
This file contains the main program logic:
-
Constants:
- Turn direction definitions for navigation
- Path arrays defining the robot's route
-
Variables:
- Navigation progress indicators
- Special mode flags for handling different scenarios
-
Functions:
drop_off(): Handles the block dropping mechanism at recycling centers.grab_from_nook(): Manages block collection from specific positions.turn_junction(): Determines robot movement at junctions.get_turn_direction(): Retrieves the next movement direction based on the path.system_decisions(): Core decision-making process based on sensor inputs.loop(): Main program loop that calls decision functions.setup(): Initializes hardware components and configurations.pick_up_block(): Executes the block pickup routine.
Ensure the following libraries are included in the project:
- Adafruit Motor Shield library
- Arduino_LSM6DS3 library
- Servo library
- Wire library
- DFRobot_VL53L0X library
- Install the required libraries.
- Connect the hardware components according to their respective pins defined in
IDP_lib.h. - Upload
system.inoto the microcontroller, ensuringIDP_lib.his included in the project directory.
- The robot follows a predefined path to navigate the model village.
- It uses line sensors to stay on track and detect junctions.
- Magnetic sensors determine if a block is recyclable.
- The robot picks up blocks using servo-operated claws.
- Blocks are deposited in the appropriate recycling centers based on sensor readings.
- Navigation: Implemented using line tracking and a path array defining the sequence of moves.
- Block Handling: The robot picks up blocks when detected and determines recyclability.
- Decision Making: Sensor inputs inform movement decisions.
- Actuator Control: Motor speeds and directions are controlled based on navigation needs.
The navigation system enables the robot to traverse the model village accurately. It relies on line sensors to detect the path and junctions.
- Configuration: Four line sensors connected to digital pins 4, 5, 6, and 7.
far_left_sensor(pin 4)left_sensor(pin 5)right_sensor(pin 6)far_right_sensor(pin 7)
- Functionality: The sensors detect black lines on a white surface, enabling the robot to follow the path and recognize junctions.
- Implementation:
read_line_sensors(): Reads the state of each sensor and updates the corresponding variables.get_line_state(): Interprets the sensor readings to determine the robot's position relative to the line and identify junctions.
- Algorithm: The robot adjusts its motor speeds based on sensor inputs to stay centered on the line.
- Functions:
line_track_forward(int forward_speed): Controls the motors to maintain alignment with the line while moving forward.move_forward_tracking(int dist): Moves the robot forward while tracking the line for a specified distance.
- Detection: Junctions are identified when specific patterns are detected by the line sensors.
- Decision Making: The robot uses the
path[]array to decide whether to turn left, right, or continue straight. - Implementation:
turn_junction(int turn_direction): Executes the appropriate maneuver at a junction based on the turn direction.
The block handling system allows the robot to pick up blocks and deposit them at the correct recycling centers.
- Sensor: A Time-of-Flight (ToF) distance sensor (
DFRobot_VL53L0X) measures the distance to potential blocks. - Functionality: The robot detects blocks within a set distance (typically 40mm) and initiates the pickup sequence.
- Implementation:
- Regularly checks
tof_block_distanceto determine if a block is nearby.
- Regularly checks
- Sensors: Two Hall effect sensors (
hallPinLefton A0 andhallPinRighton A1) detect magnetic fields. - Purpose: Determines if the block is magnetic (recyclable) or non-magnetic.
- Implementation:
read_magnet_sensor(): Reads analog values from the Hall effect sensors and setsis_magnetbased on a threshold.
- Hardware: Two servos control the left and right claws for gripping blocks.
- Class:
Servo_clawsmanages the servo positions. - Functions:
open(): Opens the claws to grab or release a block.close(): Closes the claws to hold a block securely.straight_ahead(): Positions the claws forward during normal movement.
- Process:
- Detect block using the distance sensor.
- Stop the robot and open the claws.
- Move forward to position the claws around the block.
- Close the claws to secure the block.
- Update
has_blocktotrue.
- Implementation:
pick_up_block(): Handles the entire pickup sequence.
- Process:
- Navigate to the recycling center.
- Move forward into the deposit area.
- Open the claws to release the block.
- Reverse to exit the deposit area.
- Close the claws and reset
has_block.
- Implementation:
drop_off(): Manages the drop-off sequence.
The robot's behavior is determined by sensor inputs and a predefined path.
- Path Array:
path[]defines a sequence of directions the robot should follow. - Special Modes:
special_modeandspecial_pathhandle specific scenarios, such as reaching recycling centers.
- Function:
system_decisions(). - Logic:
- Checks for blocks ahead.
- Determines if a junction is present.
- Decides on actions based on the current state and path.
- Function:
get_turn_direction(). - Purpose: Determines the next movement direction from the path array.
- Implementation:
- Considers special modes and progress counters.
Detailed descriptions of the sensors used in the robot.
- Type: Infrared reflective sensors.
- Pins: Digital pins 4, 5, 6, 7.
- Reading Values: Outputs binary values indicating line presence.
- Type: Analog sensors detecting magnetic fields.
- Pins: Analog pins A0, A1.
- Calibration:
offsetLandoffsetRadjust for sensor zero points.magnet_thresholddefines sensitivity.
- Type: DFRobot_VL53L0X Time-of-Flight sensor.
- Functionality: Provides accurate distance measurements for block detection.
- Usage: Readings are stored in
tof_block_distance.
Details about the actuators controlling robot movement and interaction.
- Hardware: Two DC motors controlled via the Adafruit Motor Shield.
- Control:
MainMotorsclass provides methods for speed and direction control.- Implements functions for moving forward, backward, and turning.
- Calibration:
max_speedandmin_speedset speed limits.- Wheel specifications used for precise movement calculations.
- Hardware: Two standard servos for the claws.
- Control:
Servo_clawsclass manages servo angles.- Angles are calibrated for open and closed positions.
- Functions:
- Methods to open, close, and reset claws.
- Hardware: Two status LEDs connected to pins 8 and 11.
- Control:
LED_indicatorclass provides methods to control LEDs.- Used for signaling robot states (e.g., block detected, error).
The software architecture separates hardware control from logic.
- IDP_lib.h: Contains hardware abstractions and utility functions.
- system.ino: Implements the control logic using abstractions from
IDP_lib.h.
- Interrupts: Used for handling specific events (e.g., button presses).
- State Management: Variables track the robot's current state and progress.
Proper testing and calibration ensure reliable robot performance.
- Line Sensors: Adjust sensor positions and sensitivity.
- Hall Effect Sensors: Fine-tune
offsetL,offsetR, andmagnet_threshold. - Motors: Adjust
max_speedand ensure balanced movement. - Servos: Calibrate minimum and maximum angles for claw operation.
- Unit Tests: Test individual functions and classes.
- Integration Tests: Test combined systems (e.g., navigation with block handling).
- Field Tests: Run the robot in the model village to observe behavior.
Common issues and solutions. These are out of date currently. Refer to code itself for possible causes of errors. Most errors will come from mistuning.
- Causes:
- Misaligned line sensors.
- Uneven motor speeds.
- Solutions:
- Re-calibrate sensors.
- Check motor configurations.
- Causes:
- Faulty distance sensor.
- Incorrect threshold settings.
- Solutions:
- Test the distance sensor separately.
- Adjust detection thresholds.
- Causes:
- Servos not receiving signals.
- Incorrect servo angles.
- Solutions:
- Verify servo connections.
- Calibrate servo angles.
Contributions are welcome in the form of feedback. Please email lh848@cam.ac.uk.