commit f705faf83ea69439edacc78ef60fb167926f0bc6 Author: George_Andreou Date: Thu May 22 01:50:23 2025 +0300 Create repository for the folkrace competition. diff --git a/README.md b/README.md new file mode 100644 index 0000000..be343fb --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This is a repository for our robot in the folkrace competition of Robotex Cyprus. It uses a feather rp-2040 with a motor control featherwing as its brains as well as featuring meccanum wheels that will hopefully enable it to evade the obstacles better. \ No newline at end of file diff --git a/folkrace.py b/folkrace.py new file mode 100644 index 0000000..3122be4 --- /dev/null +++ b/folkrace.py @@ -0,0 +1,46 @@ +import time +import board +import adafruit_hcsr04 +from adafruit_motorkit import MotorKit + +# Set the motors +kit = MotorKit() +m1 = kit.motor1 +m2 = kit.motor2 +m3 = kit.motor3 +m4 = kit.motor4 + +# Set the sensor pins +front = adafruit_hcsr04.HCSR04(trigger_pin=board.D12, echo_pin=board.D13) +right = adafruit_hcsr04.HCSR04(trigger_pin=board.D10, echo_pin=board.D11) +left = adafruit_hcsr04.HCSR04(trigger_pin=board.D8, echo_pin=board.D9) + +def forward(): + m1.throttle = 1 + m2.throttle = 1 + m3.throttle = 1 + m4.throttle = 1 + +def backward(): + m1.throttle = -1 + m2.throttle = -1 + m3.throttle = -1 + m4.throttle = -1 + +while True: + print("F=", f"{front.distance:.2f}", "R=", f"{right.distance:.2f}", "L=", f"{left.distance:.2f}") + try: + if front.distance >= 20: # What to do when there is an obstacle ahead + if left.distance > right.distance: # Diagonally left + + if right.distance > left.distance: # Diagonally right + + if left.distance < 30: # Strafe right + + if right.distance < 30: # Strafe left + + else: + forward() + + except RuntimeError: + pass \ No newline at end of file diff --git a/sensortest.py b/sensortest.py new file mode 100644 index 0000000..82e8bbd --- /dev/null +++ b/sensortest.py @@ -0,0 +1,16 @@ +import time +import board +import adafruit_hcsr04 + +# Set the sensor pins +front = adafruit_hcsr04.HCSR04(trigger_pin=board.D12, echo_pin=board.D13) +right = adafruit_hcsr04.HCSR04(trigger_pin=board.D10, echo_pin=board.D11) +left = adafruit_hcsr04.HCSR04(trigger_pin=board.D8, echo_pin=board.D9) + +while True: + try: + print("F =", f"{front.distance:.2f}", "|", "L =", f"{left.distance:.2f}", "|", "R =", f"{right.distance:.2f}") + + except RuntimeError: + print("Retrying!") + time.sleep(0.1) \ No newline at end of file