From 8dc6be6cfc9ba6d0d4081477f4788953591a4d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Wed, 7 May 2025 14:58:15 +0200 Subject: [PATCH] testcode, to test engineclass --- raspberry/motors.py | 15 ++++++++++++--- raspberry/terradrone.py | 23 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/raspberry/motors.py b/raspberry/motors.py index eadfb2f..76e3bd3 100644 --- a/raspberry/motors.py +++ b/raspberry/motors.py @@ -1,13 +1,22 @@ #################################################################### # This file contains the code to control the motors of the robot. -# +# # The motors are controlled using PWM signals. # The code is designed to work with the L298N motor driver. # The code is designed to work with the Raspberry Pi 5. ###################################################################### from gpiozero import Motor, PWMOutputDevice -from time import sleep + class Motor: def __init__(self, motor_pin1, motor_pin2, pwm_pin): - pass \ No newline at end of file + pass + + def forward(self, speed): + pass + + def backward(self, speed): + pass + + def stop(self): + pass diff --git a/raspberry/terradrone.py b/raspberry/terradrone.py index 2601517..128e5de 100644 --- a/raspberry/terradrone.py +++ b/raspberry/terradrone.py @@ -2,9 +2,28 @@ # This file contains the main code to control the robot. # #################################################################### +from motors import Motor + def main(): - pass + leftMotor = Motor(17, 18, 22) + rightMotor = Motor(23, 24, 25) + + while True: + # Move forward + leftMotor.forward(50) + rightMotor.forward(50) + + # Move backward + wait(10) + leftMotor.backward(50) + rightMotor.backward(50) + + # Stop + leftMotor.stop() + rightMotor.stop() + wait(50) + if __name__ == "__main__": - main() \ No newline at end of file + main()