Created
March 19, 2016 20:21
-
-
Save muehlburger/bd2f5be632c9896e400d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nanotec.*; | |
class Stellantrieb | |
{ | |
public static void main() | |
{ | |
int current = drive.GetCurrent(); //übernimmt den eingestellten "Phasenstrom während der Fahrt" | |
int input = 1; | |
while(true) | |
{ | |
boolean input0 = util.TestBit(input,0); | |
boolean input1 = util.TestBit(input,1); | |
boolean input2 = util.TestBit(input,2); | |
input = io.GetDigitalInput(); | |
if(input0 && !input1 && !input2) | |
{ | |
drive.SetMode(4); | |
drive.StartDrive(); | |
drive.SetCurrent(10); //setzt Phasenstrom auf 5% | |
while (drive.GetMode()==4) //Modusabfrage externe Referenzfahrt | |
{ | |
if(((drive.GetDemandPosition()-drive.GetEncoderPosition())>100)|| //Vergleicht die aktuelle Position mit der Encoderposition ob die Abweichung >100 oder <-100 ist | |
((drive.GetDemandPosition()-drive.GetEncoderPosition())<-100)) | |
{ | |
drive.StopDrive(0); //stoppt die Fahrt mit der quickstop Bremsrampe | |
util.Sleep(2000); //Wartezeit für Stop | |
drive.SetPosition(0); | |
drive.SetMode(0);//setzte Position 0 | |
} | |
} | |
if(!(util.TestBit(input,0))) | |
{ | |
drive.StopDrive(0); | |
util.Sleep(200); | |
break; | |
} | |
} | |
if(!(util.TestBit(input,0))& (util.TestBit(input,1))& !(util.TestBit(input,2))) | |
{ | |
drive.SetMode(1); | |
drive.SetCurrent(10); | |
drive.SetDirection(0); | |
drive.SetTargetPos(100); | |
drive.StartDrive(); | |
} | |
if(!(util.TestBit(input,0))& !(util.TestBit(input,1))& (util.TestBit(input,2))) | |
{ | |
drive.SetMode(1); | |
drive.SetCurrent(10); | |
drive.SetDirection(1); | |
drive.SetTargetPos(100); | |
drive.StartDrive(); | |
} | |
else | |
{ | |
drive.StopDrive(0); | |
util.Sleep(200); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment