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


Messages In This Thread
python 3 raspberry pi 4 dual control motor programming problem - by yome - Mar-21-2021, 05:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create dual folder on different path/drive based on the date agmoraojr 2 375 Jan-21-2024, 10:02 AM
Last Post: snippsat
  Can someone help me solve this programming problem? SuchUmami 6 831 Nov-20-2023, 10:01 AM
Last Post: EdwardMatthew
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,179 Feb-24-2023, 06:14 PM
Last Post: deanhystad
Question Linear Programming Problem Axel_LF 0 697 Feb-23-2023, 11:03 PM
Last Post: Axel_LF
  Programming robots using Python OscarBoots 5 3,352 Oct-31-2021, 09:38 AM
Last Post: Larz60+
  Coding for Python and Raspberry pi beast 3 39,215 Sep-21-2021, 09:56 PM
Last Post: beast
  Stepper motor/Easy Driver/HELP Harney 1 1,852 Jul-31-2021, 08:05 AM
Last Post: Harney
Lightbulb Object Oriented programming (OOP) problem OmegaRed94 6 2,860 May-31-2021, 07:19 PM
Last Post: OmegaRed94
  db migration(db version control) for python lubaz 2 2,699 May-30-2021, 01:36 PM
Last Post: lubaz
  Embedded python fails to compile on Raspberry Pi tryfon 2 3,397 Dec-22-2020, 02:06 PM
Last Post: tryfon

Forum Jump:

User Panel Messages

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