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> 20 #include <cartesian_impedance_msgs/SetCartesianImpedance.h> 21 #include <cartesian_impedance_msgs/SetCartesianForceCtrl.h> 29 #define meters_to_mm 1000 34 inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& out, std::vector<T>& v)
37 size_t last = v.size() - 1;
38 for(
size_t i = 0; i < v.size(); ++i) {
57 class KukaLBRiiwaROSPlugin :
public std::enable_shared_from_this<KukaLBRiiwaROSPlugin>
89 return std::make_tuple(
91 "KUKA_LBR_IIWA_14_R820" ,
92 "tcp://0.0.0.0:30010" ,
93 "tcp://172.31.1.147:30010",
104 ::ros::NodeHandle nh_tilde(
"~");
106 nh_tilde.getParam(
"RobotName",std::get<RobotName>(params));
107 nh_tilde.getParam(
"RobotModel",std::get<RobotModel>(params));
108 nh_tilde.getParam(
"LocalZMQAddress",std::get<LocalZMQAddress>(params));
109 nh_tilde.getParam(
"RemoteZMQAddress",std::get<RemoteZMQAddress>(params));
110 nh_tilde.getParam(
"LocalHostKukaKoniUDPAddress",std::get<LocalHostKukaKoniUDPAddress>(params));
111 nh_tilde.getParam(
"LocalHostKukaKoniUDPPort",std::get<LocalHostKukaKoniUDPPort>(params));
112 nh_tilde.getParam(
"RemoteHostKukaKoniUDPAddress",std::get<RemoteHostKukaKoniUDPAddress>(params));
113 nh_tilde.getParam(
"RemoteHostKukaKoniUDPPort",std::get<RemoteHostKukaKoniUDPPort>(params));
114 nh_tilde.getParam(
"KukaCommandMode",std::get<KukaCommandMode>(params));
115 nh_tilde.getParam(
"KukaMonitorMode",std::get<KukaMonitorMode>(params));
154 : debug(false),params_(params), nh_(
"")
165 current_js_.name.resize(7);
166 current_js_.name[0] =
"iiwa_joint_1";
167 current_js_.name[1] =
"iiwa_joint_2";
168 current_js_.name[2] =
"iiwa_joint_3";
169 current_js_.name[3] =
"iiwa_joint_4";
170 current_js_.name[4] =
"iiwa_joint_5";
171 current_js_.name[5] =
"iiwa_joint_6";
172 current_js_.name[6] =
"iiwa_joint_7";
173 current_js_.velocity.resize(7);
174 current_js_.velocity[0] = 0.;
175 current_js_.velocity[1] = 0.;
176 current_js_.velocity[2] = 0.;
177 current_js_.velocity[3] = 0.;
178 current_js_.velocity[4] = 0.;
179 current_js_.velocity[5] = 0.;
180 current_js_.velocity[6] = 0.;
182 ::ros::NodeHandle nh;
183 js_pub_ = nh.advertise<sensor_msgs::JointState>(
"joint_states",100);
192 ROS_INFO(
"done creating subscribers");
214 KukaDriverP_->construct();
231 void jt_callback(
const trajectory_msgs::JointTrajectoryConstPtr &msg) {
232 boost::lock_guard<boost::mutex> lock(jt_mutex);
235 for(
auto &pt: msg->points) {
238 BOOST_THROW_EXCEPTION(std::runtime_error(
"Malformed joint trajectory request! Wrong number of joints."));
260 boost::lock_guard<boost::mutex> lock(jt_mutex);
273 ROS_INFO(
"Receiving mode command: %s", msg->data.c_str());
276 unsigned int ArmStateLen = 9;
277 for (
unsigned int i = 0; i < ArmStateLen; ++i) {
282 ROS_INFO(info.c_str());
286 KukaDriverP_->set(interaction_mode);
294 boost::lock_guard<boost::mutex> lock(jt_mutex);
296 ROS_INFO(
"Dummy message set!");
297 KukaDriverP_->set(msg->data);
303 boost::lock_guard<boost::mutex> lock(jt_mutex);
304 ROS_INFO(
"Changing Cartesian Impedance Parameters");
311 grl::flatbuffer::Vector3d cart_stifness_trans(cartImpedance->stiffness.translational.x,cartImpedance->stiffness.translational.y,cartImpedance->stiffness.translational.z);
314 KukaDriverP_->set(cart_stifness_trans,cart_stifness_rot,cart_stiffness_values());
318 grl::flatbuffer::Vector3d cart_damping_trans(cartImpedance->damping.translational.x,cartImpedance->damping.translational.y,cartImpedance->damping.translational.z);
321 KukaDriverP_->set(cart_damping_trans,cart_damping_rot,cart_damping_values());
331 KukaDriverP_->set(cart_max_path_deviation,max_path_deviation());
340 KukaDriverP_->set(cart_max_ctrl_vel,max_cart_vel());
343 grl::flatbuffer::Vector3d cart_max_ctrl_force_trans(cartImpedance->max_ctrl_force.set.force.x,cartImpedance->max_ctrl_force.set.force.y,cartImpedance->max_ctrl_force.set.force.z);
353 KukaDriverP_->set(cart_max_ctrl_force,max_ctrl_force());
355 double nullspaceStiffness;
356 double nullspaceDamping;
358 nullspaceDamping = cartImpedance->null_space_params.damping[0];
359 nullspaceStiffness = cartImpedance->null_space_params.stiffness[0];
365 KukaDriverP_->set(nullspaceStiffness,nullspaceDamping,null_space_params());
376 boost::lock_guard<boost::mutex> lock(jt_mutex);
385 KukaDriverP_->set(cartFTCtrl->DOF.c_str(),cartFTCtrl->force,cartFTCtrl->stiffness,set_const_ctrl_force());
398 boost::lock_guard<boost::mutex> lock(jt_mutex);
402 BOOST_THROW_EXCEPTION(std::runtime_error(
"Malformed joint trajectory request! Wrong number of joints."));
416 ROS_INFO(
"Im in Joint trajectory msgs!!");
438 bool haveNewData =
false;
443 switch(interaction_mode) {
446 ROS_INFO(
"Arm is in SERVO Mode");
454 ROS_INFO(
"Arm is in TEACH mode");
464 ROS_INFO(
"Sending start!");
471 ROS_INFO(
"KukaLBRiiwaROSPlugin in unsupported mode!");
476 haveNewData = KukaDriverP_->run_one();
483 current_js_.position.clear();
486 current_js_.effort.clear();
491 current_js_.header.stamp = ::ros::Time::now();
492 current_js_.header.seq += 1;
493 js_pub_.publish(current_js_);
525 boost::mutex jt_mutex;
526 boost::shared_ptr<robot::arm::KukaDriver> KukaDriverP_;
529 ::ros::Subscriber jt_sub_;
530 ::ros::Subscriber jt_pt_sub_;
531 ::ros::Subscriber mode_sub_;
532 ::ros::Subscriber dummy_sub_;
533 ::ros::Subscriber cart_imp_sub_;
534 ::ros::Subscriber cart_ft_sub_;
536 ::ros::Publisher js_pub_;
539 sensor_msgs::JointState current_js_;
541 ::ros::NodeHandle nh_;
void set_force_control_callback(const cartesian_impedance_msgs::SetCartesianForceCtrlConstPtr &cartFTCtrl)
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::string dummy_message
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_
void set_cartesian_impedance_callback(const cartesian_impedance_msgs::SetCartesianImpedanceConstPtr &cartImpedance)
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)
void dummy_callback(const std_msgs::StringConstPtr &msg)