11 services[
"hebiros/"+model_name+
"/fk"] =
13 "hebiros/"+model_name+
"/fk",
18 EntryListSrv::Request &req, EntryListSrv::Response &res) {
24 AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res,
25 const std::map<std::string, std::string>& joint_full_names, std::unique_ptr<HebirosGroup> group_tmp) {
27 if (req.families.size() != 1 && req.families.size() != req.names.size()) {
28 ROS_WARN(
"Invalid number of familes for group [%s]", req.group_name.c_str());
32 auto& registry = HebirosGroupRegistry::Instance();
34 if (registry.hasGroup(req.group_name))
36 ROS_WARN(
"Group [%s] already exists!", req.group_name.c_str());
40 registry.addGroup(req.group_name, std::move(group_tmp));
43 ROS_INFO(
"Created group [%s]:", req.group_name.c_str());
44 for (
int i = 0; i < req.families.size(); i++) {
45 for (
int j = 0; j < req.names.size(); j++) {
47 if ((req.families.size() == 1) ||
48 (req.families.size() == req.names.size() && i == j)) {
50 std::string joint_name = req.families[i]+
"/"+req.names[j];
51 ROS_INFO(
"/%s/%s", req.group_name.c_str(), joint_name.c_str());
53 group->
joints[joint_name] = j;
65 AddGroupFromURDFSrv::Request &req, AddGroupFromURDFSrv::Response &res) {
67 ROS_INFO(
"Loaded URDF from robot_description");
73 std::stringstream ss(orig);
75 if (!std::getline(ss, family,
'/')) {
78 if (!std::getline(ss, name,
'/')) {
86 std::set<std::string>& families, std::map<std::string, std::string>& full_names,
87 const urdf::Link* link) {
88 for (
auto& joint : link->child_joints) {
90 if (joint->type != urdf::Joint::FIXED) {
91 std::string name, family;
93 if (
split(joint->name, name, family)) {
95 families.insert(family);
96 full_names[family+
'/'+name] = joint->name;
101 for (
auto& link_child : link->child_links) {
107 AddModelFromURDFSrv::Request &req, AddModelFromURDFSrv::Response &res) {
109 static const std::string default_desc(
"robot_description");
110 auto& description_param = req.description_param.size() == 0 ? default_desc : req.description_param;
120 SizeSrv::Request &req, SizeSrv::Response &res, std::string group_name) {
122 auto& registry = HebirosGroupRegistry::Instance();
124 if (!registry.hasGroup(group_name))
127 ROS_INFO(
"hebiros/%s not found; could not get size", group_name.c_str());
131 res.size = registry.getGroup(group_name)->size;
133 ROS_INFO(
"hebiros/%s size=%d", group_name.c_str(), res.size);
139 SetFeedbackFrequencySrv::Request &req, SetFeedbackFrequencySrv::Response &res,
140 std::string group_name) {
142 ROS_INFO(
"hebiros/%s feedback_frequency=%d", group_name.c_str(), req.feedback_frequency);
148 SetCommandLifetimeSrv::Request &req, SetCommandLifetimeSrv::Response &res,
149 std::string group_name) {
151 ROS_INFO(
"hebiros/%s command_lifetime=%d", group_name.c_str(), req.command_lifetime);
157 SendCommandWithAcknowledgementSrv::Request &req,
158 SendCommandWithAcknowledgementSrv::Response &res, std::string group_name) {
163 bool HebirosServices::fk(ModelFkSrv::Request& req, ModelFkSrv::Response& res,
const std::string& model_name) {
171 if (req.frame_type == ModelFkSrv::Request::FrameTypeCenterOfMass)
173 else if (req.frame_type == ModelFkSrv::Request::FrameTypeOutput)
177 Eigen::VectorXd joints(req.positions.size());
178 for (
size_t i = 0; i < joints.size(); ++i)
179 joints[i] = req.positions[i];
186 res.frames.resize(frames.size() * 16);
187 for (
size_t i = 0; i < frames.size(); ++i) {
188 for (
size_t j = 0; j < 4; ++j) {
189 for (
size_t k = 0; k < 4; ++k) {
190 res.frames[i * 16 + j * 4 + k] = frames[i](j, k);
std::vector< Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > Matrix4dVector
bool entryList(EntryListSrv::Request &req, EntryListSrv::Response &res)
bool addGroup(AddGroupFromNamesSrv::Request &req, AddGroupFromNamesSrv::Response &res, const std::map< std::string, std::string > &joint_full_names, std::unique_ptr< HebirosGroup > group_tmp)
bool setFeedbackFrequency(SetFeedbackFrequencySrv::Request &req, SetFeedbackFrequencySrv::Response &res, std::string group_name)
void addJointChildren(std::set< std::string > &names, std::set< std::string > &families, std::map< std::string, std::string > &full_names, const urdf::Link *link)
bool fk(ModelFkSrv::Request &req, ModelFkSrv::Response &res, const std::string &model_name)
void registerModelServices(const std::string &model_name)
static std::shared_ptr< ros::NodeHandle > n_ptr
bool split(const std::string &orig, std::string &name, std::string &family)
bool addModelFromURDF(AddModelFromURDFSrv::Request &req, AddModelFromURDFSrv::Response &res)
std::map< std::string, int > joints
hebi::robot_model::RobotModel & getModel()
bool size(SizeSrv::Request &req, SizeSrv::Response &res, std::string group_name)
static bool load(const std::string &name, const std::string &description_param)
bool sendCommandWithAcknowledgement(SendCommandWithAcknowledgementSrv::Request &req, SendCommandWithAcknowledgementSrv::Response &res, std::string group_name)
static std::map< std::string, ros::ServiceServer > services
bool setCommandLifetime(SetCommandLifetimeSrv::Request &req, SetCommandLifetimeSrv::Response &res, std::string group_name)
bool addGroupFromURDF(AddGroupFromURDFSrv::Request &req, AddGroupFromURDFSrv::Response &res)
std::map< std::string, std::string > joint_full_names