Fast Research Interface Library  Manual and Documentation
src/LWRGettingStartedExamples/LWRJointPositionControlExample.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 <LWRJointPositionController.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 
00069 #ifndef PI
00070 #define PI  3.1415926535897932384626433832795
00071 #endif
00072 
00073 
00074 //*******************************************************************************************
00075 // main()
00076 //
00077 int main(int argc, char *argv[])
00078 {
00079     int                         ResultValue     =   0
00080                             ,   i               =   0;
00081 
00082     float                       FunctionValue   =   0.0
00083                             ,   LoopVariable    =   0.0
00084                             ,   JointValuesInRad[NUMBER_OF_JOINTS]
00085                             ,   InitialJointValuesInRad[NUMBER_OF_JOINTS];
00086 
00087     LWRJointPositionController  *Robot;
00088 
00089     Robot   =   new LWRJointPositionController("/home/lwrcontrol/etc/980039-FRI-Driver.init");
00090 
00091     fprintf(stdout, "RobotJointPositionController object created. Starting the robot...\n");
00092 
00093     ResultValue =   Robot->StartRobot();
00094 
00095     if (ResultValue == EOK)
00096     {
00097         fprintf(stdout, "Robot successfully started.\n");
00098     }
00099     else
00100     {
00101         fprintf(stderr, "ERROR, could not start robot: %s\n", strerror(ResultValue));
00102     }
00103 
00104     fprintf(stdout, "Current system state:\n%s\n", Robot->GetCompleteRobotStateAndInformation());
00105 
00106     Robot->GetMeasuredJointPositions(InitialJointValuesInRad);
00107 
00108     while (LoopVariable < 5.0 * PI)
00109     {
00110         Robot->WaitForKRCTick();
00111 
00112         if (!Robot->IsMachineOK())
00113         {
00114             fprintf(stderr, "ERROR, the machine is not ready anymore.\n");
00115             break;
00116         }
00117 
00118         FunctionValue   =   (float)(0.3 * sin(LoopVariable));
00119         FunctionValue   *=  (float)FunctionValue;
00120 
00121         for (i = 0; i < NUMBER_OF_JOINTS; i++)
00122         {
00123             JointValuesInRad[i] =   InitialJointValuesInRad[i] + FunctionValue;
00124         }
00125 
00126         Robot->SetCommandedJointPositions(JointValuesInRad);
00127 
00128         LoopVariable    +=  (float)0.001;
00129     }
00130 
00131     fprintf(stdout, "Stopping the robot...\n");
00132     ResultValue =   Robot->StopRobot();
00133 
00134     if (ResultValue != EOK)
00135     {
00136         fprintf(stderr, "An error occurred during stopping the robot...\n");
00137     }
00138     else
00139     {
00140         fprintf(stdout, "Robot successfully stopped.\n");
00141     }
00142 
00143     fprintf(stdout, "Deleting the object...\n");
00144     delete Robot;
00145     fprintf(stdout, "Object deleted...\n");
00146 
00147     return(EXIT_SUCCESS);
00148 }
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.