add second motor

This commit is contained in:
zwarenelle
2024-06-28 15:40:47 +02:00
parent 046d57c6c2
commit 7a21e9499b
2 changed files with 40 additions and 11 deletions

View File

@@ -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)
{

View File

@@ -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]]()
globals()[sys.argv[1]]()