17 #include <boost/lexical_cast.hpp>    26     #pragma comment(lib, "Shlwapi.lib")    29 #if defined (__linux) || defined (__APPLE__)    32     #define _stricmp(x,y) strcasecmp(x,y)    35 #define PLUGIN_VERSION 1    40 #define CONCAT(x,y,z) x y z    41 #define strConCat(x,y,z)    CONCAT(x,y,z)    42 #define LUA_GET_SENSOR_DATA_COMMAND "simExtSkeleton_getSensorData"    43 #define LUA_KUKA_LBR_IIWA_START_COMMAND "simExtUniversalRobotsStart"    47 std::shared_ptr<grl::vrep::UniversalRobotsVrepPlugin> 
kukaPluginPG;
    72 std::string 
LUA_KUKA_LBR_IIWA_START_CALL_TIP(
"number result=simExtUniversalRobotsStart(string Joint1Handle , string Joint2Handle , string Joint3Handle , string Joint4Handle , string Joint5Handle , string Joint6Handle , string Joint7Handle , string RobotFlangeTipHandle, string RobotTipHandle, string RobotTargetHandle, string RobotTargetBaseHandle, string LocalZMQAddress, string RemoteZMQAddress, string LocalHostKukaKoniUDPAddress, string LocalHostKukaKoniUDPPort, string RemoteHostKukaKoniUDPAddress, string RemoteHostKukaKoniUDPPort, string KukaCommandMode, string RobotIKGroup) -- KukaCommandMode options are JAVA and FRI");
    80         BOOST_LOG_TRIVIAL(info) << 
"Starting UniversalRobots plugin connection to UR hardware\n";
    87             std::vector<CLuaFunctionDataItem>* inData=data.
getInDataPtr();
    88             std::string Joint1Handle                        (inData->at(0 ).stringData[0]);
    89             std::string Joint2Handle                        (inData->at(1 ).stringData[0]);
    90             std::string Joint3Handle                        (inData->at(2 ).stringData[0]);
    91             std::string Joint4Handle                        (inData->at(3 ).stringData[0]);
    92             std::string Joint5Handle                        (inData->at(4 ).stringData[0]);
    93             std::string Joint6Handle                        (inData->at(5 ).stringData[0]);
    94             std::string Joint7Handle                        (inData->at(6 ).stringData[0]);
    95             std::string RobotTipHandle                      (inData->at(7 ).stringData[0]); 
    96             std::string RobotFlangeTipHandle                (inData->at(8 ).stringData[0]);
    97             std::string RobotTargetHandle                   (inData->at(9 ).stringData[0]);
    98             std::string RobotTargetBaseHandle               (inData->at(10 ).stringData[0]);
    99             std::string LocalZMQAddress                     (inData->at(11).stringData[0]);
   100             std::string RemoteZMQAddress                    (inData->at(12).stringData[0]);
   101             std::string LocalHostKukaKoniUDPAddress         (inData->at(13).stringData[0]);
   102             std::string LocalHostKukaKoniUDPPort            (inData->at(14).stringData[0]);
   103             std::string RemoteHostKukaKoniUDPAddress        (inData->at(15).stringData[0]);
   104             std::string RemoteHostKukaKoniUDPPort           (inData->at(16).stringData[0]);
   105             std::string KukaCommandMode                     (inData->at(17).stringData[0]);
   106             std::string IKGroupHandle                       (inData->at(18).stringData[0]);
   109             kukaPluginPG=std::make_shared<grl::vrep::UniversalRobotsVrepPlugin>(
   118                     RobotFlangeTipHandle          ,
   121                     RobotTargetBaseHandle         ,
   124                     LocalHostKukaKoniUDPAddress   ,
   125                     LocalHostKukaKoniUDPPort      ,
   126                     RemoteHostKukaKoniUDPAddress  ,
   127                     RemoteHostKukaKoniUDPPort     ,
   132             kukaPluginPG->construct();
   136             kukaPluginPG=std::make_shared<grl::vrep::UniversalRobotsVrepPlugin>();
   145   } 
catch (
const boost::exception& e){
   147       std::string initerr(
"v_repExtUniversalRobots plugin encountered the following error and will disable itself:\n" + boost::diagnostic_information(e));
   149       BOOST_LOG_TRIVIAL(error) <<  initerr;
   151   } 
catch (
const std::exception& e){
   153       std::string initerr(
"v_repExtUniversalRobots plugin encountered the following error and will disable itself:\n" + boost::diagnostic_information(e));
   155       BOOST_LOG_TRIVIAL(error) <<  initerr;
   159       std::string initerr(
"v_repExtUniversalRobots plugin encountered an unknown error and will disable itself. Please debug this issue! file and line:" + std::string(__FILE__) + 
" " + boost::lexical_cast<std::string>(__LINE__) + 
"\n");
   161       BOOST_LOG_TRIVIAL(error) <<  initerr;
   168 VREP_DLLEXPORT 
unsigned char v_repStart(
void* reservedPointer,
int reservedInt)
   173     char curDirAndFile[1024];
   175     GetModuleFileName(NULL,curDirAndFile,1023);
   176     PathRemoveFileSpec(curDirAndFile);
   177 #elif defined (__linux) || defined (__APPLE__)   178     getcwd(curDirAndFile, 
sizeof(curDirAndFile));
   180     std::string currentDirAndPath(curDirAndFile);
   182     std::string temp(currentDirAndPath);
   185 #elif defined (__linux)   186     temp+=
