|
Fast Research Interface Library
Manual and Documentation
|
00001 // ---------------------- Doxygen info ---------------------- 00051 // ---------------------------------------------------------- 00052 // For a convenient reading of this file's source code, 00053 // please use a tab width of four characters. 00054 // ---------------------------------------------------------- 00055 00056 00057 #include <FastResearchInterface.h> 00058 #include <Console.h> 00059 #include <errno.h> 00060 #include <string.h> 00061 #include <OSAbstraction.h> 00062 #include <FastResearchInterfaceTest.h> 00063 #include <TypeIRML.h> 00064 00065 #ifndef PI 00066 #define PI 3.1415926535897932384626433832795 00067 #endif 00068 00069 #ifndef RAD 00070 #define RAD(A) ((A) * PI / 180.0 ) 00071 #endif 00072 00073 #ifndef DEG 00074 #define DEG(A) ((A) * 180.0 / PI ) 00075 #endif 00076 00077 #define NUMBER_OF_JOINTS 7 00078 00079 // **************************************************************** 00080 // RunTrajectorySimple() 00081 // 00082 void RunTrajectorySimple(FastResearchInterface *FRI) 00083 { 00084 unsigned int i = 0 ; 00085 00086 int ResultValue = 0 ; 00087 00088 00089 float JointValuesInRad[NUMBER_OF_JOINTS] ; 00090 00091 double CycleTime = 0.002 ; 00092 00093 TypeIRML *RML = NULL ; 00094 00095 TypeIRMLInputParameters *IP = NULL ; 00096 00097 TypeIRMLOutputParameters *OP = NULL ; 00098 00099 RML = new TypeIRML( NUMBER_OF_JOINTS 00100 , CycleTime ); 00101 00102 IP = new TypeIRMLInputParameters(NUMBER_OF_JOINTS); 00103 00104 OP = new TypeIRMLOutputParameters(NUMBER_OF_JOINTS); 00105 00106 memset(JointValuesInRad , 0x0, NUMBER_OF_JOINTS * sizeof(float)); 00107 00108 if ((FRI->GetCurrentControlScheme() != FastResearchInterface::JOINT_POSITION_CONTROL) || (!FRI->IsMachineOK())) 00109 { 00110 printf("Program is going to stop the robot.\n"); 00111 FRI->StopRobot(); 00112 00113 FRI->GetMeasuredJointPositions(JointValuesInRad); 00114 FRI->SetCommandedJointPositions(JointValuesInRad); 00115 00116 printf("Restarting the joint position control scheme.\n"); 00117 ResultValue = FRI->StartRobot(FastResearchInterface::JOINT_POSITION_CONTROL); 00118 00119 if ((ResultValue != EOK) && (ResultValue != EALREADY)) 00120 { 00121 printf("An error occurred during starting up the robot...\n"); 00122 delete RML; 00123 delete IP; 00124 delete OP; 00125 00126 return; 00127 } 00128 } 00129 00130 printf("Moving each joint by 20 degrees...\n"); 00131 00132 FRI->GetMeasuredJointPositions(JointValuesInRad); 00133 00134 for ( i = 0; i < NUMBER_OF_JOINTS; i++) 00135 { 00136 IP->CurrentPosition->VecData [i] = (double)DEG(JointValuesInRad[i]); 00137 IP->TargetPosition->VecData [i] = (double)20.0; 00138 IP->MaxVelocity->VecData [i] = (double)50.0; 00139 IP->MaxAcceleration->VecData [i] = (double)50.0; 00140 IP->SelectionVector->VecData [i] = true; 00141 } 00142 00143 ResultValue = TypeIRML::RML_WORKING; 00144 00145 while ((FRI->IsMachineOK()) && (ResultValue != TypeIRML::RML_FINAL_STATE_REACHED)) 00146 { 00147 FRI->WaitForKRCTick(); 00148 00149 ResultValue = RML->GetNextMotionState_Position( *IP 00150 , OP ); 00151 00152 if ((ResultValue != TypeIRML::RML_WORKING) && (ResultValue != TypeIRML::RML_FINAL_STATE_REACHED)) 00153 { 00154 printf("RunTrajectorySimple(): ERROR during trajectory generation (%d).", ResultValue); 00155 } 00156 00157 for ( i = 0; i < NUMBER_OF_JOINTS; i++) 00158 { 00159 JointValuesInRad[i] = RAD((double)(OP->NewPosition->VecData[i])); 00160 } 00161 00162 FRI->SetCommandedJointPositions(JointValuesInRad); 00163 00164 *(IP->CurrentPosition) = *(OP->NewPosition); 00165 *(IP->CurrentVelocity) = *(OP->NewVelocity); 00166 } 00167 00168 printf("Position reached. Moving the robot back to the candle position...\n"); 00169 00170 for ( i = 0; i < NUMBER_OF_JOINTS; i++) 00171 { 00172 IP->TargetPosition->VecData [i] = (double)0.0; 00173 } 00174 00175 ResultValue = TypeIRML::RML_WORKING; 00176 00177 while ((FRI->IsMachineOK()) && (ResultValue != TypeIRML::RML_FINAL_STATE_REACHED)) 00178 { 00179 FRI->WaitForKRCTick(); 00180 00181 ResultValue = RML->GetNextMotionState_Position( *IP 00182 , OP ); 00183 00184 if ((ResultValue != TypeIRML::RML_WORKING) && (ResultValue != TypeIRML::RML_FINAL_STATE_REACHED)) 00185 { 00186 printf("RunTrajectorySimple(): ERROR during trajectory generation (%d).", ResultValue); 00187 } 00188 00189 for ( i = 0; i < NUMBER_OF_JOINTS; i++) 00190 { 00191 JointValuesInRad[i] = RAD((double)(OP->NewPosition->VecData[i])); 00192 } 00193 00194 FRI->SetCommandedJointPositions(JointValuesInRad); 00195 00196 *(IP->CurrentPosition) = *(OP->NewPosition); 00197 *(IP->CurrentVelocity) = *(OP->NewVelocity); 00198 } 00199 00200 if (!FRI->IsMachineOK()) 00201 { 00202 printf("RunTrajectorySimple(): ERROR, machine is not ready."); 00203 00204 delete RML; 00205 delete IP; 00206 delete OP; 00207 00208 return; 00209 } 00210 00211 printf("Stopping the robot.\n"); 00212 FRI->StopRobot(); 00213 00214 delete RML; 00215 delete IP; 00216 delete OP; 00217 00218 return; 00219 } 00220 00221