Fast Research Interface Library  Manual and Documentation
src/FastResearchInterfaceTest/MoveToCandle.cpp
Go to the documentation of this file.
00001 //  ---------------------- Doxygen info ----------------------
00048 //  ----------------------------------------------------------
00049 //   For a convenient reading of this file's source code,
00050 //   please use a tab width of four characters.
00051 //  ----------------------------------------------------------
00052 
00053 
00054 #include <FastResearchInterface.h>
00055 #include <Console.h>
00056 #include <errno.h>
00057 #include <string.h>
00058 #include <OSAbstraction.h>
00059 #include <FastResearchInterfaceTest.h>
00060 #include <TypeIRML.h>
00061 
00062 #ifndef PI
00063 #define PI          3.1415926535897932384626433832795
00064 #endif
00065 
00066 #ifndef RAD
00067 #define RAD(A)  ((A) * PI / 180.0 )
00068 #endif
00069 
00070 #ifndef DEG
00071 #define DEG(A)  ((A) * 180.0 / PI )
00072 #endif
00073 
00074 #define NUMBER_OF_JOINTS            7
00075 
00076 
00077 
00078 // ****************************************************************
00079 // MoveToCandle()
00080 //
00081 void MoveToCandle(FastResearchInterface *FRI)
00082 {
00083     unsigned int                i                           =   0       ;
00084 
00085     int                         ResultValue                 =   0       ;
00086 
00087 
00088     float                       JointValuesInRad[NUMBER_OF_JOINTS]      ;
00089 
00090     double                      CycleTime                   =   0.002   ;
00091 
00092     TypeIRML                    *RML                        =   NULL    ;
00093 
00094     TypeIRMLInputParameters     *IP                         =   NULL    ;
00095 
00096     TypeIRMLOutputParameters    *OP                         =   NULL    ;
00097 
00098     RML                 =   new TypeIRML(       NUMBER_OF_JOINTS
00099                                             ,   CycleTime           );
00100 
00101     IP                  =   new TypeIRMLInputParameters(NUMBER_OF_JOINTS);
00102 
00103     OP                  =   new TypeIRMLOutputParameters(NUMBER_OF_JOINTS);
00104 
00105     memset(JointValuesInRad                     , 0x0, NUMBER_OF_JOINTS * sizeof(float));
00106 
00107     if ((FRI->GetCurrentControlScheme() != FastResearchInterface::JOINT_POSITION_CONTROL) || (!FRI->IsMachineOK()))
00108     {   
00109         printf("Program is going to stop the robot.\n");
00110         FRI->StopRobot();
00111 
00112         FRI->GetMeasuredJointPositions(JointValuesInRad);
00113         FRI->SetCommandedJointPositions(JointValuesInRad);
00114                 
00115         printf("Restarting the joint position control scheme.\n");
00116         ResultValue =   FRI->StartRobot(FastResearchInterface::JOINT_POSITION_CONTROL);
00117         
00118         if ((ResultValue != EOK) && (ResultValue != EALREADY))
00119         {
00120             printf("An error occurred during starting up the robot...\n");
00121             delete  RML;
00122             delete  IP;
00123             delete  OP;
00124             
00125             return;         
00126         }
00127     }
00128         
00129     printf("Moving to the candle position..\n");
00130     
00131     FRI->GetMeasuredJointPositions(JointValuesInRad);
00132     
00133     for ( i = 0; i < NUMBER_OF_JOINTS; i++)
00134     {
00135         IP->CurrentPosition->VecData        [i] =   (double)DEG(JointValuesInRad[i]);
00136         IP->TargetPosition->VecData         [i] =   (double)0.0;
00137         IP->MaxVelocity->VecData            [i] =   (double)50.0;       
00138         IP->MaxAcceleration->VecData        [i] =   (double)50.0;
00139         IP->SelectionVector->VecData        [i] =   true;
00140     }
00141     
00142     ResultValue =   TypeIRML::RML_WORKING;
00143     
00144     while ((FRI->IsMachineOK()) && (ResultValue != TypeIRML::RML_FINAL_STATE_REACHED))
00145     {
00146         FRI->WaitForKRCTick();
00147 
00148         ResultValue =   RML->GetNextMotionState_Position(       *IP
00149                                                             ,   OP  );
00150 
00151         if ((ResultValue != TypeIRML::RML_WORKING) && (ResultValue != TypeIRML::RML_FINAL_STATE_REACHED))
00152         {
00153             printf("MoveToCandle(): ERROR during trajectory generation (%d).", ResultValue);
00154         }
00155                                             
00156         for ( i = 0; i < NUMBER_OF_JOINTS; i++)
00157         {
00158             JointValuesInRad[i] =   RAD((double)(OP->NewPosition->VecData[i]));
00159         }
00160 
00161         FRI->SetCommandedJointPositions(JointValuesInRad);  
00162         
00163         *(IP->CurrentPosition)      =   *(OP->NewPosition);
00164         *(IP->CurrentVelocity)      =   *(OP->NewVelocity);
00165     }
00166 
00167     if (!FRI->IsMachineOK())
00168     {
00169         printf("MoveToCandle(): ERROR, machine is not ready.");
00170         
00171         delete  RML;
00172         delete  IP;
00173         delete  OP;
00174         
00175         return;
00176     }
00177 
00178     printf("Stopping the robot.\n");
00179     FRI->StopRobot();   
00180 
00181     delete  RML;
00182     delete  IP;
00183     delete  OP;
00184     
00185     return;
00186 }
This document was generated with Doxygen on Thu Apr 12 2012 11:18:54. User documentation of the Fast Research Interface Library for the KUKA Lightweight Robot IV by the Stanford Robotics Research Group. Copyright 2010–2012.