This repo contains Python code that can control an Elegoo Smart Car V4 using commands similar to Python Turtle.
Connect your computer wifi network exposed by the robot.
Run:
python main.py
The robot will drive around looking for green duplo.
The Car
class communicates with the robot and exposes methods similar to a turtle for simple programming.
In particular Car
handles heartbeating with the robot to prevent it disconnecting.
start()
- Connects to the comms socket and starts the heartbeating threadclose()
- Disconnects and shuts down heartbeatingstop()
- Stops all motorsforward(distance = None)
- move forward untilstop()
is called.forward(distance = 1)
- move forward 1 distance unit.backward(distance = None)
- move backward untilstop()
is called.backward(distance = 1)
- move backward 1 distance unit.left(angle = 45)
- Turn left approximatelyangle
amount.right(angle = 45)
- Turn right approximatelyangle
amount.rotate_camera_left()
- Rotate camera and distance sensor component 90 degress left.rotate_camera_right()
- Rotate camera and distance sensor component 90 degress right.rotate_camera_forward()
- Rotate camera and distance sensor component straight ahead.measure_dist()
- Returns distance measured by distance sensor.check_off_ground()
- Returns True if the car detects it has been lifted off the ground.capture_image()
- Captures the current image as a NumPy array.find_coloured_shape(lower, upper)
- Finds the biggest shape the camera can see within thelower
andupper
colour bounds. ReturnscX
- centre of shape or -1 if not found;cY
- centre of shape or -1 if not found,area
or shape,image
- capture image with shape drawn on.
- The car cannot measure distances or angles so moving or turning by an anmount are done based on time, as such they are approximate and are affected by battery level, grip on suface etc.
- run
python hsvThresholder.py
to experiment withlower
andupper
HSV values for object detection.
Thanks for inspiration from the following: