<< Click to Display Table of Contents >> Navigation: MovingCap CODE - Python Programmierung > Ein einfaches Testprogramm |
Beispiel für MovingCap turnTRACK349 Ethernet oder andere Drehantriebe
Hier ist ein einfaches Beispiel für einen Drehmotor, der mit Winkelkoordinaten arbeiten soll (360° entsprechen einer Umdrehung):
#id driveSimplePosTest.py 2025-02-04 oh
# This is a simple positioning demo for a MovingCap turnTRACK 349 rotary drive.
import sys
import mcdrive as mc
def WaitTargetReached():
# Check statusword for "target reached"
while (mc.ChkReady() == 0):
sys.wait(1)
# only continue if no error
while (mc.ChkError() != 0):
sys.wait(1)
# check digital input IN2 - if low, add a second of pause/delay time
if mc.ChkIn(2) == 0:
sys.wait(1000)
# initial wait, don't surprise me with immediate movement
sys.wait(2000)
# Set 6092h.01h Feed constant to 360 --> one turn = 360°
mc.WriteObject(0x6092, 0x01, 360)
# general init
mc.EnableDrive()
mc.SetAcc(500)
mc.SetDec(500)
mc.SetPosVel(360)
# and go...
while(1):
# set digital output OUT1 to high during move to position 0
mc.SetOut(1)
mc.GoPosAbs(0)
WaitTargetReached()
# reset OUT1 to low
mc.ClearOut(1)
mc.GoPosAbs(1000)
WaitTargetReached()
mc.GoPosAbs(180)
WaitTargetReached()
•Speichen Sie dieses Programm in einer .py-Datei, z.B. als driveSimplePosTest.py .
•Öffnen Sie in der MovingCap-Weboberfläche den Bereich Code (Python)
•Wählen Sie über Browse.. diese Datei aus und klicken Sie auf den Upload Knopf rechts daneben.
•Stellen Sie sicher, dass der Antrieb gefahrlos in Betrieb gehen kann und starten Sie das Programm mit dem Knopf Run
Beispielprogramm für eine Linearachse mit voreingestellter Fahrbegrenzung (Softlimit)
Hier ein alternatives Demoprogramm, geeignet für einen Linearantrieb mit Mikrometer-Positionseinheiten. Die unten verwendete Geschwindigkeit mc.SetPosVel(50000)entspricht in diesem Fall 5cm/Sekunde.
#id driveSoftlimitBackForth.py 2024-07-25 oh
# simple MovingCap flatTRACK application demo
# precondition: softlimit objects 607Dh.1h and 607D.2h set
import sys
import mcdrive as mc
def ChkReady():
# Check statusword for "target reached"
while (mc.ChkReady() == 0):
sys.wait(1)
# only continue if no error
while (mc.ChkError() != 0):
sys.wait(1)
# safety: only run this script if softlimit objects are set up properly
softLimitMin = mc.ReadObject(0x607d, 1)
softLimitMax = mc.ReadObject(0x607d, 2)
if ((softLimitMin == 0 and softLimitMax == 0) or softLimitMax <= (softLimitMin + 1000)):
print("flatTRACK demo abort. Check softlimit objects 607Dh.1h and 607D.2h!")
else:
# initial wait, don't surprise me with immediate movement
sys.wait(5000)
# general init
mc.EnableDrive()
mc.SetAcc(50)
mc.SetDec(50)
mc.SetPosVel(50000)
# and go...
while(1):
mc.GoPosAbs(softLimitMin)
ChkReady()
mc.GoPosAbs(softLimitMax)
ChkReady()
•Speichen Sie dieses Programm wie oben beschrieben in einer .py-Datei und führen Sie in Ihrem MovingCap flatTRACK Linearantrieb aus.