1 #ifndef KUKA_VREP_PLUGIN_HPP_     2 #define KUKA_VREP_PLUGIN_HPP_     8 #include <boost/log/trivial.hpp>     9 #include <boost/exception/all.hpp>    10 #include <boost/algorithm/string.hpp>    20 inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& out,  std::vector<T>& v)
    23     size_t last = v.size() - 1;
    24     for(
size_t i = 0; i < v.size(); ++i) {
    33 namespace grl { 
namespace vrep {
    73         std::vector<std::string>,
    93         std::vector<std::string> jointHandles;
    95         jointHandles.push_back(
"LBR_iiwa_14_R820_joint1"); 
    96         jointHandles.push_back(
"LBR_iiwa_14_R820_joint2"); 
    97         jointHandles.push_back(
"LBR_iiwa_14_R820_joint3"); 
    98         jointHandles.push_back(
"LBR_iiwa_14_R820_joint4"); 
    99         jointHandles.push_back(
"LBR_iiwa_14_R820_joint5"); 
   100         jointHandles.push_back(
"LBR_iiwa_14_R820_joint6"); 
   101         jointHandles.push_back(
"LBR_iiwa_14_R820_joint7"); 
   102         return std::make_tuple(
   106                     "RobotMillTipTarget"      , 
   108                     "KUKA_LBR_IIWA_14_R820"   , 
   125         std::vector<std::string> jointHandles;
   127         jointHandles.push_back(
"LBR_iiwa_14_R820_joint1#0"); 
   128         jointHandles.push_back(
"LBR_iiwa_14_R820_joint2#0"); 
   129         jointHandles.push_back(
"LBR_iiwa_14_R820_joint3#0"); 
   130         jointHandles.push_back(
"LBR_iiwa_14_R820_joint4#0"); 
   131         jointHandles.push_back(
"LBR_iiwa_14_R820_joint5#0"); 
   132         jointHandles.push_back(
"LBR_iiwa_14_R820_joint6#0"); 
   133         jointHandles.push_back(
"LBR_iiwa_14_R820_joint7#0"); 
   134         return std::make_tuple(
   138                     "RobotMillTipTarget#0"    , 
   140                     "KUKA_LBR_IIWA_14_R820"   , 
   183   device_driver_workP_.reset(
new boost::asio::io_service::work(device_driver_io_service));
   184   kukaDriverP_=std::make_shared<robot::arm::KukaDriver>(std::make_tuple(
   186         std::get<RobotTargetBaseName>(params),
   187         std::get<RobotModel>(params),
   188         std::get<LocalUDPAddress>(params),
   189         std::get<LocalUDPPort>(params),
   190         std::get<RemoteUDPAddress>(params),
   191         std::get<LocalHostKukaKoniUDPAddress>(params),
   192         std::get<LocalHostKukaKoniUDPPort>(params),
   193         std::get<RemoteHostKukaKoniUDPAddress>(params),
   194         std::get<RemoteHostKukaKoniUDPPort>(params),
   195         std::get<KukaCommandMode>(params),
   196         std::get<KukaMonitorMode>(params)
   200   kukaDriverP_->construct();
   202     std::cout << 
"KUKA COMMAND MODE: " << std::get<KukaCommandMode>(params) << 
"\n";
   209   if(!allHandlesSet) BOOST_THROW_EXCEPTION(std::runtime_error(
"KukaVrepPlugin: Handles have not been initialized, cannot run updates."));
   211   bool isError = getStateFromVrep(); 
   212   allHandlesSet = !isError;
   219     device_driver_workP_.reset();
   222       device_driver_io_service.stop();
   223       driver_threadP->join();
   233     vrepRobotArmDriverP_ = std::make_shared<VrepRobotArmDriver>
   236             std::get<JointNames>             (params_),
   237             std::get<RobotFlangeTipName>     (params_),
   238             std::get<RobotTipName>           (params_),
   239             std::get<RobotTargetName>        (params_),
   240             std::get<RobotTargetBaseName>    (params_),
   241             std::get<IKGroupName>            (params_)
   246     vrepRobotArmDriverP_->construct();
   249     vrepMeasuredRobotArmDriverP_ = std::make_shared<VrepRobotArmDriver>
   252             std::get<JointNames>             (measuredParams_),
   253             std::get<RobotFlangeTipName>     (measuredParams_),
   254             std::get<RobotTipName>           (measuredParams_),
   255             std::get<RobotTargetName>        (measuredParams_),
   256             std::get<RobotTargetBaseName>    (measuredParams_),
   257             std::get<IKGroupName>            (measuredParams_)
   260     vrepMeasuredRobotArmDriverP_->construct();
   264     allHandlesSet  = 
true;
   267 void getRealKukaAngles() {
   269       m_haveReceivedRealData = 
true;
   275 void syncVrepAndKuka(){
   277         if(!allHandlesSet || !m_haveReceivedRealData) 
return;
   285         kukaDriverP_->run_one();
   288         realJointPosition.clear();
   291         realJointForce.clear();
   294         realExternalJointTorque.clear();
   297         realExternalForce.clear();
   302         std::cout << 
"Measured Torque: ";
   303         std::cout << std::setw(6);
   304         for (
float t:realJointForce) {
   305             std::cout << t << 
" ";
   309         std::cout << 
"External Torque: ";
   310         std::cout << std::setw(6);
   311         for (
float t:realExternalJointTorque) {
   312             std::cout << t << 
" ";
   316         std::cout << 
"Measured Position: ";
   317         for (
float t:realJointPosition) {
   318             std::cout << t << 
" ";
   323     if(!allHandlesSet || !vrepMeasuredRobotArmDriverP_) 
return;
   325     if (realJointPosition.size() > 0) { 
   327         std::get<VrepRobotArmDriver::JointPosition>(measuredArmState) = realJointPosition;
   328         std::get<VrepRobotArmDriver::JointForce>(measuredArmState) = realJointForce;
   329         std::get<VrepRobotArmDriver::ExternalTorque>(measuredArmState) = realExternalJointTorque;
   331         vrepMeasuredRobotArmDriverP_->setState(measuredArmState);
   344 bool getStateFromVrep(){
   345             if(!allHandlesSet || !vrepRobotArmDriverP_) 
return false;
   349             bool isError = vrepRobotArmDriverP_->getState(armState);
   351             if(isError) 
return isError;
   353             simJointPosition             = std::get<VrepRobotArmDriver::JointPosition>      (armState);
   354             simJointForce                = std::get<VrepRobotArmDriver::JointForce>         (armState);
   355             simJointTargetPosition       = std::get<VrepRobotArmDriver::JointTargetPosition>(armState);
   356             simJointTransformationMatrix = std::get<VrepRobotArmDriver::JointMatrix>        (armState);
   393 bool updateVrepFromKuka() {
   409             for (
int i=0 ; i < 7 ; i++)
   424 volatile bool allHandlesSet = 
false;
   425 volatile bool m_haveReceivedRealData = 
false;
   427 double simulationTimeStep_; 
   429 boost::asio::io_service device_driver_io_service;
   430 std::unique_ptr<boost::asio::io_service::work> device_driver_workP_;
   431 std::unique_ptr<std::thread> driver_threadP;
   432 std::shared_ptr<grl::robot::arm::KukaDriver> kukaDriverP_;
   433 std::shared_ptr<VrepRobotArmDriver> vrepRobotArmDriverP_;
   434 std::shared_ptr<VrepRobotArmDriver> vrepMeasuredRobotArmDriverP_;
   438 std::vector<float> simJointPosition = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
   440 std::vector<float> simJointForce = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
   441 std::vector<float> simJointTargetPosition = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
   445 std::vector<float> realJointPosition        = { 0, 0, 0, 0, 0, 0, 0 };
   448 std::vector<float> realJointForce           = { 0, 0, 0, 0, 0, 0, 0 };
   451 std::vector<float> realExternalJointTorque  = { 0, 0, 0, 0, 0, 0, 0};
   452 std::vector<float> realExternalForce = { 0, 0, 0, 0, 0, 0};
   457 std::shared_ptr<KUKA::FRI::ClientData> friData_;
 void construct(Params params)
 
external joint torque, i.e. torques applied to an arm excluding those caused by the mass of the arm i...
 
static const Params measuredArmParams()
 
std::tuple< std::vector< std::string >, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string > Params
 
the time duration over which a command should be completed 
 
static const Params defaultParams()
 
std::vector< TransformationMatrix > TransformationMatrices
 
external forces, i.e. forces applied to an arm excluding those caused by the mass of the arm itself a...
 
KukaVrepPlugin(Params params=defaultParams())
 
std::tuple< JointScalar, JointScalar, JointScalar, JointScalar, JointScalar, TransformationMatrices, JointStateTag, JointScalar > State
 
ptrSimGetSimulationTimeStep simGetSimulationTimeStep