Python Forum
python 3 raspberry pi 4 dual control motor programming problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3 raspberry pi 4 dual control motor programming problem
#1
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
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Programming robots using Python OscarBoots 5 1,741 Oct-31-2021, 09:38 AM
Last Post: Larz60+
  Coding for Python and Raspberry pi beast 3 1,113 Sep-21-2021, 09:56 PM
Last Post: beast
  Stepper motor/Easy Driver/HELP Harney 1 1,088 Jul-31-2021, 08:05 AM
Last Post: Harney
Lightbulb Object Oriented programming (OOP) problem OmegaRed94 6 1,878 May-31-2021, 07:19 PM
Last Post: OmegaRed94
  db migration(db version control) for python lubaz 2 1,842 May-30-2021, 01:36 PM
Last Post: lubaz
  Embedded python fails to compile on Raspberry Pi tryfon 2 2,266 Dec-22-2020, 02:06 PM
Last Post: tryfon
  Understanding Raspberry PI RTS/CTS flow control zazas321 2 2,432 Oct-30-2020, 09:55 AM
Last Post: zazas321
  Understanding Raspberry PI RTS/CTS flow control zazas321 0 1,057 Oct-30-2020, 08:02 AM
Last Post: zazas321
  Uploading files to NAS from Raspberry PI using python zazas321 0 1,655 Sep-07-2020, 09:02 AM
Last Post: zazas321
  stepper motor and servo key control cel 4 1,693 Jul-27-2020, 06:26 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020