"/libv_rep.so";
   187 #elif defined (__APPLE__)   188     temp+=
"/libv_rep.dylib";
   194         BOOST_LOG_TRIVIAL(error) << 
"Error, could not find or correctly load the V-REP library. Cannot start 'v_repExtUniversalRobots' plugin.\n";
   199         BOOST_LOG_TRIVIAL(error) << 
"Error, could not find all required functions in the V-REP library. Cannot start 'v_repExtUniversalRobots' plugin.\n";
   211         BOOST_LOG_TRIVIAL(error) << 
"Sorry, your V-REP copy is somewhat old. Cannot start 'v_repExtUniversalRobots' plugin.\n";
   221     std::vector<int> inArgs;
   241     BOOST_LOG_TRIVIAL(info) << 
"KUKA LBR iiwa plugin initialized. Build date/time: " << __DATE__ << 
" " << __TIME__ <<
"\n";
   262 VREP_DLLEXPORT 
void* 
v_repMessage(
int message,
int* auxiliaryData,
void* customData,
int* replyData)
   265     static bool refreshDlgFlag=
true;
   288         int flags=auxiliaryData[0];
   289         bool sceneContentChanged=((flags&(1+2+4+8+16+32+64+256))!=0); 
   290         bool instanceSwitched=((flags&64)!=0);
   292         if (instanceSwitched)
   297         if (sceneContentChanged)
   328               } 
catch (
const boost::exception& e){
   330                   std::string initerr(
"v_repExtUniversalRobots plugin encountered the following error and will disable itself:\n" + boost::diagnostic_information(e));
   332                   BOOST_LOG_TRIVIAL(error) <<  initerr;
   334               } 
catch (
const std::exception& e){
   336                   std::string initerr(
"v_repExtUniversalRobots plugin encountered the following error and will disable itself:\n" + boost::diagnostic_information(e));
   338                   BOOST_LOG_TRIVIAL(error) <<  initerr;
   342                   std::string initerr(
"v_repExtUniversalRobots plugin encountered an unknown error and will disable itself. Please debug this issue! file and line:" + std::string(__FILE__) + 
" " + boost::lexical_cast<std::string>(__LINE__) + 
"\n");
   344                   BOOST_LOG_TRIVIAL(error) <<  initerr;
   387         BOOST_LOG_TRIVIAL(info) << 
"Ending KUKA LBR iiwa plugin connection to Kuka iiwa\n";
   394         if ( (customData==NULL)||(_stricmp(
"PluginSkeleton",(
char*)customData)==0) ) 
   402         if ( (customData==NULL)||(_stricmp(
"PluginSkeleton",(
char*)customData)==0) ) 
   410         if ( (customData==NULL)||(_stricmp(
"PluginSkeleton",(
char*)customData)==0) ) 
   439         refreshDlgFlag=
false;
 
int getVrepProcAddresses(LIBRARY lib)
 
LIBRARY loadVrepLibrary(const char *pathAndFilename)
 
bool readDataFromLua(const SLuaCallBack *p, const int *expectedArguments, int requiredArgumentCount, const char *functionName)
 
VREP_DLLEXPORT unsigned char v_repStart(void *reservedPointer, int reservedInt)
 
ptrSimSetIntegerParameter simSetIntegerParameter
 
#define LUA_KUKA_LBR_IIWA_START_COMMAND
 
void LUA_SIM_EXT_KUKA_LBR_IIWA_START(SLuaCallBack *p)
 
VREP_DLLEXPORT void * v_repMessage(int message, int *auxiliaryData, void *customData, int *replyData)
 
ptrSimGetIntegerParameter simGetIntegerParameter
 
void unloadVrepLibrary(LIBRARY lib)
 
static void getInputDataForFunctionRegistration(const int *dat, std::vector< int > &outDat)
 
ptrSimRegisterCustomLuaFunction simRegisterCustomLuaFunction
 
std::shared_ptr< grl::vrep::UniversalRobotsVrepPlugin > kukaPluginPG
 
std::string LUA_KUKA_LBR_IIWA_START_CALL_TIP("number result=simExtUniversalRobotsStart(string Joint1Handle , string Joint2Handle , string Joint3Handle , string Joint4Handle , string Joint5Handle , string Joint6Handle , string Joint7Handle , string RobotFlangeTipHandle, string RobotTipHandle, string RobotTargetHandle, string RobotTargetBaseHandle, string LocalZMQAddress, string RemoteZMQAddress, string LocalHostKukaKoniUDPAddress, string LocalHostKukaKoniUDPPort, string RemoteHostKukaKoniUDPAddress, string RemoteHostKukaKoniUDPPort, string KukaCommandMode, string RobotIKGroup) -- KukaCommandMode options are JAVA and FRI")
 
const int inArgs_KUKA_LBR_IIWA_START[]
 
ptrSimGetSimulationState simGetSimulationState
 
std::vector< CLuaFunctionDataItem > * getInDataPtr()
 
VREP_DLLEXPORT void v_repEnd()
 
ptrSimAddStatusbarMessage simAddStatusbarMessage