Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) class Motor: def __init__(self, EnaA, In1A, In2A, EnaB, In1B, In2B): self.EnaA = EnaA self.In1A =
import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) class Motor: def __init__(self, EnaA, In1A, In2A, EnaB, In1B, In2B): self.EnaA = EnaA self.In1A = In1A self.In2A = In2A self.EnaB = EnaB self.In1B = In1B self.In2B = In2B GPIO.setup(self.EnaA, GPIO.OUT) GPIO.setup(self.In1A, GPIO.OUT) GPIO.setup(self.In2A, GPIO.OUT) GPIO.setup(self.EnaB, GPIO.OUT) GPIO.setup(self.In1B, GPIO.OUT) GPIO.setup(self.In2B, GPIO.OUT) self.pwmA = GPIO.PWM(self.EnaA,100) self.pwmA.start(0) self.pwmB = GPIO.PWM(self.EnaB,100) self.pwmB.start(0) def move(self, motorA, motorB): GPIO.output(self.In1A, GPIO.LOW) GPIO.output(self.In2A, GPIO.HIGH) GPIO.output(self.In1B, GPIO.LOW) GPIO.output(self.In2B, GPIO.HIGH) self.pwmA.ChangeDutyCycle(motorA) self.pwmB.ChangeDutyCycle(motorB) def start(self, s): for i in range(0, s): i = i + 1 sleep(0.01) self.pwmA.ChangeDutyCycle(i) self.pwmB.ChangeDutyCycle(i) return def stop(self, s=0): self.pwmA.ChangeDutyCycle(s) self.pwmB.ChangeDutyCycle(s) def motormain(self, speed, diva, angl): Motor.move(True,speed-angl+diva//10,speed+angl-diva//10) return if __name__ == '__main__': motor = Motor(20, 25, 8, 7, 1, 21) motor.motormain(70,100,40)
############################################
I get an error while executing the code:
Traceback (most recent call last): File "/home/pi/tmp/402V1.0/tmp/pycharm_project_34/Motor.py", line 51, in
Process finished with exit code 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started