1 #ifndef _GRL_VREP_ROBOT_ARM_DRIVER_HPP_ 2 #define _GRL_VREP_ROBOT_ARM_DRIVER_HPP_ 8 #include <boost/range.hpp> 9 #include <boost/log/trivial.hpp> 10 #include <boost/exception/all.hpp> 11 #include <boost/algorithm/string.hpp> 12 #include <boost/lexical_cast.hpp> 19 namespace grl {
namespace vrep {
30 std::vector<std::string>
jointToLink(
const std::vector<std::string>& jointNames)
32 std::vector<std::string> linkNames;
33 for(std::string jointName : jointNames)
35 boost::algorithm::replace_last(jointName,
"joint",
"link");
36 linkNames.push_back(jointName);
39 linkNames.push_back(
"LBR_iiwa_14_R820_link8");
49 std::vector<std::string> linkNames_resp;
52 for(std::string linkName : linkNames)
57 boost::algorithm::replace_last(linkName,
"link" + boost::lexical_cast<std::string>(i),
"link" + boost::lexical_cast<std::string>(i) +
"_resp");
58 linkNames_resp.push_back(linkName);
63 return linkNames_resp;
86 std::vector<std::string>,
105 std::vector<std::string> jointNames{
106 "LBR_iiwa_14_R820_joint1" ,
107 "LBR_iiwa_14_R820_joint2" ,
108 "LBR_iiwa_14_R820_joint3" ,
109 "LBR_iiwa_14_R820_joint4" ,
110 "LBR_iiwa_14_R820_joint5" ,
111 "LBR_iiwa_14_R820_joint6" ,
112 "LBR_iiwa_14_R820_joint7" 115 return std::make_tuple(
119 "RobotMillTipTarget" ,
127 std::vector<std::string> jointNames{
128 "LBR_iiwa_14_R820_joint1#0" ,
129 "LBR_iiwa_14_R820_joint2#0" ,
130 "LBR_iiwa_14_R820_joint3#0" ,
131 "LBR_iiwa_14_R820_joint4#0" ,
132 "LBR_iiwa_14_R820_joint5#0" ,
133 "LBR_iiwa_14_R820_joint6#0" ,
134 "LBR_iiwa_14_R820_joint7#0" 137 return std::make_tuple(
141 "RobotMillTipTarget#0" ,
191 std::vector<int> jointHandle;
192 getHandleFromParam<JointNames>(params_,std::back_inserter(jointHandle));
195 std::move(jointHandle)
196 ,getHandleFromParam<RobotTipName> (params_)
197 ,getHandleFromParam<RobotFlangeTipName> (params_)
198 ,getHandleFromParam<RobotTargetName> (params_)
199 ,getHandleFromParam<RobotTargetBaseName> (params_)
204 linkNames =
jointToLink(std::get<JointNames>(params_));
205 getHandles(linkNames, std::back_inserter(linkHandles));
208 linkHandles.push_back(-1);
209 getHandles(boost::make_iterator_range(linkRespondableNames.begin()+1,linkRespondableNames.end()), std::back_inserter(linkHandles));
211 allHandlesSet =
true;
218 if(!allHandlesSet)
return false;
219 const std::vector<int>& jointHandle = std::get<JointNames>(handleParams_);
221 std::get<JointPosition> (state).resize(jointHandle.size());
222 std::get<JointForce> (state).resize(jointHandle.size());
223 std::get<JointTargetPosition> (state).resize(jointHandle.size());
224 std::get<JointMatrix> (state).resize(jointHandle.size());
225 std::get<JointLowerPositionLimit> (state).resize(jointHandle.size());
226 std::get<JointUpperPositionLimit> (state).resize(jointHandle.size());
235 float jointAngleInterval[2];
236 double inf = std::numeric_limits<double>::infinity();
238 for (std::size_t i=0 ; i < jointHandle.size() ; i++)
240 int currentJointHandle = jointHandle[i];
250 std::get<JointLowerPositionLimit>(state)[i] = -inf;
251 std::get<JointUpperPositionLimit>(state)[i] = inf;
255 std::get<JointLowerPositionLimit>(state)[i] = jointAngleInterval[lower];
256 std::get<JointUpperPositionLimit>(state)[i] = jointAngleInterval[upper];
297 if(!allHandlesSet)
return false;
298 const std::vector<int>& jointHandle = std::get<JointNames>(handleParams_);
299 std::vector<float> realJointPosition = std::get<JointPosition>(state);
300 std::vector<float> realJointForce = std::get<JointForce>(state);
301 std::vector<float> externalJointForce = std::get<ExternalTorque>(state);
305 for (
int i=0 ; i < 7 ; i++)
318 if (externalHandlesSet) {
324 for (
int i=0 ; i < 7 ; i++) {
325 std::string torqueString = boost::lexical_cast<std::string>(externalJointForce[i]);
326 char * externalTorqueBytes =
new char[torqueString.length()+1];
327 std::strcpy(externalTorqueBytes, torqueString.c_str());
329 simAddObjectCustomData(jointHandle[i], externalTorqueHandle, externalTorqueBytes, torqueString.length()+1);
341 return std::get<JointNames>(handleParams_);
346 return std::get<JointNames>(params_);
365 return linkRespondableHandles;
370 return linkRespondableNames;
380 return handleParams_;
389 std::vector<std::string> linkNames;
391 std::vector<std::string> linkRespondableNames;
394 std::vector<int> linkHandles;
396 std::vector<int> linkRespondableHandles;
401 int externalTorqueHandle = 310832412;
403 volatile bool allHandlesSet =
false;
404 volatile bool externalHandlesSet =
false;
415 #endif // _GRL_VREP_ROBOT_ARM_DRIVER_HPP_ bool getState(State &state)
std::array< float, 12 > TransformationMatrix
ptrSimGetJointPosition simGetJointPosition
ptrSimGetJointMatrix simGetJointMatrix
C++ interface for any open chain V-REP robot arm.
std::vector< std::string > jointToLinkRespondable(std::vector< std::string > jointNames)
ptrSimGetIkGroupHandle simGetIkGroupHandle
const std::vector< std::string > & getJointNames()
ptrSimGetJointInterval simGetJointInterval
static const Params defaultParams()
const Params & getParams()
ptrSimSetJointPosition simSetJointPosition
VrepRobotArmDriver(Params params=defaultParams())
const VrepHandleParams & getVrepHandleParams()
const std::vector< int > & getLinkHandles()
OutputIterator getHandles(const SinglePassRange inputRange, OutputIterator out)
std::tuple< std::vector< std::string >, std::string, std::string, std::string, std::string, std::string > Params
std::vector< float > JointScalar
std::tuple< std::vector< int >, int, int, int, int, int > VrepHandleParams
const std::vector< std::string > & getLinkNames()
bool setState(State &state)
std::vector< std::string > jointToLink(const std::vector< std::string > &jointNames)
std::vector< TransformationMatrix > TransformationMatrices
const std::vector< int > & getLinkRespondableHandles()
ptrSimGetJointTargetPosition simGetJointTargetPosition
ptrSimAddObjectCustomData simAddObjectCustomData
const std::vector< std::string > & getLinkRespondableNames()
ptrSimGetJointForce simGetJointForce
const std::vector< int > & getJointHandles()
std::tuple< JointScalar, JointScalar, JointScalar, JointScalar, JointScalar, TransformationMatrices, JointStateTag, JointScalar > State
static const Params measuredArmParams()