From 7a21e9499bf969031c10818a4bf0f50dbb117632 Mon Sep 17 00:00:00 2001 From: zwarenelle Date: Fri, 28 Jun 2024 15:40:47 +0200 Subject: [PATCH] add second motor --- src/Client/RobotController/Motor.cs | 10 +++---- src/Client/RobotController/stepper.py | 41 +++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Client/RobotController/Motor.cs b/src/Client/RobotController/Motor.cs index 2c16abc..dd3262c 100644 --- a/src/Client/RobotController/Motor.cs +++ b/src/Client/RobotController/Motor.cs @@ -4,16 +4,16 @@ using System.Text; namespace RobotController { - class Motor(int stepOne, int dirOne, int stepTwo, int dirTwo) + class Motor(int stepLeft, int dirLeft, int stepRight, int dirRight) { StringBuilder outputBuilder; ProcessStartInfo processStartInfo; Process process; - public int STEP_PIN1 { get; set; } = stepOne; - public int DIR_PIN1 { get; set; } = dirOne; - public int STEP_PIN2 { get; set; } = stepTwo; - public int DIR_PIN2 { get; set; } = dirTwo; + public int _stepLeft { get; set; } = stepLeft; + public int _dirLeft { get; set; } = dirLeft; + public int _stepRight { get; set; } = stepRight; + public int _dirRight { get; set; } = dirRight; public void Drive(bool direction, int steps) { diff --git a/src/Client/RobotController/stepper.py b/src/Client/RobotController/stepper.py index fa198c2..4ab4a74 100644 --- a/src/Client/RobotController/stepper.py +++ b/src/Client/RobotController/stepper.py @@ -2,16 +2,45 @@ import RPi.GPIO as GPIO from RpiMotorLib import RpiMotorLib import time import sys +import threading -direction= 23 # Direction (DIR) GPIO Pin -step = 22 # Step GPIO Pin +# Motor pins +stepLeft = 22 +dirLeft = 23 +enableLeft = 24 + +stepRight = 25 +dirRight = 26 +enableRight = 27 + +def init(): + GPIO.setup(enableLeft, GPIO.OUT) + GPIO.setup(enableRight, GPIO.OUT) + + motorLeft = RpiMotorLib.A4988Nema(dirLeft, stepLeft, (21,21,21), "DRV8825") + motorRight = RpiMotorLib.A4988Nema(dirRight, stepRight, (21,21,21), "DRV8825") def drive(): - mymotortest = RpiMotorLib.A4988Nema(direction, step, (21,21,21), "DRV8825") + GPIO.output(enableLeft, GPIO.LOW) + motorLeft.motor_go(False, # True=Clockwise, False=Counter-Clockwise + "Full" , # Step type (Full,Half,1/4,1/8,1/16,1/32) + 200, # number of steps + .0005, # step delay [sec] + False, # True = print verbose output + .05) # initial delay [sec] + GPIO.output(enableLeft, GPIO.HIGH) - mymotortest.motor_go(False, "Full", 200, 0.0005, False, .05) + GPIO.output(enableRight, GPIO.LOW) + motorRight.motor_go(False, # True=Clockwise, False=Counter-Clockwise + "Full" , # Step type (Full,Half,1/4,1/8,1/16,1/32) + 200, # number of steps + .0005, # step delay [sec] + False, # True = print verbose output + .05) # initial delay [sec] + GPIO.output(enableRight, GPIO.HIGH) - GPIO.cleanup() +def shutdown(): +GPIO.cleanup() # clear GPIO allocations after run if __name__ == '__main__': - globals()[sys.argv[1]]() \ No newline at end of file + globals()[sys.argv[1]]()