franka_hw.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Franka Emika GmbH
2 // Use of this source code is governed by the Apache-2.0 license, see LICENSE
3 #include <franka_hw/franka_hw.h>
5 
6 #include <array>
7 #include <cstdint>
8 #include <exception>
9 #include <functional>
10 #include <list>
11 #include <mutex>
12 #include <ostream>
13 #include <sstream>
14 #include <string>
15 #include <utility>
16 
17 #include <franka/control_types.h>
18 #include <franka/rate_limiting.h>
19 #include <franka/robot.h>
21 
22 namespace franka_hw {
23 
24 namespace {
25 std::ostream& operator<<(std::ostream& ostream, franka::ControllerMode mode) {
27  ostream << "joint_impedance";
29  ostream << "cartesian_impedance";
30  } else {
31  ostream << "<unknown>";
32  }
33  return ostream;
34 }
35 
36 std::string toStringWithPrecision(const double value, const size_t precision = 6) {
37  std::ostringstream out;
38  out.precision(precision);
39  out << std::fixed << value;
40  return out.str();
41 }
42 
43 } // anonymous namespace
44 
46  : position_joint_command_ros_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
47  position_joint_command_libfranka_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
48  velocity_joint_command_ros_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
49  velocity_joint_command_libfranka_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
50  effort_joint_command_ros_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
51  effort_joint_command_libfranka_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
52  pose_cartesian_command_ros_(
53  {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}),
54  pose_cartesian_command_libfranka_(
55  {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}),
56  velocity_cartesian_command_ros_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}),
57  velocity_cartesian_command_libfranka_({0.0, 0.0, 0.0, 0.0, 0.0, 0.0}) {}
58 
59 bool FrankaHW::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw_nh) {
60  if (initialized_) {
61  ROS_ERROR("FrankaHW: Cannot be initialized twice.");
62  return false;
63  }
64 
65  if (!initParameters(root_nh, robot_hw_nh)) {
66  ROS_ERROR("FrankaHW: Failed to parse all required parameters.");
67  return false;
68  }
69  try {
70  initRobot();
71  } catch (const std::runtime_error& error) {
72  ROS_ERROR("FrankaHW: Failed to initialize libfranka robot. %s", error.what());
73  return false;
74  }
75  initROSInterfaces(robot_hw_nh);
76  setupParameterCallbacks(robot_hw_nh);
77 
78  initialized_ = true;
79  return true;
80 }
81 
83  std::vector<std::string> joint_names_vector;
84  if (!robot_hw_nh.getParam("joint_names", joint_names_vector) || joint_names_vector.size() != 7) {
85  ROS_ERROR("Invalid or no joint_names parameters provided");
86  return false;
87  }
88  std::copy(joint_names_vector.cbegin(), joint_names_vector.cend(), joint_names_.begin());
89 
90  bool rate_limiting;
91  if (!robot_hw_nh.getParamCached("rate_limiting", rate_limiting)) {
92  ROS_ERROR("Invalid or no rate_limiting parameter provided");
93  return false;
94  }
95 
96  double cutoff_frequency;
97  if (!robot_hw_nh.getParamCached("cutoff_frequency", cutoff_frequency)) {
98  ROS_ERROR("Invalid or no cutoff_frequency parameter provided");
99  return false;
100  }
101 
102  std::string internal_controller;
103  if (!robot_hw_nh.getParam("internal_controller", internal_controller)) {
104  ROS_ERROR("No internal_controller parameter provided");
105  return false;
106  }
107 
108  if (!robot_hw_nh.getParam("arm_id", arm_id_)) {
109  ROS_ERROR("Invalid or no arm_id parameter provided");
110  return false;
111  }
112 
113  if (!urdf_model_.initParamWithNodeHandle("robot_description", root_nh)) {
114  ROS_ERROR("Could not initialize URDF model from robot_description");
115  return false;
116  }
117 
118  if (!robot_hw_nh.getParam("robot_ip", robot_ip_)) {
119  ROS_ERROR("Invalid or no robot_ip parameter provided");
120  return false;
121  }
122 
123  if (!robot_hw_nh.getParam("joint_limit_warning_threshold", joint_limit_warning_threshold_)) {
124  ROS_INFO(
125  "No parameter joint_limit_warning_threshold is found, using default "
126  "value %f",
128  }
129 
130  std::string realtime_config_param = robot_hw_nh.param("realtime_config", std::string("enforce"));
131  if (realtime_config_param == "enforce") {
133  } else if (realtime_config_param == "ignore") {
135  } else {
136  ROS_ERROR("Invalid realtime_config parameter provided. Valid values are 'enforce', 'ignore'.");
137  return false;
138  }
139 
140  // Get full collision behavior config from the parameter server.
141  std::vector<double> thresholds =
142  getCollisionThresholds("lower_torque_thresholds_acceleration", robot_hw_nh,
143  {20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0});
144  std::copy(thresholds.begin(), thresholds.end(),
146  thresholds = getCollisionThresholds("upper_torque_thresholds_acceleration", robot_hw_nh,
147  {20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0});
148  std::copy(thresholds.begin(), thresholds.end(),
150  thresholds = getCollisionThresholds("lower_torque_thresholds_nominal", robot_hw_nh,
151  {20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0});
152  std::copy(thresholds.begin(), thresholds.end(),
154  thresholds = getCollisionThresholds("upper_torque_thresholds_nominal", robot_hw_nh,
155  {20.0, 20.0, 18.0, 18.0, 16.0, 14.0, 12.0});
156  std::copy(thresholds.begin(), thresholds.end(),
158  thresholds.resize(6);
159  thresholds = getCollisionThresholds("lower_force_thresholds_acceleration", robot_hw_nh,
160  {20.0, 20.0, 20.0, 25.0, 25.0, 25.0});
161  std::copy(thresholds.begin(), thresholds.end(),
163  thresholds = getCollisionThresholds("upper_force_thresholds_acceleration", robot_hw_nh,
164  {20.0, 20.0, 20.0, 25.0, 25.0, 25.0});
165  std::copy(thresholds.begin(), thresholds.end(),
167  thresholds = getCollisionThresholds("lower_force_thresholds_nominal", robot_hw_nh,
168  {20.0, 20.0, 20.0, 25.0, 25.0, 25.0});
169  std::copy(thresholds.begin(), thresholds.end(),
171  thresholds = getCollisionThresholds("upper_force_thresholds_nominal", robot_hw_nh,
172  {20.0, 20.0, 20.0, 25.0, 25.0, 25.0});
173  std::copy(thresholds.begin(), thresholds.end(),
175 
176  return true;
177 }
178 
179 void FrankaHW::update(const franka::RobotState& robot_state) {
180  std::lock_guard<std::mutex> ros_lock(ros_state_mutex_);
181  robot_state_ros_ = robot_state;
182 }
183 
184 bool FrankaHW::controllerActive() const noexcept {
185  return controller_active_;
186 }
187 
189  const std::function<bool(const ros::Time&, const ros::Duration&)>& ros_callback) const {
190  if (!initialized_) {
191  ROS_ERROR("FrankaHW: Call to control before initialization!");
192  return;
193  }
194  if (!controller_active_) {
195  return;
196  }
197 
199 
200  run_function_(*robot_, [this, ros_callback, &last_time](const franka::RobotState& robot_state,
201  franka::Duration time_step) {
202  if (last_time != robot_state.time) {
203  last_time = robot_state.time;
204 
205  return ros_callback(ros::Time::now(), ros::Duration(time_step.toSec()));
206  }
207  return true;
208  });
209 }
210 
212  if (period.toSec() > 0.0) {
216  }
217 }
218 
219 bool FrankaHW::checkForConflict(const std::list<hardware_interface::ControllerInfo>& info) const {
220  ResourceWithClaimsMap resource_map = getResourceMap(info);
221  if (hasConflictingMultiClaim(resource_map)) {
222  return true;
223  }
224  ArmClaimedMap arm_claim_map;
225  if (!getArmClaimedMap(resource_map, arm_claim_map)) {
226  ROS_ERROR_STREAM("FrankaHW: Unknown interface claimed. Conflict!");
227  return true;
228  }
229  return hasConflictingJointAndCartesianClaim(arm_claim_map, arm_id_) ||
230  partiallyClaimsArmJoints(arm_claim_map, arm_id_);
231 }
232 
233 // doSwitch runs on the main realtime thread.
234 void FrankaHW::doSwitch(const std::list<hardware_interface::ControllerInfo>& /* start_list */,
235  const std::list<hardware_interface::ControllerInfo>& /* stop_list */) {
237  reset();
238  controller_active_ = true;
239  }
240 }
241 
242 // prepareSwitch runs on the background message handling thread.
243 bool FrankaHW::prepareSwitch(const std::list<hardware_interface::ControllerInfo>& start_list,
244  const std::list<hardware_interface::ControllerInfo>& stop_list) {
245  ResourceWithClaimsMap start_resource_map = getResourceMap(start_list);
246  ArmClaimedMap start_arm_claim_map;
247  if (!getArmClaimedMap(start_resource_map, start_arm_claim_map)) {
248  ROS_ERROR("FrankaHW: Unknown interface claimed for starting!");
249  return false;
250  }
251 
252  ControlMode start_control_mode = getControlMode(arm_id_, start_arm_claim_map);
253 
254  ResourceWithClaimsMap stop_resource_map = getResourceMap(stop_list);
255  ArmClaimedMap stop_arm_claim_map;
256  if (!getArmClaimedMap(stop_resource_map, stop_arm_claim_map)) {
257  ROS_ERROR("FrankaHW: Unknown interface claimed for stopping!");
258  return false;
259  }
260  ControlMode stop_control_mode = getControlMode(arm_id_, stop_arm_claim_map);
261 
262  ControlMode requested_control_mode = current_control_mode_;
263  requested_control_mode &= ~stop_control_mode;
264  requested_control_mode |= start_control_mode;
265 
266  if (!setRunFunction(requested_control_mode, get_limit_rate_(), get_cutoff_frequency_(),
268  return false;
269  }
270 
271  if (current_control_mode_ != requested_control_mode) {
272  ROS_INFO_STREAM("FrankaHW: Prepared switching controllers to "
273  << requested_control_mode << " with parameters "
274  << "limit_rate=" << get_limit_rate_()
275  << ", cutoff_frequency=" << get_cutoff_frequency_()
276  << ", internal_controller=" << get_internal_controller_());
277  current_control_mode_ = requested_control_mode;
278  controller_active_ = false;
279  }
280 
281  return true;
282 }
283 
284 std::array<double, 7> FrankaHW::getJointPositionCommand() const noexcept {
286 }
287 
288 std::array<double, 7> FrankaHW::getJointVelocityCommand() const noexcept {
290 }
291 
292 std::array<double, 7> FrankaHW::getJointEffortCommand() const noexcept {
294 }
295 
298 }
299 
301  std::string joint_limits_warning;
302  for (const auto& k_joint_name : joint_names_) {
303  try {
304  auto joint_handle = joint_state_interface_.getHandle(k_joint_name);
305  auto urdf_joint = urdf_model_.getJoint(k_joint_name);
307  if (getJointLimits(urdf_joint, joint_limits)) {
308  double joint_lower = joint_limits.min_position;
309  double joint_upper = joint_limits.max_position;
310  double joint_position = joint_handle.getPosition();
311  double dist = fmin(fabs(joint_position - joint_lower), fabs(joint_position - joint_upper));
312  if (dist < joint_limit_warning_threshold_) {
313  joint_limits_warning +=
314  "\n\t" + k_joint_name + ": " + toStringWithPrecision(dist * 180 / M_PI) +
315  " degrees to joint limits (limits: [" + toStringWithPrecision(joint_lower) + ", " +
316  toStringWithPrecision(joint_upper) + "]" +
317  " q: " + toStringWithPrecision(joint_position) + ") ";
318  }
319  } else {
320  ROS_ERROR_STREAM_ONCE("FrankaHW: Could not parse joint limit for joint "
321  << k_joint_name << " for joint limit interfaces");
322  }
324  ROS_ERROR_STREAM_ONCE("FrankaHW: Could not get joint handle " << k_joint_name << " .\n"
325  << ex.what());
326  return;
327  }
328  }
329  if (!joint_limits_warning.empty()) {
330  ROS_WARN_THROTTLE(5, "FrankaHW: %s", joint_limits_warning.c_str());
331  }
332 }
333 
335  if (!initialized_ || !robot_) {
336  std::string error_message = "FrankaHW: Attempt to access robot before initialization!";
337  ROS_ERROR("%s", error_message.c_str());
338  throw std::logic_error(error_message);
339  }
340  return *robot_;
341 }
342 
343 void FrankaHW::read(const ros::Time& /*time*/, const ros::Duration& /*period*/) {
344  std::lock_guard<std::mutex> ros_lock(ros_state_mutex_);
345  std::lock_guard<std::mutex> libfranka_lock(libfranka_state_mutex_);
347 }
348 
349 void FrankaHW::write(const ros::Time& /*time*/, const ros::Duration& /*period*/) {
350  std::lock_guard<std::mutex> ros_lock(ros_cmd_mutex_);
351  std::lock_guard<std::mutex> libfranka_lock(libfranka_cmd_mutex_);
357 }
358 
360  for (size_t i = 0; i < joint_names_.size(); i++) {
361  hardware_interface::JointStateHandle joint_handle_q(joint_names_[i], &robot_state.q[i],
362  &robot_state.dq[i], &robot_state.tau_J[i]);
363  joint_state_interface_.registerHandle(joint_handle_q);
364  }
366 }
367 
369  FrankaStateHandle franka_state_handle(arm_id_ + "_robot", robot_state);
370  franka_state_interface_.registerHandle(franka_state_handle);
372 }
373 
375  FrankaCartesianPoseHandle franka_cartesian_pose_handle(
376  franka_state_interface_.getHandle(arm_id_ + "_robot"), pose_cartesian_command.O_T_EE,
377  pose_cartesian_command.elbow);
378  franka_pose_cartesian_interface_.registerHandle(franka_cartesian_pose_handle);
380 }
381 
383  franka::CartesianVelocities& velocity_cartesian_command) {
384  FrankaCartesianVelocityHandle franka_cartesian_velocity_handle(
385  franka_state_interface_.getHandle(arm_id_ + "_robot"), velocity_cartesian_command.O_dP_EE,
386  velocity_cartesian_command.elbow);
387  franka_velocity_cartesian_interface_.registerHandle(franka_cartesian_velocity_handle);
389 }
390 
392  if (model_) {
393  franka_hw::FrankaModelHandle model_handle(arm_id_ + "_model", *model_, robot_state);
396  }
397 }
398 
399 bool FrankaHW::setRunFunction(const ControlMode& requested_control_mode,
400  const bool limit_rate,
401  const double cutoff_frequency,
402  const franka::ControllerMode internal_controller) {
403  using std::placeholders::_1;
404  using std::placeholders::_2;
405  using Callback = std::function<bool(const franka::RobotState&, franka::Duration)>;
406 
407  switch (requested_control_mode) {
408  case ControlMode::None:
409  break;
411  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
412  robot.control(std::bind(&FrankaHW::controlCallback<franka::Torques>, this,
413  std::cref(effort_joint_command_libfranka_), ros_callback, _1, _2),
414  limit_rate, cutoff_frequency);
415  };
416  break;
418  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
419  robot.control(std::bind(&FrankaHW::controlCallback<franka::JointPositions>, this,
420  std::cref(position_joint_command_libfranka_), ros_callback, _1, _2),
421  internal_controller, limit_rate, cutoff_frequency);
422  };
423  break;
425  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
426  robot.control(std::bind(&FrankaHW::controlCallback<franka::JointVelocities>, this,
427  std::cref(velocity_joint_command_libfranka_), ros_callback, _1, _2),
428  internal_controller, limit_rate, cutoff_frequency);
429  };
430  break;
432  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
433  robot.control(std::bind(&FrankaHW::controlCallback<franka::CartesianPose>, this,
434  std::cref(pose_cartesian_command_libfranka_), ros_callback, _1, _2),
435  internal_controller, limit_rate, cutoff_frequency);
436  };
437  break;
439  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
440  robot.control(
441  std::bind(&FrankaHW::controlCallback<franka::CartesianVelocities>, this,
442  std::cref(velocity_cartesian_command_libfranka_), ros_callback, _1, _2),
443  internal_controller, limit_rate, cutoff_frequency);
444  };
445  break;
447  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
448  robot.control(std::bind(&FrankaHW::controlCallback<franka::Torques>, this,
449  std::cref(effort_joint_command_libfranka_), ros_callback, _1, _2),
450  std::bind(&FrankaHW::controlCallback<franka::JointPositions>, this,
451  std::cref(position_joint_command_libfranka_), ros_callback, _1, _2),
452  limit_rate, cutoff_frequency);
453  };
454  break;
456  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
457  robot.control(std::bind(&FrankaHW::controlCallback<franka::Torques>, this,
458  std::cref(effort_joint_command_libfranka_), ros_callback, _1, _2),
459  std::bind(&FrankaHW::controlCallback<franka::JointVelocities>, this,
460  std::cref(velocity_joint_command_libfranka_), ros_callback, _1, _2),
461  limit_rate, cutoff_frequency);
462  };
463  break;
465  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
466  robot.control(std::bind(&FrankaHW::controlCallback<franka::Torques>, this,
467  std::cref(effort_joint_command_libfranka_), ros_callback, _1, _2),
468  std::bind(&FrankaHW::controlCallback<franka::CartesianPose>, this,
469  std::cref(pose_cartesian_command_libfranka_), ros_callback, _1, _2),
470  limit_rate, cutoff_frequency);
471  };
472  break;
474  run_function_ = [=](franka::Robot& robot, Callback ros_callback) {
475  robot.control(
476  std::bind(&FrankaHW::controlCallback<franka::Torques>, this,
477  std::cref(effort_joint_command_libfranka_), ros_callback, _1, _2),
478  std::bind(&FrankaHW::controlCallback<franka::CartesianVelocities>, this,
479  std::cref(velocity_cartesian_command_libfranka_), ros_callback, _1, _2),
480  limit_rate, cutoff_frequency);
481  };
482  break;
483  default:
484  ROS_WARN("FrankaHW: No valid control mode selected; cannot switch controllers.");
485  return false;
486  }
487  return true;
488 }
489 
498  setupLimitInterface<joint_limits_interface::PositionJointSoftLimitsHandle>(
500  setupLimitInterface<joint_limits_interface::VelocityJointSoftLimitsHandle>(
502  setupLimitInterface<joint_limits_interface::EffortJointSoftLimitsHandle>(
508 }
509 
511  robot_ = std::make_unique<franka::Robot>(robot_ip_, realtime_config_);
512  model_ = std::make_unique<franka::Model>(robot_->loadModel());
521  update(robot_->readOnce());
522 }
523 
525  get_limit_rate_ = [robot_hw_nh]() {
526  bool rate_limiting;
527  robot_hw_nh.getParamCached("rate_limiting", rate_limiting);
528  return rate_limiting;
529  };
530 
531  get_internal_controller_ = [robot_hw_nh]() {
532  std::string internal_controller;
533  robot_hw_nh.getParamCached("internal_controller", internal_controller);
534  franka::ControllerMode controller_mode;
535  if (internal_controller == "joint_impedance") {
536  controller_mode = franka::ControllerMode::kJointImpedance;
537  } else if (internal_controller == "cartesian_impedance") {
539  } else {
540  ROS_WARN("Invalid internal_controller parameter provided, falling back to joint impedance");
541  controller_mode = franka::ControllerMode::kJointImpedance;
542  }
543  return controller_mode;
544  };
545 
546  get_cutoff_frequency_ = [robot_hw_nh]() {
547  double cutoff_frequency;
548  robot_hw_nh.getParamCached("cutoff_frequency", cutoff_frequency);
549  return cutoff_frequency;
550  };
551 }
552 
554  return arrayHasNaN(command.tau_J);
555 }
556 
558  return arrayHasNaN(command.q);
559 }
560 
562  return arrayHasNaN(command.dq);
563 }
564 
566  return arrayHasNaN(command.elbow) || arrayHasNaN(command.O_T_EE);
567 }
568 
570  return arrayHasNaN(command.elbow) || arrayHasNaN(command.O_dP_EE);
571 }
572 
573 std::vector<double> FrankaHW::getCollisionThresholds(const std::string& name,
574  ros::NodeHandle& robot_hw_nh,
575  const std::vector<double>& defaults) {
576  std::vector<double> thresholds;
577  if (!robot_hw_nh.getParam("collision_config/" + name, thresholds) ||
578  thresholds.size() != defaults.size()) {
579  std::string message;
580  for (const double& threshold : defaults) {
581  message += std::to_string(threshold);
582  message += " ";
583  }
584  ROS_INFO("No parameter %s found, using default values: %s", name.c_str(), message.c_str());
585  return defaults;
586  }
587  return thresholds;
588 }
589 
590 } // namespace franka_hw
static bool arrayHasNaN(const std::array< double, size > &array)
Checks whether an array of doubles contains NaN values.
Definition: franka_hw.h:265
FrankaStateInterface franka_state_interface_
Definition: franka_hw.h:466
virtual std::array< double, 7 > getJointPositionCommand() const noexcept
Gets the current joint position command.
Definition: franka_hw.cpp:284
virtual void enforceLimits(const ros::Duration &period)
Enforces limits on position, velocity, and torque level.
Definition: franka_hw.cpp:211
virtual void setupFrankaCartesianPoseInterface(franka::CartesianPose &pose_cartesian_command)
Configures and registers the command interface for Cartesian poses in ros_control.
Definition: franka_hw.cpp:374
std::array< double, 7 > q
virtual void setupFrankaModelInterface(franka::RobotState &robot_state)
Configures and registers the model interface offering kinematics and dynamics in ros_control.
Definition: franka_hw.cpp:391
virtual void reset()
Resets the limit interfaces.
Definition: franka_hw.cpp:296
std::ostream & operator<<(std::ostream &ostream, ControlMode mode)
std::unique_ptr< franka::Model > model_
Definition: franka_hw.h:497
std::array< double, 7 > lower_torque_thresholds_nominal
Definition: franka_hw.h:456
std::array< double, 7 > dq
virtual bool controllerActive() const noexcept
Indicates whether there is an active controller.
Definition: franka_hw.cpp:184
#define ROS_WARN_THROTTLE(rate,...)
std::array< double, 16 > O_T_EE
franka::CartesianVelocities velocity_cartesian_command_libfranka_
Definition: franka_hw.h:487
virtual void setupFrankaCartesianVelocityInterface(franka::CartesianVelocities &velocity_cartesian_command)
Configures and registers the command interface for Cartesian velocities in ros_control.
Definition: franka_hw.cpp:382
std::string robot_ip_
Definition: franka_hw.h:501
franka::CartesianVelocities velocity_cartesian_command_ros_
Definition: franka_hw.h:494
FrankaPoseCartesianInterface franka_pose_cartesian_interface_
Definition: franka_hw.h:470
virtual void update(const franka::RobotState &robot_state)
Updates the controller interfaces from the given robot state.
Definition: franka_hw.cpp:179
bool getParamCached(const std::string &key, std::string &s) const
franka::Torques effort_joint_command_ros_
Definition: franka_hw.h:492
std::array< double, 7 > lower_torque_thresholds_acceleration
Definition: franka_hw.h:454
franka::JointVelocities velocity_joint_command_libfranka_
Definition: franka_hw.h:484
Handle to read the complete state of a robot.
FrankaVelocityCartesianInterface franka_velocity_cartesian_interface_
Definition: franka_hw.h:471
franka::JointVelocities velocity_joint_command_ros_
Definition: franka_hw.h:491
CollisionConfig collision_config_
Definition: franka_hw.h:464
virtual bool checkForConflict(const std::list< hardware_interface::ControllerInfo > &info) const override
Checks whether a requested controller can be run, based on the resources and interfaces it claims...
Definition: franka_hw.cpp:219
virtual void checkJointLimits()
Checks the proximity of each joint to its joint position limits and prints a warning whenever a joint...
Definition: franka_hw.cpp:300
URDF_EXPORT bool initParamWithNodeHandle(const std::string &param, const ros::NodeHandle &nh=ros::NodeHandle())
bool getArmClaimedMap(ResourceWithClaimsMap &resource_map, ArmClaimedMap &arm_claim_map)
virtual bool setRunFunction(const ControlMode &requested_control_mode, bool limit_rate, double cutoff_frequency, franka::ControllerMode internal_controller)
Configures the run function which is used as libfranka control callback based on the requested contro...
Definition: franka_hw.cpp:399
void control(std::function< Torques(const RobotState &, franka::Duration)> control_callback, bool limit_rate=true, double cutoff_frequency=kDefaultCutoffFrequency)
franka::Torques effort_joint_command_libfranka_
Definition: franka_hw.h:485
virtual void control(const std::function< bool(const ros::Time &, const ros::Duration &)> &ros_callback) const
Runs the currently active controller in a realtime loop.
Definition: franka_hw.cpp:188
bool hasConflictingJointAndCartesianClaim(const ArmClaimedMap &arm_claim_map, const std::string &arm_id)
franka::JointPositions position_joint_command_libfranka_
Definition: franka_hw.h:483
std::string arm_id_
Definition: franka_hw.h:500
ControlMode getControlMode(const std::string &arm_id, ArmClaimedMap &arm_claim_map)
#define ROS_WARN(...)
void enforceLimits(const ros::Duration &period)
std::map< std::string, ResourceClaims > ArmClaimedMap
FrankaHW()
Default constructor.
Definition: franka_hw.cpp:45
franka::RobotState robot_state_ros_
Definition: franka_hw.h:480
std::mutex ros_state_mutex_
Definition: franka_hw.h:478
virtual void write(const ros::Time &time, const ros::Duration &period) override
Writes data to the franka robot.
Definition: franka_hw.cpp:349
std::array< double, 6 > lower_force_thresholds_acceleration
Definition: franka_hw.h:458
franka::JointPositions position_joint_command_ros_
Definition: franka_hw.h:490
std::array< double, 7 > q
virtual void initRobot()
Uses the robot_ip_ to connect to the robot via libfranka and loads the libfranka model.
Definition: franka_hw.cpp:510
std::mutex libfranka_cmd_mutex_
Definition: franka_hw.h:482
std::unique_ptr< franka::Robot > robot_
Definition: franka_hw.h:496
std::array< double, 7 > upper_torque_thresholds_acceleration
Definition: franka_hw.h:455
bool getJointLimits(const std::string &joint_name, const ros::NodeHandle &nh, JointLimits &limits)
ControlMode current_control_mode_
Definition: franka_hw.h:508
std::array< double, 6 > upper_force_thresholds_nominal
Definition: franka_hw.h:461
franka::RobotState robot_state_libfranka_
Definition: franka_hw.h:479
std::mutex ros_cmd_mutex_
Definition: franka_hw.h:489
hardware_interface::EffortJointInterface effort_joint_interface_
Definition: franka_hw.h:469
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Handle to read and command a Cartesian velocity.
std::array< std::string, 7 > joint_names_
Definition: franka_hw.h:499
franka::RealtimeConfig realtime_config_
Definition: franka_hw.h:504
virtual std::array< double, 7 > getJointEffortCommand() const noexcept
Gets the current joint torque command.
Definition: franka_hw.cpp:292
std::array< double, 7 > dq
std::atomic_bool controller_active_
Definition: franka_hw.h:507
std::array< double, 2 > elbow
std::function< double()> get_cutoff_frequency_
Definition: franka_hw.h:512
virtual bool initParameters(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
Reads the parameterization of the hardware class from the ROS parameter server (e.g.
Definition: franka_hw.cpp:82
std::function< franka::ControllerMode()> get_internal_controller_
Definition: franka_hw.h:510
std::map< std::string, std::vector< std::vector< std::string >>> ResourceWithClaimsMap
virtual void setupParameterCallbacks(ros::NodeHandle &robot_hw_nh)
Initializes the callbacks for on-the-fly reading the parameters for rate limiting, internal controllers and cutoff frequency.
Definition: franka_hw.cpp:524
void setupJointCommandInterface(std::array< double, 7 > &command, franka::RobotState &state, bool use_q_d, T &interface)
Configures and registers a joint command interface for positions velocities or efforts in ros_control...
Definition: franka_hw.h:366
virtual void read(const ros::Time &time, const ros::Duration &period) override
Reads data from the franka robot.
Definition: franka_hw.cpp:343
void registerHandle(const JointStateHandle &handle)
Handle to read and command a Cartesian pose.
hardware_interface::PositionJointInterface position_joint_interface_
Definition: franka_hw.h:467
joint_limits_interface::PositionJointSoftLimitsInterface position_joint_limit_interface_
Definition: franka_hw.h:473
static std::vector< double > getCollisionThresholds(const std::string &name, ros::NodeHandle &robot_hw_nh, const std::vector< double > &defaults)
Parses a set of collision thresholds from the parameter server.
Definition: franka_hw.cpp:573
JointStateHandle getHandle(const std::string &name)
virtual void setupJointStateInterface(franka::RobotState &robot_state)
Configures and registers the joint state interface in ros_control.
Definition: franka_hw.cpp:359
joint_limits_interface::VelocityJointSoftLimitsInterface velocity_joint_limit_interface_
Definition: franka_hw.h:474
urdf::Model urdf_model_
Definition: franka_hw.h:502
#define ROS_INFO_STREAM(args)
virtual franka::Robot & robot() const
Getter for the libfranka robot instance.
Definition: franka_hw.cpp:334
double joint_limit_warning_threshold_
Definition: franka_hw.h:503
virtual bool prepareSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list) override
Prepares switching between controllers (not real-time capable).
Definition: franka_hw.cpp:243
bool getParam(const std::string &key, std::string &s) const
std::array< double, 6 > O_dP_EE
FrankaModelInterface franka_model_interface_
Definition: franka_hw.h:472
std::array< double, 6 > lower_force_thresholds_nominal
Definition: franka_hw.h:460
franka::CartesianPose pose_cartesian_command_ros_
Definition: franka_hw.h:493
bool partiallyClaimsArmJoints(const ArmClaimedMap &arm_claim_map, const std::string &arm_id)
hardware_interface::VelocityJointInterface velocity_joint_interface_
Definition: franka_hw.h:468
#define ROS_ERROR_STREAM_ONCE(args)
virtual void setupFrankaStateInterface(franka::RobotState &robot_state)
Configures and registers the state interface offering the full franka::RobotState in ros_control...
Definition: franka_hw.cpp:368
std::function< void(franka::Robot &, Callback)> run_function_
Definition: franka_hw.h:513
std::array< double, 7 > upper_torque_thresholds_nominal
Definition: franka_hw.h:457
hardware_interface::JointStateInterface joint_state_interface_
Definition: franka_hw.h:465
std::array< double, 6 > upper_force_thresholds_acceleration
Definition: franka_hw.h:459
std::array< double, 7 > tau_J
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh) override
Initializes the FrankaHW class to be fully operational.
Definition: franka_hw.cpp:59
franka::CartesianPose pose_cartesian_command_libfranka_
Definition: franka_hw.h:486
#define ROS_ERROR_STREAM(args)
Handle to perform calculations using the dynamic model of a robot.
virtual std::array< double, 7 > getJointVelocityCommand() const noexcept
Gets the current joint velocity command.
Definition: franka_hw.cpp:288
#define ROS_ERROR(...)
std::array< double, 7 > tau_J
virtual void initROSInterfaces(ros::NodeHandle &robot_hw_nh)
Initializes the class in terms of ros_control interfaces.
Definition: franka_hw.cpp:490
std::function< bool(const franka::RobotState &, franka::Duration)> Callback
Definition: franka_hw.h:269
ResourceWithClaimsMap getResourceMap(const std::list< hardware_interface::ControllerInfo > &info)
bool hasConflictingMultiClaim(const ResourceWithClaimsMap &resource_map)
virtual void doSwitch(const std::list< hardware_interface::ControllerInfo > &, const std::list< hardware_interface::ControllerInfo > &) override
Performs controller switching (real-time capable).
Definition: franka_hw.cpp:234
std::function< bool()> get_limit_rate_
Definition: franka_hw.h:511
std::mutex libfranka_state_mutex_
Definition: franka_hw.h:477
std::array< double, 2 > elbow
joint_limits_interface::EffortJointSoftLimitsInterface effort_joint_limit_interface_
Definition: franka_hw.h:475
static bool commandHasNaN(const franka::Torques &command)
Checks a command for NaN values.
Definition: franka_hw.cpp:553


franka_hw
Author(s): Franka Emika GmbH
autogenerated on Fri Oct 23 2020 03:47:05