31 #include <controller_manager_msgs/ListControllers.h> 32 #include <sr_robot_msgs/sendupdate.h> 33 #include <std_msgs/Float64.h> 35 #include <boost/algorithm/string.hpp> 50 ethercat_controllers_found(false)
54 std::string robot_desc_string;
55 node_.
param(
"sh_description", robot_desc_string, std::string());
57 if (!robot_model.
initString(robot_desc_string))
59 ROS_WARN(
"Failed to parse urdf file - trying with robot_description instead of sh_description.");
61 node_.
param(
"robot_description", robot_desc_string, std::string());
62 if (!robot_model.
initString(robot_desc_string))
64 ROS_ERROR_STREAM(
"Couldn't parse the urdf file on sh_description or on robot_description (namespace=" <<
98 "controller_manager/list_controllers");
100 controller_manager_msgs::ListControllers controller_list;
101 std::string controlled_joint_name;
103 controller_list_client.
call(controller_list);
105 for (
size_t i = 0; i < controller_list.response.controller.size(); i++)
107 if (controller_list.response.controller[i].state ==
"running")
109 std::string controller =
node_.
resolveName(controller_list.response.controller[i].name);
110 if (
node_.
getParam(controller +
"/joint", controlled_joint_name))
112 ROS_DEBUG(
"controller %d:%s controls joint %s\n",
113 static_cast<int>(i), controller.c_str(), controlled_joint_name.c_str());
136 for (
size_t i = 0; i < joint_vector.size(); ++i)
138 std_msgs::Float64 target;
139 target.data = joint_vector.at(i).joint_target * M_PI / 180.0;
145 sr_robot_msgs::sendupdate sendupdate_msg;
146 sendupdate_msg.sendupdate_length = joint_vector.size();
147 sendupdate_msg.sendupdate_list = joint_vector;
157 boost::split(split_name, joint_name, boost::is_any_of(
"0"));
158 if (split_name.size() == 1)
161 joint_names.push_back(joint_name);
166 joint_names.push_back(split_name[0] +
"1");
167 joint_names.push_back(split_name[0] +
"2");
171 std::pair<double, double> min_max;
172 for (
size_t i = 0; i < joint_names.size(); ++i)
174 std::string jn = joint_names[i];
176 std::map<std::string, boost::shared_ptr<urdf::Joint> >::iterator it =
all_joints.find(jn);
180 min_max.first += it->second->limits->lower;
181 min_max.second += it->second->limits->upper;
194 std::vector<std::string> all_joints_names;
195 std::map<std::string, std::string>::iterator it;
199 all_joints_names.push_back(it->first);
202 return all_joints_names;
211 std::map<std::string, std::string>::iterator it =
sr_hand_sub_topics.find(joint_name);
223 topic =
"shadowhand_data";
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool ethercat_controllers_found
void publish(const boost::shared_ptr< M > &message) const
URDF_EXPORT bool initString(const std::string &xmlstring)
Publisher sr_hand_target_pub
Publisher for the CAN hand targets.
std::string resolveName(const std::string &name, bool remap=true) const
boost::ptr_map< std::string, Publisher > sr_hand_target_pub_map
Publishers for the ethercat hand targets for every joint.
void sendCommands(std::vector< sr_robot_msgs::joint > joint_vector)
bool call(MReq &req, MRes &res)
std::vector< std::string > get_all_joints()
std::pair< double, double > get_min_max(std::string joint_name)
NodeHandle node_
ros node handle
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
shadowhandRosLib::HandType hand_type
std::map< std::string, boost::shared_ptr< urdf::Joint > > all_joints
stores data about the hand (read from urdf)
const std::string & getNamespace() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static const double TIMEOUT_TO_DETECT_CONTROLLER_MANAGER
HandCommander(const std::string &ns="")
std::string get_controller_state_topic(std::string joint_name)
std::map< std::string, std::string > sr_hand_sub_topics
A map of topics for the controller states.
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
This is a library that offers a simple interface to send commands to hand joints. It is compatible wi...
~HandCommander()
Destructor.
void initializeEthercatHand()
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)