Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************/
- /* Programmname: PROJEKT func.h */
- /***************************************************/
- /* Programm: Grafische Darstellung und Simulation */
- /* eines Roboterarms */
- /* */
- /* Copyright: sasi
- /* */
- /* Datum: 30.01.2006 */
- /* */
- /***************************************************/
- //Bool erstellen (Für boolean datentype)
- enum bool {false, true};
- //Struktur von ZeichenFesnter (ViewPORTS)
- struct viewPortStruct
- {
- int left;
- int top;
- int right;
- int bottom;
- int clip;
- int hintergrund;
- int NullPunktVerschiebungX;
- } vPort1,vPort2,vPort3; //Direkte Deklaration
- //Struktur für Roboterarm Informationen
- struct robo_arm
- {
- double x1;
- double y1;
- double x2;
- double y2;
- double radius;
- char text[100];
- }ober_arm, unter_arm;
- //Struktur von Koordinaten system
- struct Koordinatensystem
- {
- float faktor;
- float x1;
- float x2;
- float y1;
- float y2;
- int farbe;
- float alfa;
- float beta;
- float alfa_alt;
- float beta_alt;
- } alpha_beta;
- //Struktur für Weltkoordinate
- struct weltStruct
- {
- float xmin;
- float xmax;
- float ymin;
- float ymax;
- } welt1, welt2 ,welt3;
- //Struktur fuer eingaben
- struct eingabefeld
- {
- char ex1[50];
- char ex2[50];
- char ey1[50];
- char ey2[50];
- char modi[10];
- } Input;
- //In Grafikmodus Umschalten
- void Load_BGI_Driver(char Treiberpfad[])
- {
- int Grafiktreiber, Grafikmodus;
- //Grafiktreiber bestimmen und Laden
- Grafiktreiber = DETECT;
- //Grafik initialiseren
- initgraph(&Grafiktreiber,&Grafikmodus,Treiberpfad);
- //Falls Fehler auftreten Programm mit Fehlermeldung beenden
- if(Grafiktreiber<=0)
- {
- cputs(grapherrormsg(Grafiktreiber));
- exit(1);
- }
- }
- //Zeigt die Umrisse des Übergebenen Viewports
- void VpShow(viewPortStruct viewPort)
- {
- setviewport(viewPort.left,
- viewPort.top,
- viewPort.right,
- viewPort.bottom,
- viewPort.clip);
- rectangle(0,0,
- (viewPort.right-viewPort.left),
- (viewPort.bottom-viewPort.top));
- //Füllt den raum mit hintergrundFarbe
- setfillstyle(1, viewPort.hintergrund);
- bar3d(0, 0,
- (viewPort.right-viewPort.left),
- (viewPort.bottom-viewPort.top), 0, 0);
- }
- //Zeichnet einen farbigen Punkt
- void VpPunkt(int x, int y, int farbe,viewPortStruct viewPort)
- {
- setviewport(viewPort.left,
- viewPort.top,
- viewPort.right,
- viewPort.bottom,
- viewPort.clip);
- putpixel(x,
- (viewPort.bottom-viewPort.top)-y,
- farbe);
- }
- //Zeichnet eine linie
- void VpLinie(int x1, int y1, int x2, int y2,viewPortStruct viewPort)
- {
- setviewport(viewPort.left,
- viewPort.top,
- viewPort.right,
- viewPort.bottom,
- viewPort.clip);
- line(x1,
- (viewPort.bottom-viewPort.top)-y1,
- x2,
- (viewPort.bottom-viewPort.top)-y2);
- }
- //Löscht den Inhalt eines ViewPorts
- void VpReset(viewPortStruct viewPort)
- {
- setviewport(viewPort.left,
- viewPort.top,
- viewPort.right,
- viewPort.bottom,
- viewPort.clip);
- clearviewport();
- }
- //Gezielte Text ausgabe
- void VpText(int x, int y, char Text[], viewPortStruct viewPort)
- {
- setviewport(viewPort.left,
- viewPort.top,
- viewPort.right,
- viewPort.bottom,
- viewPort.clip);
- outtextxy(x,
- (viewPort.bottom-viewPort.top)-y,
- Text);
- }
- //Welkoordinate in gerätekoordinate umwandeln
- int XWeltToViewPort(float xW, weltStruct welt, viewPortStruct viewPort)
- {
- double delta_xG, delta_xW, xG;
- int dummy;
- delta_xG=viewPort.right-viewPort.left;
- delta_xW=welt.xmax-welt.xmin;
- //xG=viewPort.left+((delta_xG/delta_xW)*(xW-welt.xmin));
- xG=((delta_xG/delta_xW)*(xW-welt.xmin));
- dummy = xG/1;
- if ((xG-0.5)<dummy)
- {
- dummy=floor(xG);
- }
- else
- {
- dummy=ceil(xG);
- }
- return dummy;
- }
- int YWeltToViewPort(float yW, weltStruct welt, viewPortStruct viewPort)
- {
- double delta_yG, delta_yW, yG;
- int dummy;
- delta_yG=(viewPort.bottom-viewPort.top);
- delta_yW=welt.ymax-welt.ymin;
- //yG=viewPort.top+((delta_yG/delta_yW)*(yW-welt.ymin));
- yG=((delta_yG/delta_yW)*(yW-welt.ymin));
- dummy = yG/1;
- if ((yG-0.5)<dummy)
- {
- dummy=floor(yG);
- }
- else
- {
- dummy=ceil(yG);
- }
- return dummy;
- }
- //Viewportszeichnen
- void InitViewPort1(void)
- {
- //Viewport1 erstellen
- vPort1.left = 10;
- vPort1.top = 10;
- vPort1.right = getmaxx()/2;
- vPort1.bottom = (getmaxy()*0.7);
- vPort1.clip = 1;
- vPort1.hintergrund = 9;
- vPort1.NullPunktVerschiebungX = vPort1.left;
- VpShow(vPort1);
- //Ende Viewport1
- }
- void InitViewPort2(void)
- {
- //ANfang Viewport2
- vPort2.left = vPort1.right+10;
- vPort2.top = vPort1.top;
- vPort2.right = getmaxx()-vPort1.left;
- vPort2.bottom = vPort1.bottom;
- vPort2.clip=1;
- vPort2.hintergrund = 9;
- vPort2.NullPunktVerschiebungX = vPort2.left;
- VpShow(vPort2);
- //Viewport2 ende
- }
- void InitViewPort3(void)
- {
- //ANfang Viewport3
- vPort3.left = vPort1.left;
- vPort3.top = vPort2.bottom+10;
- vPort3.right = vPort2.right;
- vPort3.bottom = getmaxy()-(vPort3.top-vPort2.bottom);
- vPort3.clip=1;
- vPort3.hintergrund = 9;
- vPort3.NullPunktVerschiebungX = vPort3.left;
- VpShow(vPort3);
- //Viewport3 ende
- }
- // Koordinate initialisieren
- void kord_achsen(void)
- {
- char Beschriftung[4];
- //Koordinaten Achsen
- VpLinie(XWeltToViewPort(alpha_beta.x1,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1,welt2,vPort2),
- XWeltToViewPort(alpha_beta.x2,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1,welt2,vPort2),
- vPort2);
- VpLinie(XWeltToViewPort(alpha_beta.x1,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1,welt2,vPort2),
- XWeltToViewPort(alpha_beta.x1,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y2,welt2,vPort2),
- vPort2);
- //Achsen beschriftung
- VpText(XWeltToViewPort(alpha_beta.x2+3,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1+3,welt2,vPort2),
- "Alpha",
- vPort2);
- VpText(XWeltToViewPort(alpha_beta.x1-13,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y2+13,welt2,vPort2),
- "Beta",
- vPort2);
- //Überschrift
- VpText(XWeltToViewPort(alpha_beta.x1+40,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y2+40,welt2,vPort2),
- "0 < Alpha < 180",
- vPort2);
- VpText(XWeltToViewPort(alpha_beta.x1+40,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y2+30,welt2,vPort2),
- "0 < Beta < 180",
- vPort2);
- //skalierung
- for (int i=0; i<=(alpha_beta.x2-alpha_beta.x1);i+=30)
- {
- VpLinie(XWeltToViewPort(alpha_beta.x1+i,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1,welt2,vPort2),
- XWeltToViewPort(alpha_beta.x1+i,welt2,vPort2),
- YWeltToViewPort((alpha_beta.y1+alpha_beta.faktor),welt2,vPort2),
- vPort2);
- if(i%30==0 || i==0)
- {
- sprintf(Beschriftung,"%d",i);
- VpText(XWeltToViewPort((alpha_beta.x1+i)-8,welt2,vPort2),
- YWeltToViewPort((alpha_beta.y1+alpha_beta.faktor)-5,welt2,vPort2),
- Beschriftung,
- vPort2);
- }
- }
- for (i=0; i<=alpha_beta.x2-alpha_beta.x1;i+=30)
- {
- VpLinie(XWeltToViewPort(alpha_beta.x1,welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1+i,welt2,vPort2),
- XWeltToViewPort((alpha_beta.x1+alpha_beta.faktor),welt2,vPort2),
- YWeltToViewPort(alpha_beta.y1+i,welt2,vPort2),
- vPort2);
- if(i%30==0 || i==0)
- {
- sprintf(Beschriftung,"%d",i);
- VpText(XWeltToViewPort((alpha_beta.x1+alpha_beta.faktor)-22,welt2,vPort2),
- YWeltToViewPort((alpha_beta.y1+i)+3,welt2,vPort2),
- Beschriftung,
- vPort2);
- }
- }
- }
- //Koordinaten kreuz zeichnen abhängig vom ALFA BETA
- void VpKoordinatenSystem(Koordinatensystem alpha_beta, viewPortStruct viewPort)
- {
- int col=getcolor();
- setcolor(alpha_beta.farbe);
- VpLinie(XWeltToViewPort((alpha_beta.x1+alpha_beta.alfa_alt),welt2,viewPort),
- YWeltToViewPort((alpha_beta.y1+alpha_beta.beta_alt),welt2,viewPort),
- XWeltToViewPort((alpha_beta.x1+alpha_beta.alfa),welt2,viewPort),
- YWeltToViewPort((alpha_beta.y1+alpha_beta.beta),welt2,viewPort),
- viewPort);
- setcolor(col);
- }
- //ROBOTER ARM ZEICHNEN
- bool ZeichneRobot(float alfa, float beta, viewPortStruct viewPort)
- {
- if ((beta>=0) && (beta<=180) && (alfa>=0) && (alfa<=180))
- {
- //Alte A B postionen merken
- alpha_beta.alfa_alt = alpha_beta.alfa;
- alpha_beta.beta_alt = alpha_beta.beta;
- alpha_beta.alfa = alfa;
- alpha_beta.beta = beta;
- VpKoordinatenSystem(alpha_beta, vPort2);
- int col=getcolor();
- setcolor(viewPort.hintergrund);
- //meldung löschen
- VpText(XWeltToViewPort(ober_arm.x1-50,welt1,viewPort),
- YWeltToViewPort(ober_arm.y1-50,welt1,viewPort),
- ober_arm.text,
- viewPort);
- //zeichne oberarm
- VpLinie(XWeltToViewPort(ober_arm.x1,welt1,viewPort),
- YWeltToViewPort(ober_arm.y1,welt1,viewPort),
- XWeltToViewPort(ober_arm.x2,welt1,viewPort),
- YWeltToViewPort(ober_arm.y2,welt1,viewPort),
- viewPort);
- //zeichner unterarm
- VpLinie(XWeltToViewPort(unter_arm.x1,welt1,viewPort),
- YWeltToViewPort(unter_arm.y1,welt1,viewPort),
- XWeltToViewPort(unter_arm.x2,welt1,viewPort),
- YWeltToViewPort(unter_arm.y2,welt1,viewPort),
- viewPort);
- //rechnet zum beta alfa dazu wenn beta konstat ist
- //und alfa sich ändert, muss beta so bleiben wie er war
- beta=alfa+beta;
- //beta=alfa-beta;
- ober_arm.x2 = ober_arm.x1+(ober_arm.radius*cos((alfa*M_PI)/(double)180.0));
- ober_arm.y2 = ober_arm.y1+(ober_arm.radius*sin((alfa*M_PI)/(double)180.0));
- unter_arm.x1 = ober_arm.x2;
- unter_arm.y1 = ober_arm.y2;
- unter_arm.x2 = ober_arm.x2-(unter_arm.radius*cos((beta*M_PI)/(double)180.0));
- unter_arm.y2 = ober_arm.y2-(unter_arm.radius*sin((beta*M_PI)/(double)180.0));
- setcolor(col);
- //zeichne oberarm
- VpLinie(XWeltToViewPort(ober_arm.x1,welt1,viewPort),
- YWeltToViewPort(ober_arm.y1,welt1,viewPort),
- XWeltToViewPort(ober_arm.x2,welt1,viewPort),
- YWeltToViewPort(ober_arm.y2,welt1,viewPort),
- viewPort);
- //zeichner unterarm
- VpLinie(XWeltToViewPort(unter_arm.x1,welt1,viewPort),
- YWeltToViewPort(unter_arm.y1,welt1,viewPort),
- XWeltToViewPort(unter_arm.x2,welt1,viewPort),
- YWeltToViewPort(unter_arm.y2,welt1,viewPort),
- viewPort);
- return true;
- }
- return false;
- }
- //Bewegt den RoboterArm Linear
- void BewegeLienar(float alfa1, float beta1, float alfa2, float beta2,viewPortStruct viewPort)
- {
- float delta_alfa, delta_beta;
- delta_alfa = alfa1 - alpha_beta.alfa;
- delta_beta = beta1 - alpha_beta.beta;
- if(alfa1>alpha_beta.alfa)
- {
- for(int d=alpha_beta.alfa; d<=alfa1; d++)
- {
- ZeichneRobot(d,(alpha_beta.beta+(delta_beta/delta_alfa)),viewPort);
- delay(50);
- }
- }
- else
- {
- for(int d=alpha_beta.alfa; d>=alfa1; d--)
- {
- ZeichneRobot(d,(alpha_beta.beta-(delta_beta/delta_alfa)),viewPort);
- delay(50);
- }
- }
- delay(500);
- delta_alfa = alfa2 - alpha_beta.alfa;
- delta_beta = beta2 - alpha_beta.beta;
- if(alfa2>alpha_beta.alfa)
- {
- for(int d=alpha_beta.alfa; d<=alfa2; d++)
- {
- ZeichneRobot(d,(alpha_beta.beta+(delta_beta/delta_alfa)),viewPort);
- delay(50);
- }
- }
- else
- {
- for(int d=alpha_beta.alfa; d>=alfa2; d--)
- {
- ZeichneRobot(d,(alpha_beta.beta-(delta_beta/delta_alfa)),viewPort);
- delay(50);
- }
- }
- }
- //bewegt das arm sequentiell
- void BewegeSequent(float alfa1, float beta1, float alfa2, float beta2,viewPortStruct viewPort)
- {
- //Sequentielle Bewegung
- if(alfa1>alpha_beta.alfa)
- {
- for(int i=alpha_beta.alfa; i<=alfa1; i++)
- {
- ZeichneRobot(i,alpha_beta.beta,viewPort);
- delay(50);
- }
- }
- else
- {
- for(int i=alpha_beta.alfa; i>=alfa1; i--)
- {
- ZeichneRobot(i,alpha_beta.beta,viewPort);
- delay(50);
- }
- }
- if(beta1>alpha_beta.beta)
- {
- for(int i=alpha_beta.beta; i<=beta1; i++)
- {
- ZeichneRobot(alpha_beta.alfa,i,viewPort);
- delay(50);
- }
- }
- else
- {
- for(int i=alpha_beta.beta; i>=beta1; i--)
- {
- ZeichneRobot(alpha_beta.alfa,i,viewPort);
- delay(50);
- }
- }
- delay(500);
- if(alfa2>alpha_beta.alfa)
- {
- for(int i=alpha_beta.alfa; i<=alfa2; i++)
- {
- ZeichneRobot(i,alpha_beta.beta,viewPort);
- delay(50);
- }
- }
- else
- {
- for(int i=alpha_beta.alfa; i>=alfa2; i--)
- {
- ZeichneRobot(i,alpha_beta.beta,viewPort);
- delay(50);
- }
- }
- if(beta2>alpha_beta.beta)
- {
- for(int i=alpha_beta.beta; i<=beta2; i++)
- {
- ZeichneRobot(alpha_beta.alfa,i,viewPort);
- delay(50);
- }
- }
- else
- {
- for(int i=alpha_beta.beta; i>=beta2; i--)
- {
- ZeichneRobot(alpha_beta.alfa,i,viewPort);
- delay(50);
- }
- }
- }
- //ermittelt aus x und y Wert den alfa winkel
- float GetRobotAlfa(float xWelt, float yWelt)
- {
- double a,b,c;
- float alfa, hilfe;
- //seitenlänge
- a=sqrt(((xWelt-ober_arm.x1)*(xWelt-ober_arm.x1))+((yWelt-ober_arm.y1)*(yWelt-ober_arm.y1)));
- b=unter_arm.radius;
- c=ober_arm.radius;
- //AlfaWinkel
- alfa=((c*c)+(a*a)-(b*b));
- alfa=alfa/(2*c*a);
- if(alfa!=0)
- {
- alfa=(acos(alfa)*180)/M_PI;
- }
- else
- {
- alfa=acos(alfa);
- }
- hilfe=(((xWelt-ober_arm.x1)*(xWelt-ober_arm.x1))+(a*a)-((yWelt-ober_arm.y1)*(yWelt-ober_arm.y1)));
- if(hilfe!=0)
- {
- hilfe=hilfe/(2*(xWelt-ober_arm.x1)*a);
- hilfe=(acos(hilfe)*180)/M_PI;
- }
- else
- {
- hilfe=90;
- }
- if(yWelt<0)
- {
- alfa=alfa-hilfe;
- return alfa;
- }
- else
- {
- alfa=alfa+hilfe;
- return alfa;
- }
- }
- //ermittelt aus x und y Wert den beta winkel
- float GetRobotBeta(float xWelt,float yWelt)
- {
- double a,b,c;
- float beta;
- //seitenlänge
- a=sqrt(((xWelt-ober_arm.x1)*(xWelt-ober_arm.x1))+((yWelt-ober_arm.y1)*(yWelt-ober_arm.y1)));
- b=unter_arm.radius;
- c=ober_arm.radius;
- //BetaWinkel
- beta=((c*c)+(b*b)-(a*a));
- if(beta!=0)
- {
- beta=beta/(2*b*c);
- beta=(acos(beta)*180)/M_PI;
- return beta;
- }
- return beta;
- }
- //Bewegt den Roboterarm an eine gewünschte Position
- bool BewegeRobot(float xStart, float yStart, float xEnde, float yEnde,int modi, viewPortStruct viewPort)
- {
- double a;
- //seitenlänge
- a=sqrt(((xStart-ober_arm.x1)*(xStart-ober_arm.x1))+((yStart-ober_arm.y1)*(yStart-ober_arm.y1)));
- if(a!=0 && !(a>ober_arm.radius+unter_arm.radius) && !(a<ober_arm.radius-unter_arm.radius))
- {
- //seitenlänge
- a=sqrt(((xEnde-ober_arm.x1)*(xEnde-ober_arm.x1))+((yEnde-ober_arm.y1)*(yEnde-ober_arm.y1)));
- if(a!=0 && !(a>ober_arm.radius+unter_arm.radius) && !(a<ober_arm.radius-unter_arm.radius))
- {
- if(modi==0)
- {
- BewegeLienar(GetRobotAlfa(xStart,yStart),
- GetRobotBeta(xStart,yStart),
- GetRobotAlfa(xEnde,yEnde),
- GetRobotBeta(xEnde,yEnde),
- viewPort);
- return true;
- }
- else
- {
- BewegeSequent(GetRobotAlfa(xStart,yStart),
- GetRobotBeta(xStart,yStart),
- GetRobotAlfa(xEnde,yEnde),
- GetRobotBeta(xEnde,yEnde),
- viewPort);
- return true;
- }
- }
- return false;
- }
- return false;
- }
- //steurungsinfo
- void infotxt(void)
- {
- char Text1[]="Tasten Belegung";
- char Text2[]="'B'-Beenden 'D'-Direkte Steuerung, 'E'-Eingabe, 'R'-Reset";
- char Text3[]="'4'-Links '6'-Rechts '2'-Runter '8'-Hoch";
- char Text4[300];
- sprintf(Text4,"Eingabegrenzen: X [%.0f, %.0f], Y [%.0f, %.0f]",
- ((ober_arm.radius+unter_arm.radius)*(-1)),
- (ober_arm.radius+unter_arm.radius),
- (ober_arm.radius+unter_arm.radius),
- (unter_arm.radius)*(-1));
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(115,welt3,vPort3),
- Text1,vPort3);
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(105,welt3,vPort3),
- Text2,vPort3);
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(95,welt3,vPort3),
- Text3,vPort3);
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(85,welt3,vPort3),
- Text4,vPort3);
- }
- //Lies die eingaben ein und speichert sie in die Struktur
- void read_key(char *txt, char *strukt,int zeile, viewPortStruct viewPort)
- {
- int komma=0;
- int vorzeichen=0;
- int minus=0;
- int eingabe;
- char zahl[30];
- strcpy(strukt, "");
- strcpy(zahl, "");
- do
- {
- eingabe=getch();
- switch(eingabe)
- {
- case 45:
- if(vorzeichen==0)
- {
- strcpy(zahl, "");
- sprintf(zahl,"%c", eingabe);
- strcat(strukt,zahl);
- VpText(XWeltToViewPort(10+textwidth(txt),welt3,viewPort),
- YWeltToViewPort(zeile,welt3,viewPort),
- strukt,viewPort);
- minus=1;
- ++vorzeichen;
- };break;
- case 46:
- if(komma==0)
- {
- if((minus==0 && vorzeichen>0) || (minus==1 && vorzeichen>1))
- {
- strcpy(zahl, "");
- sprintf(zahl,"%c", eingabe);
- strcat(strukt,zahl);
- VpText(XWeltToViewPort(10+textwidth(txt),welt3,viewPort),
- YWeltToViewPort(zeile,welt3,viewPort),
- strukt,viewPort);
- komma=1;
- ++vorzeichen;
- }
- };break;
- case 48: case 49: case 50:
- case 51: case 52: case 53:
- case 54: case 55: case 56:
- case 57:
- strcpy(zahl, "");
- sprintf(zahl,"%c", eingabe);
- strcat(strukt,zahl);
- VpText(XWeltToViewPort(10+textwidth(txt),welt3,viewPort),
- YWeltToViewPort(zeile,welt3,viewPort),
- strukt,viewPort);
- ++vorzeichen;
- break;
- }
- } while(eingabe!=13);
- }
- //Liest die werte über andere funktionen ein und ruft bewege robot auf
- bool Lese_Keyboard(void)
- {
- char Text1[300]="Bitte geben Sie die Start x und y Werte ein: X:";
- char Text2[300]="Bitte geben Sie die End x und y Werte ein: X:";
- char Text3[300]="Fuer Lineare Bewegung '0' sonst '1': Modi:";
- VpReset(vPort3);
- VpShow(vPort3);
- infotxt();
- int zeile=30;
- //xStart yStart
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(zeile,welt3,vPort3),
- Text1,vPort3);
- read_key(Text1, Input.ex1,zeile, vPort3);
- strcat(Text1,Input.ex1);
- strcat(Text1," Y:");
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(zeile,welt3,vPort3),
- Text1,vPort3);
- read_key(Text1, Input.ey1, zeile, vPort3);
- //xyStart-ende
- zeile=zeile-10;
- //xEnde yEnde
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(zeile,welt3,vPort3),
- Text2,vPort3);
- read_key(Text2, Input.ex2,zeile, vPort3);
- strcat(Text2,Input.ex2);
- strcat(Text2," Y:");
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(zeile,welt3,vPort3),
- Text2,vPort3);
- read_key(Text2, Input.ey2, zeile, vPort3);
- //xyStart-ende
- zeile=zeile-10;
- //modi Start
- VpText(XWeltToViewPort(10,welt3,vPort3),
- YWeltToViewPort(zeile,welt3,vPort3),
- Text3,vPort3);
- read_key(Text3, Input.modi,zeile, vPort3);
- //modi ende
- if(textwidth(Input.ex1)>0 && textwidth(Input.ey1)>0 && textwidth(Input.ex2)>0 && textwidth(Input.ey2)>0 && textwidth(Input.modi)>0)
- {
- if(!BewegeRobot(atof(Input.ex1),atof(Input.ey1),atof(Input.ex2),atof(Input.ey2),atof(Input.modi),vPort1))
- {
- //meldung
- VpText(XWeltToViewPort(ober_arm.x1-50,welt1,vPort1),
- YWeltToViewPort(ober_arm.y1-50,welt1,vPort1),
- ober_arm.text,
- vPort1);
- return true;
- }
- return false;
- }
- else
- {
- //meldung
- VpText(XWeltToViewPort(ober_arm.x1-50,welt1,vPort1),
- YWeltToViewPort(ober_arm.y1-50,welt1,vPort1),
- ober_arm.text,
- vPort1);
- }
- return false;
- }
- //ERSTE AUFRUF IM PROGRAMM
- void Main_Init(void)
- {
- //ViewPorts INITIALISIEREN UND ZEICHNEN
- InitViewPort1();
- InitViewPort2();
- InitViewPort3();
- //Roboterarm initialisieren
- ober_arm.radius = 100;
- unter_arm.radius = ((ober_arm.radius*70)/100);
- strcpy(ober_arm.text,"Nicht Ausfuehrbar");
- //WELTKOODINATE MIN MIX FÜR 3VP's
- //Weltkoordinaten punkte für ViewPort1
- welt1.xmax=ober_arm.x1+(ober_arm.radius+unter_arm.radius)+10;
- welt1.xmin=ober_arm.x1-(ober_arm.radius+unter_arm.radius)-10;
- welt1.ymax=ober_arm.y1+(ober_arm.radius+unter_arm.radius)+10;
- welt1.ymin=ober_arm.y1-(ober_arm.radius+unter_arm.radius)-10;
- //Weltkoordinaten punkte für ViewPort2
- welt2.xmin = -40;
- welt2.xmax = 230;
- welt2.ymin = -40;
- welt2.ymax = 230;
- //Weltkoordinaten punkte für ViewPort3
- welt3.xmin=0;
- welt3.xmax=vPort3.right-vPort3.left;
- welt3.ymin=0;
- welt3.ymax=vPort3.bottom-vPort3.top;
- //Roboterarm Usrpsrung
- ober_arm.x1 = 0;
- ober_arm.y1 = 0;
- //Winkelfestlegen
- alpha_beta.alfa = 90;
- alpha_beta.beta = 90;
- //Werte Für Koordinatenachse Init..
- alpha_beta.faktor = -10;
- alpha_beta.x1 = 0;
- alpha_beta.x2 = alpha_beta.x1+180;
- alpha_beta.y1 = alpha_beta.x1;
- alpha_beta.y2 = alpha_beta.y1+180;
- alpha_beta.farbe = 0;
- //Koordianten Achsen Zeichnen
- kord_achsen();
- //Steuerungs info
- infotxt();
- //Roboterarm für Start Zeichnen
- ZeichneRobot(alpha_beta.alfa, alpha_beta.beta, vPort1);
- }
- //Steuerung mit Tastatur
- void Steuerung(void)
- {
- int beenden=0, d_beenden=0;
- while (beenden==0)
- {
- int taste;
- taste=getch();
- //b oder B taste drücken damit das Programm Beendet wird
- if (taste==66 || taste==98 || taste==27)
- {
- beenden=1;
- }
- //R TASTE
- if (taste==82 || taste==114)
- {
- VpReset(vPort1);
- VpReset(vPort2);
- VpReset(vPort3);
- Main_Init();
- }
- //E TASTE
- if (taste==69 || taste==101)
- {
- Lese_Keyboard();
- }
- //D oder D drücken damit man Direktsteuerungs modus kommt
- if (taste==68 || taste==100)
- {
- d_beenden=0;
- while (d_beenden==0)
- {
- taste=getch();
- //D Drücken um zu verlassen (DIREKT)
- if (taste==68 || taste==100 || taste==27)
- {
- d_beenden=1;
- }
- if (taste==50)
- {
- //Unterrarm Bewegen Grad-
- int winkel=alpha_beta.beta;
- --winkel;
- if (!(ZeichneRobot(alpha_beta.alfa,winkel,vPort1)))
- {
- ++winkel;
- alpha_beta.beta=winkel;
- }
- }
- if (taste==56)
- {
- //Unterarm Bewegen Grad+
- int winkel=alpha_beta.beta;
- ++winkel;
- if (!(ZeichneRobot(alpha_beta.alfa,winkel,vPort1)))
- {
- --winkel;
- alpha_beta.beta=winkel;
- }
- }
- if (taste==54)
- {
- //Oberrarm Bewegen Grad-
- int winkel=alpha_beta.alfa;
- --winkel;
- if (!(ZeichneRobot(winkel,alpha_beta.beta,vPort1)))
- {
- ++winkel;
- alpha_beta.alfa=winkel;
- }
- }
- if (taste==52)
- {
- //Oberarm Bewegen Grad+
- int winkel=alpha_beta.alfa;
- ++winkel;
- if (!(ZeichneRobot(winkel,alpha_beta.beta,vPort1)))
- {
- --winkel;
- alpha_beta.alfa=winkel;
- }
- }
- }
- }
- }
- //Grafikmodus Verlassen
- closegraph();
- }
Add Comment
Please, Sign In to add comment