1 #ifndef GRL_ROS_BRIDGE_HPP_ 2 #define GRL_ROS_BRIDGE_HPP_ 8 #include <boost/log/trivial.hpp> 9 #include <boost/exception/all.hpp> 10 #include <boost/algorithm/string.hpp> 11 #include <boost/thread/mutex.hpp> 12 #include <boost/thread/locks.hpp> 15 #include <trajectory_msgs/JointTrajectory.h> 16 #include <trajectory_msgs/JointTrajectoryPoint.h> 17 #include <sensor_msgs/JointState.h> 18 #include <std_msgs/String.h> 19 #include <geometry_msgs/Wrench.h> 29 inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& out, std::vector<T>& v)
32 size_t last = v.size() - 1;
33 for(
size_t i = 0; i < v.size(); ++i) {
84 return std::make_tuple(
86 "KUKA_LBR_IIWA_14_R820" ,
88 "tcp://172.31.1.147:30010",
99 ::ros::NodeHandle nh_tilde(
"~");
101 nh_tilde.getParam(
"RobotName",std::get<RobotName>(params));
102 nh_tilde.getParam(
"RobotModel",std::get<RobotModel>(params));
103 nh_tilde.getParam(
"LocalZMQAddress",std::get<LocalZMQAddress>(params));
104 nh_tilde.getParam(
"RemoteZMQAddress",std::get<RemoteZMQAddress>(params));
105 nh_tilde.getParam(
"LocalHostKukaKoniUDPAddress",std::get<LocalHostKukaKoniUDPAddress>(params));
106 nh_tilde.getParam(
"LocalHostKukaKoniUDPPort",std::get<LocalHostKukaKoniUDPPort>(params));
107 nh_tilde.getParam(
"RemoteHostKukaKoniUDPAddress",std::get<RemoteHostKukaKoniUDPAddress>(params));
108 nh_tilde.getParam(
"RemoteHostKukaKoniUDPPort",std::get<RemoteHostKukaKoniUDPPort>(params));
109 nh_tilde.getParam(
"KukaCommandMode",std::get<KukaCommandMode>(params));
110 nh_tilde.getParam(
"KukaMonitorMode",std::get<KukaMonitorMode>(params));
149 : debug(false),params_(params), nh_(
"")
160 current_js_.name.resize(7);
161 current_js_.name[0] =
"iiwa_joint_1";
162 current_js_.name[1] =
"iiwa_joint_2";
163 current_js_.name[2] =
"iiwa_joint_3";
164 current_js_.name[3] =
"iiwa_joint_4";
165 current_js_.name[4] =
"iiwa_joint_5";
166 current_js_.name[5] =
"iiwa_joint_6";
167 current_js_.name[6] =
"iiwa_joint_7";
168 current_js_.velocity.resize(7);
169 current_js_.velocity[0] = 0.;
170 current_js_.velocity[1] = 0.;
171 current_js_.velocity[2] = 0.;
172 current_js_.velocity[3] = 0.;
173 current_js_.velocity[4] = 0.;
174 current_js_.velocity[5] = 0.;
175 current_js_.velocity[6] = 0.;
177 ::ros::NodeHandle nh;
178 js_pub_ = nh.advertise<sensor_msgs::JointState>(
"joint_states",100);
181 wrench_pub_ = nh.advertise<geometry_msgs::Wrench>(
"slave/wrench_r",100);
183 ROS_INFO(
"done creating subscribers");
205 KukaDriverP_->construct();
222 void jt_callback(
const trajectory_msgs::JointTrajectoryConstPtr &msg) {
223 boost::lock_guard<boost::mutex> lock(jt_mutex);
226 for(
auto &pt: msg->points) {
229 BOOST_THROW_EXCEPTION(std::runtime_error(
"Malformed joint trajectory request! Wrong number of joints."));
252 boost::lock_guard<boost::mutex> lock(jt_mutex);
256 ROS_INFO(
"Receiving mode command: %s", msg->data.c_str());
259 unsigned int ArmStateLen = 9;
260 for (
unsigned int i = 0; i < ArmStateLen; ++i) {
265 ROS_INFO(info.c_str());
269 KukaDriverP_->set(interaction_mode);
279 boost::lock_guard<boost::mutex> lock(jt_mutex);
283 BOOST_THROW_EXCEPTION(std::runtime_error(
"Malformed joint trajectory request! Wrong number of joints."));
317 bool haveNewData =
false;
322 switch(interaction_mode) {
325 ROS_INFO(
"Arm is in SERVO Mode");
333 ROS_INFO(
"Arm is in TEACH mode");
343 ROS_INFO(
"Sending start!");
349 ROS_INFO(
"KukaLBRiiwaROSPlugin in unsupported mode!");
352 haveNewData = KukaDriverP_->run_one();
359 current_js_.position.clear();
362 current_js_.effort.clear();
367 current_js_.header.stamp = ::ros::Time::now();
368 current_js_.header.seq += 1;
369 js_pub_.publish(current_js_);
374 std::vector<double> wrench_vector;
375 KukaDriverP_->getWrench(std::back_inserter(wrench_vector));
376 if (!wrench_vector.empty())
378 current_wrench.force.x = wrench_vector[0];
379 current_wrench.force.y = wrench_vector[1];
380 current_wrench.force.z = wrench_vector[2];
381 current_wrench.torque.x = wrench_vector[3];
382 current_wrench.torque.y = wrench_vector[4];
383 current_wrench.torque.z = wrench_vector[5];
385 wrench_pub_.publish(current_wrench);
414 boost::mutex jt_mutex;
415 boost::shared_ptr<robot::arm::KukaDriver> KukaDriverP_;
418 ::ros::Subscriber jt_sub_;
419 ::ros::Subscriber jt_pt_sub_;
420 ::ros::Subscriber mode_sub_;
422 ::ros::Publisher js_pub_;
423 ::ros::Publisher wrench_pub_;
425 sensor_msgs::JointState current_js_;
426 geometry_msgs::Wrench current_wrench;
428 ::ros::NodeHandle nh_;
void jt_pt_callback(const trajectory_msgs::JointTrajectoryPointConstPtr &msg)
bool run_one()
spin once, call this repeatedly to run the driver
bool setState(State &state)
std::vector< double > simJointTargetPosition
void jt_callback(const trajectory_msgs::JointTrajectoryConstPtr &msg)
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
boost::asio::io_service device_driver_io_service
const char ** EnumNamesArmState()
std::vector< double > JointScalar
std::vector< double > realJointPosition
static const Params defaultParams()
Kuka LBR iiwa Primary Multi Mode Driver, supports communication over FRI and JAVA interfaces...
std::tuple< JointScalar, JointScalar, JointScalar, JointScalar, JointScalar, TransformationMatrices, robot::arm::KukaJAVAdriver::JointStateTag > State
std::array< double, 12 > TransformationMatrix
void mode_callback(const std_msgs::StringConstPtr &msg)
ROS callback to set current interaction mode; determines whether commands will be send in SERVO...
void construct(Params params)
const Params & getParams()
std::vector< double > simJointPosition
KukaLBRiiwaROSPlugin(Params params=defaultParams())
std::vector< double > realJointForce
std::vector< double > simJointVelocity
std::unique_ptr< boost::asio::io_service::work > device_driver_workP_
std::unique_ptr< std::thread > driver_threadP
std::tuple< std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string > Params
KukaLBRiiwaROSPlugin::TransformationMatrices simJointTransformationMatrix
std::vector< TransformationMatrix > TransformationMatrices
std::vector< double > simJointForce
Params & loadRosParams(Params ¶ms)