services.h
Go to the documentation of this file.
1 // Copyright (c) 2019 Franka Emika GmbH
2 // Use of this source code is governed by the Apache-2.0 license, see LICENSE
3 #pragma once
4 #include <vector>
5 
6 #include <franka/exception.h>
7 #include <franka/robot.h>
8 #include <ros/console.h>
9 #include <ros/node_handle.h>
10 #include <ros/service_server.h>
11 
12 #include <franka_msgs/SetCartesianImpedance.h>
13 #include <franka_msgs/SetEEFrame.h>
14 #include <franka_msgs/SetForceTorqueCollisionBehavior.h>
15 #include <franka_msgs/SetFullCollisionBehavior.h>
16 #include <franka_msgs/SetJointImpedance.h>
17 #include <franka_msgs/SetKFrame.h>
18 #include <franka_msgs/SetLoad.h>
19 
20 namespace franka_hw {
21 
31 template <typename T>
33  ros::NodeHandle& node_handle,
34  const std::string& name,
35  std::function<void(typename T::Request&, typename T::Response&)> handler) {
36  return node_handle.advertiseService<typename T::Request, typename T::Response>(
37  name, [name, handler](typename T::Request& request, typename T::Response& response) {
38  try {
39  handler(request, response);
40  response.success = true;
41  ROS_DEBUG_STREAM(name << " succeeded.");
42  } catch (const franka::Exception& ex) {
43  ROS_ERROR_STREAM(name << " failed: " << ex.what());
44  response.success = false;
45  response.error = ex.what();
46  }
47  return true;
48  });
49 }
50 
56  public:
62  template <typename T, typename... TArgs>
64  ros::ServiceServer server = franka_hw::advertiseService<T>(std::forward<TArgs>(args)...);
65  services_.push_back(server);
66  return *this;
67  }
68 
69  private:
70  std::vector<ros::ServiceServer> services_;
71 };
72 
80 void setupServices(franka::Robot& robot, ros::NodeHandle& node_handle, ServiceContainer& services);
81 
90  const franka_msgs::SetCartesianImpedance::Request& req,
91  franka_msgs::SetCartesianImpedance::Response& res);
92 
100 void setJointImpedance(franka::Robot& robot,
101  const franka_msgs::SetJointImpedance::Request& req,
102  franka_msgs::SetJointImpedance::Response& res);
103 
111 void setEEFrame(franka::Robot& robot,
112  const franka_msgs::SetEEFrame::Request& req,
113  franka_msgs::SetEEFrame::Response& res);
114 
122 void setKFrame(franka::Robot& robot,
123  const franka_msgs::SetKFrame::Request& req,
124  franka_msgs::SetKFrame::Response& res);
125 
134  franka::Robot& robot,
135  const franka_msgs::SetForceTorqueCollisionBehavior::Request& req,
136  franka_msgs::SetForceTorqueCollisionBehavior::Response& res);
137 
146  const franka_msgs::SetFullCollisionBehavior::Request& req,
147  franka_msgs::SetFullCollisionBehavior::Response& res);
148 
156 void setLoad(franka::Robot& robot,
157  const franka_msgs::SetLoad::Request& req,
158  franka_msgs::SetLoad::Response& res);
159 
160 } // 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
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
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
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
std::vector< ros::ServiceServer > services_
Definition: services.h:70
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 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
ros::ServiceServer advertiseService(ros::NodeHandle &node_handle, const std::string &name, std::function< void(typename T::Request &, typename T::Response &)> handler)
Advertises a service that acts according to the handler function which is used in the service callbac...
Definition: services.h:32
#define ROS_DEBUG_STREAM(args)
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
#define ROS_ERROR_STREAM(args)
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