so i got this code:
Code: Select all
#! /usr/env/python
from Phidget22.Phidget import *
from Phidget22.Devices.DigitalInput import *
from Phidget22.Devices.Stepper import *
import time
#Stepper moving up
def motorHoch():
mot4 = Stepper()
mot4.setHubPort(0)
mot4.setDeviceSerialNumber(682067)
mot4.openWaitForAttachment(5000)
mot4.setAcceleration(1000000)
mot4.setVelocityLimit(15000)
mot4.setTargetPosition(10000)
mot4.setEngaged(True)
while mot4.getIsMoving():
time.sleep(0.1) # Eine kurze Verzögerung, um unnötige CPU-Auslastung zu vermeiden
mot4.close()
pass
#Stepper moving down
def motorRunter():
mot4 = Stepper()
# print("1")
mot4.setHubPort(0)
# print("2")
mot4.setDeviceSerialNumber(682067)
# print("3")
mot4.openWaitForAttachment(5000)
# print("4")
mot4.setAcceleration(1000000)
mot4.setVelocityLimit(15000)
mot4.setTargetPosition(-10000)
# print("5")
mot4.setEngaged(True)
# print("6")
while mot4.getIsMoving():
time.sleep(0.1) # Eine kurze Verzögerung, um unnötige CPU-Auslastung zu vermeiden
# print("7")
mot4.close()
# print("8")
pass
#stepper stopp
def motorStopp():
mot4 = Stepper()
# print("1")
mot4.setHubPort(0)
# print("2")
mot4.setDeviceSerialNumber(682067)
# print("3")
mot4.openWaitForAttachment(5000)
# print("4")
mot4.setTargetPosition(0)
# print("5")
mot4.setEngaged(False)
# print("6")
while mot4.getIsMoving():
time.sleep(0.1) # Eine kurze Verzögerung, um unnötige CPU-Auslastung zu vermeiden
# print("7")
mot4.close()
pass
#status of digital input
def onStateChangeTop(self, state):
print("State [" + str(self.getHubPort()) + "]: " + str(state))
pass
def main():
# Initialisierung Endschalter oben
digitalInputTop = DigitalInput()
digitalInputBot = DigitalInput()
digitalInputTop.setIsHubPortDevice(True)
digitalInputTop.setHubPort(3)
digitalInputTop.setDeviceSerialNumber(682056)
digitalInputBot.setIsHubPortDevice(True)
digitalInputBot.setHubPort(3)
digitalInputBot.setDeviceSerialNumber(682057)
digitalInputTop.setOnStateChangeHandler(onStateChangeTop)
digitalInputBot.setOnStateChangeHandler(onStateChangeTop)
digitalInputTop.openWaitForAttachment(5000)
digitalInputBot.openWaitForAttachment(5000)
digitalInputTop.getState()
digitalInputBot.getState()
#try:
# input("Press Enter to Stop\n")
#except (Exception, KeyboardInterrupt):
# pass
#loop for stepper moving up until the upper input is 0 and then moving down until the lower input is 0
bool1 = False
while True:
if digitalInputTop.getState() and digitalInputBot.getState() and bool1 == False:
motorHoch()
print("oben =", digitalInputTop.getState())
continue
bool1 = True
if digitalInputBot.getState() and bool1 == True:
motorRunter()
print("oben =", digitalInputTop.getState())
continue
else:
motorStopp()
print("unten =", digitalInputBot.getState())
break
digitalInputTop.close()
digitalInputBot.close()
The problem is that the stepper motor moves in small increments of 10,000 steps. How can I make it move smoothly and consistently without these small increments?
Thank you for your help