Want Assist in the Raspberry Pi code : raspberry_pi

That is my code==>

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.pwmB=GPIO.PWM(self.ENAb,100)
self.pwmA.begin(0)
self.pwmB.begin(0)

def transfer(self,pace=0.5,flip=0,t=0):
pace *=100
flip *=70
lspeed=speed-turn
rspeed=pace+flip
if lspeed>100:
lspeed=100
elif lspeed<-100:
lspeed=-100
if rspeed>100:
rspeed=100
elif rspeed<-100:
rspeed=-100
self.pwmA.ChangeDutyCycle(abs(lspeed))
self.pwmB.ChangeDutyCycle(abs(rspeed))
sleep(t)

def cease(self,t=0):
self.pwmA.ChangeDutyCycle(0)
self.pwmB.ChangeDutyCycle(0)
sleep(t)
if __name__ == '__main__':
motor=Motor(25,23,24,16,20,21)
motor.transfer(50,0,2)
motor.cease(2)
I get this error once I run it==>

Traceback (most up-to-date name final):

File "/dwelling/pi/Desktop/motorcode.py", line 48, in <module>

motor=Motor(25,23,24,16,20,21)

File "/dwelling/pi/Desktop/motorcode.py", line 20, in __init__

self.pwmA=GPIO.PWM(self.ENAa,100)

RuntimeError: A PWM object already exists for this GPIO channel

Any assist shall be tremendously appreciated !!!



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *