Mar-21-2021, 05:17 PM
Hello,
I am developing a cablecam around a raspberry and I have bounce problems with the translation motor.
This camera and others, aim to record music groups in live sessions
The motor has a dual control:
1 °) via a web server a left right and stop command
2 °) via 2 limit switches (hall effect sensors) with 2 magnets at the ends of the cable
my concern is that I have random operations or the motor does the opposite of what we ask it to do
here is the part of the code concerned
I am developing a cablecam around a raspberry and I have bounce problems with the translation motor.
This camera and others, aim to record music groups in live sessions
The motor has a dual control:
1 °) via a web server a left right and stop command
2 °) via 2 limit switches (hall effect sensors) with 2 magnets at the ends of the cable
my concern is that I have random operations or the motor does the opposite of what we ask it to do
here is the part of the code concerned
class PiTZ:
MoteurOutputPinL=24
MoteurOutputPinR=23
MoteurOutputPinN=18
TiltSensorPin = 19
TiltSensorPin2 = 16
Moteur_status = ""
t=0.05
def __init__(self):
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(self.MoteurOutputPinL, GPIO.OUT)
GPIO.setup(self.MoteurOutputPinR, GPIO.OUT)
GPIO.setup(self.MoteurOutputPinN, GPIO.OUT)
GPIO.setup(self.TiltSensorPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(self.TiltSensorPin2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
self.Pwm()
self.loop()
self.configCall("default")
self.initPan()
self.initTilt()
self.initZoom()
self.initFocus()
self.initIrCut()
self.initIMG()
self.initccMan()
def Pwm(self):
self.V1=GPIO.PWM(self.MoteurOutputPinN, 1000)
self.V1.start(0)
def initccMan(self):
self.ccMan()
self.ccManStop()
def ccMan(self,ccDir=""):
global Moteur_status
self.Moteur_status = not self.Moteur_status
GPIO.output(self.MoteurOutputPinL, self.Moteur_status)
GPIO.output(self.MoteurOutputPinR, self.Moteur_status)
GPIO.output(self.MoteurOutputPinN, self.Moteur_status)
if self.Moteur_status == 1 or ccDir=="ccleft":
GPIO.output(self.MoteurOutputPinL,GPIO.HIGH)
GPIO.output(self.MoteurOutputPinR,GPIO.LOW)
GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
for dc in range(0, 101, 10):
self.V1.ChangeDutyCycle(dc)
time.sleep(self.t)
elif self.Moteur_status == 0 or ccDir=="ccright":
GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
GPIO.output(self.MoteurOutputPinR,GPIO.HIGH)
GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
for dc in range(0, 101, 10):
self.V1.ChangeDutyCycle(dc)
time.sleep(self.t)
def ccManStop(self,ccstop=""):
if ccstop=="ccstop" and self.Moteur_status == 1:
GPIO.output(self.MoteurOutputPinL,GPIO.HIGH)
GPIO.output(self.MoteurOutputPinR,GPIO.LOW)
GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
for dc in range(100, -1, -10):
self.V1.ChangeDutyCycle(dc)
time.sleep(self.t)
elif ccstop=="ccstop" and self.Moteur_status == 0:
GPIO.output(self.MoteurOutputPinL,GPIO.LOW)
GPIO.output(self.MoteurOutputPinR,GPIO.HIGH)
GPIO.output(self.MoteurOutputPinN,GPIO.HIGH)
for dc in range(100, -1, -10):
self.V1.ChangeDutyCycle(dc)
time.sleep(self.t)
def loop(self):
GPIO.add_event_detect(self.TiltSensorPin, GPIO.FALLING, callback=self.ccMan, bouncetime = 5000)
GPIO.add_event_detect(self.TiltSensorPin2, GPIO.FALLING, callback=self.ccMan, bouncetime = 5000)merci beaucoup
