component duplo " component for sauter 12 station turret " ; option userspace yes ; // option userinit yes ; pin in bit codB# [4] ; pin in bit codparity ; pin out bit parity-error; pin in bit strobe ; pin in bit toolchange ; pin out bit toolchanged = 1 ; pin in s32 newtoolnumber ; pin out s32 currentduplonumber ; pin out bit motorCW = 0 ; pin out bit motorCCW = 0 ; pin out bit brake = 0 ; pin out bit indexingSolenoid = 0 ; pin in bit indexingSwitch ; pin in bit lockingSwitch ; pin out s32 state = 0; license "GPL"; ;; #include #include #include #include #include // variable int state = 0; int p = 0 ; int pcalc = 0 ; int i, start, beforenewpos; int sensCW = 0; int sensCCW = 0; int courseCW = 0; int courseCCW = 0; // timerT1 = 0.05 10e3 ; // timerT2 = 0.2 10e3 ; void user_mainloop(void) { while (1) { FOR_ALL_INSTS() { for (i = 0; i < 4 ; i++) { p += codB(i) << i ; /* umwandlung binär dezimal pcalc ^= codB(i) ; /* Berechnung der Parität pcalc = 1 wenn ungerade */ } if (strobe) { currentduplonumber = p ; p = 0 ; parity_error = ( pcalc ^= codparity ); } switch (state) { case 0: /* stabil auf der currentduplonumber warten ... bei Änderungswunsch state = 1 */ brake = 1 ; if (toolchange) { if (( currentduplonumber != newtoolnumber ) && ( newtoolnumber != 0)) { toolchanged = 0 ; brake = 0 ; state = 1 ; start = currentduplonumber ; courseCW = 0 ; while ( start != newtoolnumber ) { start += 1 ; courseCW += 1 ; if( start == 13) start = 1 ; } start = currentduplonumber ; courseCCW = 0 ; while ( start != newtoolnumber ) { start += -1 ; courseCCW += 1 ; if( start == 0 ) start = 12 ; } if ( courseCW <= courseCCW ) /* die Strecke 1 2 3 ist die kürzeste oder gleichwertige Ri */ { sensCW = 0 ; sensCCW = 0 ; if ( newtoolnumber == 1 ) beforenewpos = 12 ; else (beforenewpos = (newtoolnumber - 1)) ; } else { sensCW = 0 ; sensCCW = 0 ; if ( newtoolnumber == 12 ) beforenewpos = 1 ; else (beforenewpos = (newtoolnumber + 1)) ; } } } else toolchanged = 0 ; break; /*case 3: /* Defaut changeur outils */ while (1) { toolchanged = 0 ; sensCW = 0; sensCCW = 0; motorCW = sensCW ; motorCCW = sensCCW ; rtapi_print_msg (RTAPI_MSG_ERR, "Paritätsfehler Werkzeugwechsler"); fprintf(stderr, "Paritätsfehler Werkzeugwechsler"); } break; } // de switch } } }