Fast Research Interface Library  Manual and Documentation
src/LWRGettingStartedExamples/LWRCartImpedanceControlExample.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 <LWRCartImpedanceController.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_FRAME_ELEMENTS    12
00067 #define NUMBER_OF_CART_DOFS         6
00068 #define NUMBER_OF_JOINTS            7
00069 #define RUN_TIME_IN_SECONDS         10.0
00070 
00071 
00072 //*******************************************************************************************
00073 // main()
00074 //
00075 int main(int argc, char *argv[])
00076 {
00077     unsigned int                CycleCounter    =   0
00078                             ,   i               =   0;
00079 
00080     int                         ResultValue     =   0;
00081 
00082     float                       CommandedForcesAndTorques               [NUMBER_OF_CART_DOFS        ]
00083                             ,   CommandedStiffness                      [NUMBER_OF_CART_DOFS        ]
00084                             ,   CommandedDamping                        [NUMBER_OF_CART_DOFS        ]
00085                             ,   EstimatedExternalCartForcesAndTorques   [NUMBER_OF_CART_DOFS        ]
00086                             ,   CommandedPose                           [NUMBER_OF_FRAME_ELEMENTS   ]
00087                             ,   MeasuredPose                            [NUMBER_OF_FRAME_ELEMENTS   ]
00088                             ,   JointValuesInRad                        [NUMBER_OF_JOINTS           ]
00089                             ,   MeasuredJointTorques                    [NUMBER_OF_JOINTS           ];
00090 
00091     LWRCartImpedanceController  *Robot;
00092 
00093     Robot   =   new LWRCartImpedanceController("/home/lwrcontrol/etc/980039-FRI-Driver.init");
00094 
00095     fprintf(stdout, "RobotCartImpedanceController object created. Starting the robot...\n");
00096 
00097     ResultValue =   Robot->StartRobot();
00098 
00099     if (ResultValue == EOK)
00100     {
00101         fprintf(stdout, "Robot successfully started.\n");
00102     }
00103     else
00104     {
00105         fprintf(stderr, "ERROR, could not start robot: %s\n", strerror(ResultValue));
00106     }
00107 
00108     fprintf(stdout, "Current system state:\n%s\n", Robot->GetCompleteRobotStateAndInformation());
00109 
00110     for (i = 0; i < NUMBER_OF_CART_DOFS; i++)
00111     {
00112         CommandedStiffness          [i] =   (float)200.0 * ((i <= 2)?(10.0):(1.0));
00113         CommandedDamping            [i] =   (float)0.7;
00114         CommandedForcesAndTorques   [i] =   (float)0.0;
00115     }
00116 
00117     Robot->GetMeasuredCartPose(MeasuredPose);
00118 
00119     for (i = 0; i < NUMBER_OF_FRAME_ELEMENTS; i++)
00120     {
00121         CommandedPose[i]    =   MeasuredPose[i];
00122     }
00123 
00124     fprintf(stdout, "Performing Cartesian impedance control for %.1f seconds.\n", RUN_TIME_IN_SECONDS);
00125 
00126     while ((float)CycleCounter * Robot->GetCycleTime() < RUN_TIME_IN_SECONDS)
00127     {
00128         Robot->WaitForKRCTick();
00129 
00130         if (!Robot->IsMachineOK())
00131         {
00132             fprintf(stderr, "ERROR, the machine is not ready anymore.\n");
00133             break;
00134         }
00135 
00136         Robot->GetMeasuredJointTorques                  (MeasuredJointTorques                   );
00137         Robot->GetMeasuredJointPositions                (JointValuesInRad                       );
00138         Robot->GetMeasuredCartPose                      (MeasuredPose                           );
00139         Robot->GetEstimatedExternalCartForcesAndTorques (EstimatedExternalCartForcesAndTorques  );
00140 
00141         Robot->SetCommandedCartStiffness                (CommandedStiffness                     );
00142         Robot->SetCommandedCartDamping                  (CommandedDamping                       );
00143         Robot->SetCommandedCartForcesAndTorques         (CommandedForcesAndTorques              );
00144         Robot->SetCommandedCartPose                     (CommandedPose                          );
00145 
00146         CycleCounter++;
00147     }
00148 
00149     fprintf(stdout, "Stopping the robot...\n");
00150     ResultValue =   Robot->StopRobot();
00151 
00152     if (ResultValue != EOK)
00153     {
00154         fprintf(stderr, "An error occurred during stopping the robot...\n");
00155     }
00156     else
00157     {
00158         fprintf(stdout, "Robot successfully stopped.\n");
00159     }
00160 
00161     fprintf(stdout, "Deleting the object...\n");
00162     delete Robot;
00163     fprintf(stdout, "Object deleted...\n");
00164 
00165     return(EXIT_SUCCESS);
00166 }
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.