1 #ifndef UniversalRobots_VREP_PLUGIN_HPP_ 2 #define UniversalRobots_VREP_PLUGIN_HPP_ 8 #include <boost/range/algorithm/copy.hpp> 9 #include <boost/asio.hpp> 10 #include <boost/log/trivial.hpp> 11 #include <boost/exception/all.hpp> 12 #include <boost/algorithm/string.hpp> 13 #include <ur_modern_driver/ur_hardware_interface_standalone.h> 22 inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& out, std::vector<T>& v)
25 size_t last = v.size() - 1;
26 for(
size_t i = 0; i < v.size(); ++i) {
35 namespace grl {
namespace vrep {
102 return std::make_tuple(
103 "LBR_iiwa_14_R820_joint1" ,
104 "LBR_iiwa_14_R820_joint2" ,
105 "LBR_iiwa_14_R820_joint3" ,
106 "LBR_iiwa_14_R820_joint4" ,
107 "LBR_iiwa_14_R820_joint5" ,
108 "LBR_iiwa_14_R820_joint6" ,
109 "LBR_iiwa_14_R820_joint7" ,
112 "RobotMillTipTarget" ,
114 "tcp://0.0.0.0:30010" ,
115 "tcp://172.31.1.147:30010",
151 device_driver_workP_.reset(
new boost::asio::io_service::work(device_driver_io_service));
154 UniversalRobotsDriverP_.reset(
new ur::UrHardwareInterfaceStandalone(std::string(std::get<LocalHostUniversalRobotsKoniUDPAddress > (params))));
161 if(!allHandlesSet) BOOST_THROW_EXCEPTION(std::runtime_error(
"UniversalRobotsVrepPlugin: Handles have not been initialized, cannot run updates."));
162 getRealUniversalRobotsAngles();
163 bool isError = getStateFromVrep();
164 allHandlesSet = !isError;
167 sendSimulatedJointAnglesToUniversalRobots();
173 device_driver_workP_.reset();
176 device_driver_io_service.stop();
177 driver_threadP->join();
187 vrepRobotArmDriverP_ = std::make_shared<VrepRobotArmDriver>
190 std::vector<std::string>
192 std::get<Joint1Name> (params_),
193 std::get<Joint2Name> (params_),
194 std::get<Joint3Name> (params_),
195 std::get<Joint4Name> (params_),
196 std::get<Joint5Name> (params_),
197 std::get<Joint6Name> (params_),
198 std::get<Joint7Name> (params_)
200 std::get<RobotFlangeTipName> (params_),
201 std::get<RobotTipName> (params_),
202 std::get<RobotTargetName> (params_),
203 std::get<RobotTargetBaseName> (params_),
204 std::get<RobotIKGroup> (params_)
207 vrepRobotArmDriverP_->construct();
209 allHandlesSet =
true;
212 void getRealUniversalRobotsAngles() {
214 m_haveReceivedRealData =
true;
215 if(UniversalRobotsDriverP_)
217 std::vector<double> vals;
218 UniversalRobotsDriverP_->read_joint_position(vals);
219 realJointPosition.clear();
220 boost::copy(vals,std::back_inserter(realJointPosition));
222 UniversalRobotsDriverP_->read_joint_velocity(vals);
223 realJointPosition.clear();
224 boost::copy(vals,std::back_inserter(realJointVelocity));
227 #if BOOST_VERSION < 105900 230 BOOST_LOG_TRIVIAL(trace) <<
"Real joint angles from FRI: " << realJointPosition <<
"\n";
235 void sendSimulatedJointAnglesToUniversalRobots(){
237 if(!allHandlesSet || !m_haveReceivedRealData)
return;
241 if( UniversalRobotsDriverP_)
243 std::vector<double> dpos;
244 boost::copy(simJointPosition,std::back_inserter(dpos));
245 UniversalRobotsDriverP_->write_joint_position(dpos);
258 bool getStateFromVrep(){
259 if(!allHandlesSet || !vrepRobotArmDriverP_)
return false;
263 bool isError = vrepRobotArmDriverP_->getState(armState);
265 if(isError)
return isError;
267 simJointPosition = std::get<VrepRobotArmDriver::JointPosition> (armState);
268 simJointForce = std::get<VrepRobotArmDriver::JointForce> (armState);
269 simJointTargetPosition = std::get<VrepRobotArmDriver::JointTargetPosition>(armState);
270 simJointTransformationMatrix = std::get<VrepRobotArmDriver::JointMatrix> (armState);
276 bool updateVrepFromUniversalRobots() {
292 for (
int i=0 ; i < 7 ; i++)
308 volatile bool allHandlesSet =
false;
309 volatile bool m_haveReceivedRealData =
false;
311 boost::asio::io_service device_driver_io_service;
312 std::unique_ptr<boost::asio::io_service::work> device_driver_workP_;
313 std::unique_ptr<std::thread> driver_threadP;
314 std::unique_ptr<ur::UrHardwareInterfaceStandalone> UniversalRobotsDriverP_;
315 std::shared_ptr<VrepRobotArmDriver> vrepRobotArmDriverP_;
319 std::vector<float> simJointPosition = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
321 std::vector<float> simJointForce = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
322 std::vector<float> simJointTargetPosition = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
326 std::vector<float> realJointPosition = { 0, 0, 0, 0, 0, 0, 0 };
329 std::vector<float> realJointForce = { 0, 0, 0, 0, 0, 0, 0 };
330 std::vector<float> realJointVelocity = { 0, 0, 0, 0, 0, 0, 0 };
OutputIterator copy(std::string model, OutputIterator it, grl::revolute_joint_velocity_open_chain_state_constraint_tag)
copy vector of joint velocity limits in radians/s
void construct(Params params)
UniversalRobotsVrepPlugin(Params params=defaultParams())
std::vector< TransformationMatrix > TransformationMatrices
static const Params defaultParams()
std::tuple< 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, std::string, std::string, std::string > Params
~UniversalRobotsVrepPlugin()
std::tuple< JointScalar, JointScalar, JointScalar, JointScalar, JointScalar, TransformationMatrices, JointStateTag, JointScalar > State