Fast Research Interface Library  Manual and Documentation
src/LWRGettingStartedExamples/LWRJointImpedanceControlExample.cpp
Go to the documentation of this file.
00001 //  ---------------------- Doxygen info ----------------------
00052 //  ----------------------------------------------------------
00053 //   For a convenient reading of this file's source code,
00054 //   please use a tab width of four characters.
00055 //  ----------------------------------------------------------
00056 
00057 
00058 #include <LWRJointImpedanceController.h>
00059 #include <stdlib.h>
00060 #include <stdio.h>
00061 #include <string.h>
00062 #include <errno.h>
00063 #include <math.h>
00064 
00065 
00066 #define NUMBER_OF_JOINTS        7
00067 
00068 #define RUN_TIME_IN_SECONDS     10.0
00069 
00070 
00071 //*******************************************************************************************
00072 // main()
00073 //
00074 int main(int argc, char *argv[])
00075 {
00076     unsigned int                CycleCounter    =   0
00077                             ,   i               =   0;
00078 
00079     int                         ResultValue     =   0;
00080 
00081     float                       CommandedTorquesInNm    [NUMBER_OF_JOINTS]
00082                             ,   CommandedStiffness      [NUMBER_OF_JOINTS]
00083                             ,   CommandedDamping        [NUMBER_OF_JOINTS]
00084                             ,   MeasuredTorquesInNm     [NUMBER_OF_JOINTS]
00085                             ,   JointValuesInRad        [NUMBER_OF_JOINTS];
00086 
00087     LWRJointImpedanceController *Robot;
00088 
00089     Robot   =   new LWRJointImpedanceController("/home/lwrcontrol/etc/980039-FRI-Driver.init");
00090 
00091     fprintf(stdout, "RobotJointImpedanceController object created. Starting the robot...\n");
00092 
00093     for (i = 0; i < NUMBER_OF_JOINTS; i++)
00094     {
00095         CommandedStiffness  [i] =   (float)200.0;
00096         CommandedDamping    [i] =   (float)0.7;
00097         CommandedTorquesInNm[i] =   (float)0.0;
00098     }
00099 
00100     Robot->SetCommandedJointStiffness   (CommandedStiffness     );
00101     Robot->SetCommandedJointDamping     (CommandedDamping       );
00102     Robot->SetCommandedJointTorques     (CommandedTorquesInNm   );
00103 
00104     ResultValue =   Robot->StartRobot();
00105 
00106     if (ResultValue == EOK)
00107     {
00108         fprintf(stdout, "Robot successfully started.\n");
00109     }
00110     else
00111     {
00112         fprintf(stderr, "ERROR, could not start robot: %s\n", strerror(ResultValue));
00113     }
00114 
00115     fprintf(stdout, "Current system state:\n%s\n", Robot->GetCompleteRobotStateAndInformation());
00116 
00117     Robot->GetMeasuredJointPositions(JointValuesInRad);
00118 
00119     fprintf(stdout, "Performing joint impedance control for %.1f seconds.\n", RUN_TIME_IN_SECONDS);
00120 
00121     while ((float)CycleCounter * Robot->GetCycleTime() < RUN_TIME_IN_SECONDS)
00122     {
00123         Robot->WaitForKRCTick();
00124 
00125         if (!Robot->IsMachineOK())
00126         {
00127             fprintf(stderr, "ERROR, the machine is not ready anymore.\n");
00128             break;
00129         }
00130 
00131         Robot->GetMeasuredJointTorques      (MeasuredTorquesInNm    );
00132         Robot->GetMeasuredJointPositions    (JointValuesInRad       );
00133 
00134         Robot->SetCommandedJointPositions   (JointValuesInRad);
00135         Robot->SetCommandedJointStiffness   (CommandedStiffness     );
00136         Robot->SetCommandedJointDamping     (CommandedDamping       );
00137         Robot->SetCommandedJointTorques     (CommandedTorquesInNm   );
00138 
00139         CycleCounter++;
00140     }
00141 
00142     fprintf(stdout, "Stopping the robot...\n");
00143     ResultValue =   Robot->StopRobot();
00144 
00145     if (ResultValue != EOK)
00146     {
00147         fprintf(stderr, "An error occurred during stopping the robot...\n");
00148     }
00149     else
00150     {
00151         fprintf(stdout, "Robot successfully stopped.\n");
00152     }
00153 
00154     fprintf(stdout, "Deleting the object...\n");
00155     delete Robot;
00156     fprintf(stdout, "Object deleted...\n");
00157 
00158     return(EXIT_SUCCESS);
00159 }
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.