|
Fast Research Interface Library
Manual and Documentation
|
00001 // ---------------------- Doxygen info ---------------------- 00056 // ---------------------------------------------------------- 00057 // For a convenient reading of this file's source code, 00058 // please use a tab width of four characters. 00059 // ---------------------------------------------------------- 00060 00061 00062 #include <LWRJointPositionController.h> 00063 #include <stdlib.h> 00064 #include <stdio.h> 00065 #include <string.h> 00066 #include <errno.h> 00067 #include <math.h> 00068 00069 00070 #define NUMBER_OF_JOINTS 7 00071 00072 #ifndef PI 00073 #define PI 3.1415926535897932384626433832795 00074 #endif 00075 00076 00077 00078 //******************************************************************************************* 00079 // main() 00080 // 00081 int main(int argc, char *argv[]) 00082 { 00083 unsigned int CycleCounter = 0; 00084 00085 int ResultValue = 0 00086 , i = 0; 00087 00088 float FunctionValue = 0.0 00089 , LoopVariable = 0.0 00090 , JointValuesInRad[NUMBER_OF_JOINTS] 00091 , InitialJointValuesInRad[NUMBER_OF_JOINTS]; 00092 00093 LWRJointPositionController *Robot; 00094 00095 Robot = new LWRJointPositionController("/home/lwrcontrol/etc/980039-FRI-Driver.init"); 00096 00097 fprintf(stdout, "RobotJointPositionController object created. Starting the robot...\n"); 00098 00099 ResultValue = Robot->StartRobot(); 00100 00101 if (ResultValue == EOK) 00102 { 00103 fprintf(stdout, "Robot successfully started.\n"); 00104 } 00105 else 00106 { 00107 fprintf(stderr, "ERROR, could not start robot: %s\n", strerror(ResultValue)); 00108 } 00109 00110 fprintf(stdout, "Current system state:\n%s\n", Robot->GetCompleteRobotStateAndInformation()); 00111 00112 Robot->GetMeasuredJointPositions(InitialJointValuesInRad); 00113 00114 fprintf(stdout, "Preparing data logger...\n"); 00115 // Data logging method 1 00116 Robot->PrepareLogging("OptionalStringForFileIdentification"); 00117 fprintf(stdout, "Data logger prepared.\n"); 00118 00119 while (LoopVariable < 5.0 * PI) 00120 { 00121 Robot->WaitForKRCTick(); 00122 00123 if (!Robot->IsMachineOK()) 00124 { 00125 fprintf(stderr, "ERROR, the machine is not ready anymore.\n"); 00126 break; 00127 } 00128 00129 CycleCounter++; 00130 00131 if (CycleCounter == 2000) 00132 { 00133 // Data logging method 2 00134 ResultValue = Robot->StartLogging(); 00135 00136 if (ResultValue == EOK) 00137 { 00138 // this printf method is real-time capable 00139 Robot->printf("Data logging successfully started.\n"); 00140 } 00141 else 00142 { 00143 Robot->printf("ERROR, cannot start data logging.\n"); 00144 } 00145 } 00146 00147 if (CycleCounter == 12000) 00148 { 00149 // Data logging method 3 00150 ResultValue = Robot->StopLogging(); 00151 00152 if (ResultValue == EOK) 00153 { 00154 Robot->printf("Data logging successfully stopped.\n"); 00155 } 00156 else 00157 { 00158 Robot->printf("ERROR, cannot stop data logging.\n"); 00159 } 00160 } 00161 00162 FunctionValue = 0.3 * sin(LoopVariable); 00163 FunctionValue *= FunctionValue; 00164 00165 for (i = 0; i < NUMBER_OF_JOINTS; i++) 00166 { 00167 JointValuesInRad[i] = InitialJointValuesInRad[i] + FunctionValue; 00168 } 00169 00170 Robot->SetCommandedJointPositions(JointValuesInRad); 00171 00172 LoopVariable += (float)0.001; 00173 } 00174 00175 fprintf(stdout, "Writing data file...\n"); 00176 // Data logging method 4 00177 Robot->WriteLoggingDataFile(); 00178 fprintf(stdout, "Data file written.\n"); 00179 00180 fprintf(stdout, "Stopping the robot...\n"); 00181 ResultValue = Robot->StopRobot(); 00182 00183 if (ResultValue != EOK) 00184 { 00185 fprintf(stderr, "An error occurred during stopping the robot...\n"); 00186 } 00187 else 00188 { 00189 fprintf(stdout, "Robot successfully stopped.\n"); 00190 } 00191 00192 fprintf(stdout, "Deleting the object...\n"); 00193 delete Robot; 00194 fprintf(stdout, "Object deleted...\n"); 00195 00196 return(EXIT_SUCCESS); 00197 }