- Interactive Motion Control -

Information Hardware Software Example Code
/*************************************************** * JogMotor1.c * * This program will jog motor 1 by an encoder * count inputted by the user. **************************************************/ #include <stdio.h> #include <unistd.h> #include "Pmacu.h" //Include file for PMAC /*************************************************** * int JogMotor(DWORD DwDevice) * * Returns: * the status of the * Arguments: * DwDevice is the PMAC device number * * This function will request the user to input an * encoder count to move motor 1 to and then * command the PMAC board to move the motor. **************************************************/ int JogMotor( DWORD DwDevice ) { char inputbuf[500]; char outputbuf[256]; int jog_position; int i; int DONE = 0; // Kill all motors before continuing. printf("Killing all motors\n"); // Print the command to a char buffer array // to send to PMAC. sprintf(inputbuf, "K\n"); // Send the command to PMAC and store any response. PmacGetResponseA(DwDevice,outputbuf,250,inputbuf); // Check PMAC for errors. if(PmacGetErrorStr(DwDevice, outputbuf, 250)) { printf("\nERROR: First killing motor call\n"); printf("%s\n", outputbuf); return -1; } // Ask the user to input an encoder count number // to jog to. printf("What position would you like to jog to: "); fflush(_stdin); fgets(inputbuf, 49, _stdin); jog_position = atoi(inputbuf); // Print out how many encoder counts we are moving // the motor to. printf("Jogging to %d\n", jog_position); // Print the command to a char buffer array // to send to PMAC. sprintf(inputbuf, "J:%d\n", jog_position); // Send the command to PMAC and get any response. PmacGetResponseA(DwDevice,outputbuf,250,inputbuf); // Check PMAC for errors. if(PmacGetErrorStr(DwDevice, outputbuf, 250)) { printf("\nERROR: First killing motor call\n"); printf("%s\n", outputbuf); return -1; } // Sleep for 10 msec to allow PMAC to update the // dual port ram before checking it for motor // movement. usleep(10); // Loop until the motor has stopped moving. while(!DONE) { PmacDPRUpdateRealTime(DwDevice); if( PmacDPRGetMotorMotion(DwDevice, 0) != 2) DONE=1; } // Kill all motors before continuing. printf("Killing all motors\n"); // Print the command to a char buffer array // to send to PMAC. sprintf(inputbuf, "K\n"); // Send the command to PMAC and store any response. PmacGetResponseA(DwDevice,outputbuf,250,inputbuf); // Check PMAC for errors. if(PmacGetErrorStr(DwDevice, outputbuf, 250)) { printf("\nERROR: First killing motor call\n"); printf("%s\n", outputbuf); return -1; } return 0; } int main(void) { DWORD DwDevice = 0; //Variable to store the device number int status; //Variable for return status //Ask the user to input a PMAC device number and store //it in the device number variable. printf( "\n\nInput DwDevice: " ); scanf( "%d",&DwDevice ); //Print out to the user what device number they entered. printf( "You entered DwDevice: %d\n\n", DwDevice ); //Open the PMAC device. if ( OpenPmacDevice( DwDevice ) ) printf( "PMAC Open Successfully! status = %d\n", status ); else { printf( "PMAC Open Error: DwDevice %d not found.\n", DwDevice ); printf( "Terminating program.\n\n" ); exit( -1 ); } //Initialize the Dual Port Ram real time data acquisition for //motor information used to check to see if the motor is in //motion. if(!PmacDPRRealTimeEx(DwDevice, 5, 10, 1)) printf("Unable to Initialize Real-Time Buffer"); //Call the JogMotor() function sending it the PMAC device //number. JogMotor(DwDevice); //Diable the Dual Port Ram real time. if(!PmacDPRRealTimeEx(DwDevice, 0, 0, 0)) printf("Unable to Disable Real-Time Buffer"); //Close the PMAC device. if ( ClosePmacDevice( DwDevice ) ) printf( "PMAC Close Successfully! status = %d\n", status ); else { printf( "PMAC Close Error: DwDevice %d could not be closed.\n", DwDevice ); exit( -1 ); } return 0; } /* End of Program */