services.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/services.h>
4 
5 namespace franka_hw {
6 
7 void setupServices(franka::Robot& robot, ros::NodeHandle& node_handle, ServiceContainer& services) {
8  services
9  .advertiseService<franka_msgs::SetJointImpedance>(node_handle, "set_joint_impedance",
10  [&robot](auto&& req, auto&& res) {
12  robot, req, res);
13  })
14  .advertiseService<franka_msgs::SetCartesianImpedance>(
15  node_handle, "set_cartesian_impedance",
16  [&robot](auto&& req, auto&& res) {
17  return franka_hw::setCartesianImpedance(robot, req, res);
18  })
19  .advertiseService<franka_msgs::SetEEFrame>(
20  node_handle, "set_EE_frame",
21  [&robot](auto&& req, auto&& res) { return franka_hw::setEEFrame(robot, req, res); })
22  .advertiseService<franka_msgs::SetKFrame>(
23  node_handle, "set_K_frame",
24  [&robot](auto&& req, auto&& res) { return franka_hw::setKFrame(robot, req, res); })
25  .advertiseService<franka_msgs::SetForceTorqueCollisionBehavior>(
26  node_handle, "set_force_torque_collision_behavior",
27  [&robot](auto&& req, auto&& res) {
28  return franka_hw::setForceTorqueCollisionBehavior(robot, req, res);
29  })
30  .advertiseService<franka_msgs::SetFullCollisionBehavior>(
31  node_handle, "set_full_collision_behavior",
32  [&robot](auto&& req, auto&& res) {
33  return franka_hw::setFullCollisionBehavior(robot, req, res);
34  })
35  .advertiseService<franka_msgs::SetLoad>(
36  node_handle, "set_load",
37  [&robot](auto&& req, auto&& res) { return franka_hw::setLoad(robot, req, res); });
38 }
39 
41  const franka_msgs::SetCartesianImpedance::Request& req,
42  franka_msgs::SetCartesianImpedance::Response& /* res */) {
43  std::array<double, 6> cartesian_stiffness;
44  std::copy(req.cartesian_stiffness.cbegin(), req.cartesian_stiffness.cend(),
45  cartesian_stiffness.begin());
46  robot.setCartesianImpedance(cartesian_stiffness);
47 }
48 
50  const franka_msgs::SetJointImpedance::Request& req,
51  franka_msgs::SetJointImpedance::Response& /* res */) {
52  std::array<double, 7> joint_stiffness;
53  std::copy(req.joint_stiffness.cbegin(), req.joint_stiffness.cend(), joint_stiffness.begin());
54  robot.setJointImpedance(joint_stiffness);
55 }
56 
58  const franka_msgs::SetEEFrame::Request& req,
59  franka_msgs::SetEEFrame::Response& /* res */) {
60  std::array<double, 16> F_T_EE; // NOLINT [readability-identifier-naming]
61  std::copy(req.F_T_EE.cbegin(), req.F_T_EE.cend(), F_T_EE.begin());
62  robot.setEE(F_T_EE);
63 }
64 
66  const franka_msgs::SetKFrame::Request& req,
67  franka_msgs::SetKFrame::Response& /* res */) {
68  std::array<double, 16> EE_T_K; // NOLINT [readability-identifier-naming]
69  std::copy(req.EE_T_K.cbegin(), req.EE_T_K.cend(), EE_T_K.begin());
70  robot.setK(EE_T_K);
71 }
72 
74  franka::Robot& robot,
75  const franka_msgs::SetForceTorqueCollisionBehavior::Request& req,
76  franka_msgs::SetForceTorqueCollisionBehavior::Response& /* res */
77 ) {
78  std::array<double, 7> lower_torque_thresholds_nominal;
79  std::copy(req.lower_torque_thresholds_nominal.cbegin(),
80  req.lower_torque_thresholds_nominal.cend(), lower_torque_thresholds_nominal.begin());
81  std::array<double, 7> upper_torque_thresholds_nominal;
82  std::copy(req.upper_torque_thresholds_nominal.cbegin(),
83  req.upper_torque_thresholds_nominal.cend(), upper_torque_thresholds_nominal.begin());
84  std::array<double, 6> lower_force_thresholds_nominal;
85  std::copy(req.lower_force_thresholds_nominal.cbegin(), req.lower_force_thresholds_nominal.cend(),
86  lower_force_thresholds_nominal.begin());
87  std::array<double, 6> upper_force_thresholds_nominal;
88  std::copy(req.upper_force_thresholds_nominal.cbegin(), req.upper_force_thresholds_nominal.cend(),
89  upper_force_thresholds_nominal.begin());
90 
91  robot.setCollisionBehavior(lower_torque_thresholds_nominal, upper_torque_thresholds_nominal,
92  lower_force_thresholds_nominal, upper_force_thresholds_nominal);
93 }
94 
96  const franka_msgs::SetFullCollisionBehavior::Request& req,
97  franka_msgs::SetFullCollisionBehavior::Response& /* res */) {
98  std::array<double, 7> lower_torque_thresholds_acceleration;
99  std::copy(req.lower_torque_thresholds_acceleration.cbegin(),
100  req.lower_torque_thresholds_acceleration.cend(),
101  lower_torque_thresholds_acceleration.begin());
102  std::array<double, 7> upper_torque_thresholds_acceleration;
103  std::copy(req.upper_torque_thresholds_acceleration.cbegin(),
104  req.upper_torque_thresholds_acceleration.cend(),
105  upper_torque_thresholds_acceleration.begin());
106  std::array<double, 7> lower_torque_thresholds_nominal;
107  std::copy(req.lower_torque_thresholds_nominal.cbegin(),
108  req.lower_torque_thresholds_nominal.cend(), lower_torque_thresholds_nominal.begin());
109  std::array<double, 7> upper_torque_thresholds_nominal;
110  std::copy(req.upper_torque_thresholds_nominal.cbegin(),
111  req.upper_torque_thresholds_nominal.cend(), upper_torque_thresholds_nominal.begin());
112  std::array<double, 6> lower_force_thresholds_acceleration;
113  std::copy(req.lower_force_thresholds_acceleration.cbegin(),
114  req.lower_force_thresholds_acceleration.cend(),
115  lower_force_thresholds_acceleration.begin());
116  std::array<double, 6> upper_force_thresholds_acceleration;
117  std::copy(req.upper_force_thresholds_acceleration.cbegin(),
118  req.upper_force_thresholds_acceleration.cend(),
119  upper_force_thresholds_acceleration.begin());
120  std::array<double, 6> lower_force_thresholds_nominal;
121  std::copy(req.lower_force_thresholds_nominal.cbegin(), req.lower_force_thresholds_nominal.cend(),
122  lower_force_thresholds_nominal.begin());
123  std::array<double, 6> upper_force_thresholds_nominal;
124  std::copy(req.upper_force_thresholds_nominal.cbegin(), req.upper_force_thresholds_nominal.cend(),
125  upper_force_thresholds_nominal.begin());
126  robot.setCollisionBehavior(lower_torque_thresholds_acceleration,
127  upper_torque_thresholds_acceleration, lower_torque_thresholds_nominal,
128  upper_torque_thresholds_nominal, lower_force_thresholds_acceleration,
129  upper_force_thresholds_acceleration, lower_force_thresholds_nominal,
130  upper_force_thresholds_nominal);
131 }
132 
133 void setLoad(franka::Robot& robot,
134  const franka_msgs::SetLoad::Request& req,
135  franka_msgs::SetLoad::Response& /* res */) {
136  double mass(req.mass);
137  std::array<double, 3> F_x_center_load; // NOLINT [readability-identifier-naming]
138  std::copy(req.F_x_center_load.cbegin(), req.F_x_center_load.cend(), F_x_center_load.begin());
139  std::array<double, 9> load_inertia;
140  std::copy(req.load_inertia.cbegin(), req.load_inertia.cend(), load_inertia.begin());
141 
142  robot.setLoad(mass, F_x_center_load, load_inertia);
143 }
144 
145 } // namespace franka_hw
void setKFrame(franka::Robot &robot, const franka_msgs::SetKFrame::Request &req, franka_msgs::SetKFrame::Response &res)
Callback for the service interface to franka::robot::setKFrame.
Definition: services.cpp:65
void setEE(const std::array< double, 16 > &F_T_EE)
This class serves as container that gathers all possible service interfaces to a libfranka robot inst...
Definition: services.h:55
void setJointImpedance(franka::Robot &robot, const franka_msgs::SetJointImpedance::Request &req, franka_msgs::SetJointImpedance::Response &res)
Callback for the service interface to franka::robot::setJointImpedance.
Definition: services.cpp:49
void setJointImpedance(const std::array< double, 7 > &K_theta)
void setCartesianImpedance(const std::array< double, 6 > &K_x)
void setLoad(franka::Robot &robot, const franka_msgs::SetLoad::Request &req, franka_msgs::SetLoad::Response &res)
Callback for the service interface to franka::robot::setLoad.
Definition: services.cpp:133
void setK(const std::array< double, 16 > &EE_T_K)
void setForceTorqueCollisionBehavior(franka::Robot &robot, const franka_msgs::SetForceTorqueCollisionBehavior::Request &req, franka_msgs::SetForceTorqueCollisionBehavior::Response &res)
Callback for the service interface to franka::robot::setForceTorqueCollisionBehavior.
Definition: services.cpp:73
void setupServices(franka::Robot &robot, ros::NodeHandle &node_handle, ServiceContainer &services)
Sets up all services relevant for a libfranka robot inside a service container.
Definition: services.cpp:7
ServiceContainer & advertiseService(TArgs &&...args)
Advertises and adds a service to the container class.
Definition: services.h:63
void setLoad(double load_mass, const std::array< double, 3 > &F_x_Cload, const std::array< double, 9 > &load_inertia)
void setCollisionBehavior(const std::array< double, 7 > &lower_torque_thresholds_acceleration, const std::array< double, 7 > &upper_torque_thresholds_acceleration, const std::array< double, 7 > &lower_torque_thresholds_nominal, const std::array< double, 7 > &upper_torque_thresholds_nominal, const std::array< double, 6 > &lower_force_thresholds_acceleration, const std::array< double, 6 > &upper_force_thresholds_acceleration, const std::array< double, 6 > &lower_force_thresholds_nominal, const std::array< double, 6 > &upper_force_thresholds_nominal)
void setFullCollisionBehavior(franka::Robot &robot, const franka_msgs::SetFullCollisionBehavior::Request &req, franka_msgs::SetFullCollisionBehavior::Response &res)
Callback for the service interface to franka::robot::setFullCollisionBehavior.
Definition: services.cpp:95
void setCartesianImpedance(franka::Robot &robot, const franka_msgs::SetCartesianImpedance::Request &req, franka_msgs::SetCartesianImpedance::Response &res)
Callback for the service interface to franka::robot::setCartesianImpedance.
Definition: services.cpp:40
void setEEFrame(franka::Robot &robot, const franka_msgs::SetEEFrame::Request &req, franka_msgs::SetEEFrame::Response &res)
Callback for the service interface to franka::robot::setEEFrame.
Definition: services.cpp:57


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