32 #include <boost/algorithm/string.hpp> 35 #include <std_msgs/Float64.h> 50 ROS_INFO(
"This ROS interface is built for Gazebo.");
53 std::string searched_param;
57 std::string full_topic = prefix +
"joint_states";
58 gazebo_subscriber =
node.
subscribe(full_topic, 2, &VirtualShadowhand::gazeboCallback,
this);
60 ROS_INFO(
"This ROS interface is not built for Gazebo.");
82 tmpDataZero.
max = 180.0;
85 std::string topic_prefix =
"/sh_";
86 std::string topic_suffix =
"_mixed_position_velocity_controller/command";
87 std::string full_topic =
"";
91 std::string robot_desc_string;
92 node.
param(
"hand_description", robot_desc_string, std::string());
94 if (!robot_model.
initString(robot_desc_string))
100 std::map<std::string, boost::shared_ptr<urdf::Joint> > all_joints = robot_model.joints_;
101 std::map<std::string, boost::shared_ptr<urdf::Joint> >::const_iterator iter = all_joints.begin();
109 for (; iter != all_joints.end(); ++iter)
111 if (iter->second->type == urdf::Joint::REVOLUTE)
113 std::string current_joint_name = iter->first;
123 bool no_controller =
false;
126 bool create_joint_zero =
false;
127 boost::algorithm::to_lower(current_joint_name);
128 if (current_joint_name ==
"ffj2" || current_joint_name ==
"mfj2" 129 || current_joint_name ==
"rfj2" || current_joint_name ==
"lfj2")
131 create_joint_zero =
true;
134 no_controller =
true;
139 if (current_joint_name ==
"ffj1" || current_joint_name ==
"mfj1" 140 || current_joint_name ==
"rfj1" || current_joint_name ==
"lfj1")
142 no_controller =
true;
146 if (create_joint_zero)
149 full_topic = topic_prefix + std::string(1, current_joint_name[0]) +
"fj0" + topic_suffix;
150 gazebo_publishers.push_back(
node.
advertise<std_msgs::Float64>(full_topic, 2));
155 boost::algorithm::to_upper(current_joint_name);
156 joints_map[std::string(1, current_joint_name[0]) +
"FJ0"] = tmpDataZero;
157 controllers_map[std::string(1, current_joint_name[0]) +
"FJ0"] = tmpController;
169 boost::algorithm::to_lower(current_joint_name);
170 full_topic = topic_prefix + current_joint_name + topic_suffix;
171 gazebo_publishers.push_back(
node.
advertise<std_msgs::Float64>(full_topic, 2));
178 boost::algorithm::to_upper(current_joint_name);
229 JointsMap::iterator iter =
joints_map.find(joint_name);
231 std_msgs::Float64 target_msg;
237 ROS_DEBUG(
"Joint %s not found", joint_name.c_str());
249 if (iter->second.isJointZero == 1)
253 if (target < tmpData0.
min)
255 target = tmpData0.
min;
257 if (target > tmpData0.
max)
259 target = tmpData0.
max;
273 target_msg.data =
toRad(target);
278 tmpData1.
target = target / 2.0;
289 tmpData2.
target = target / 2.0;
300 if (target < tmpData.
min)
302 target = tmpData.
min;
304 if (target > tmpData.
max)
306 target = tmpData.
max;
311 target_msg.data =
toRad(target);
328 JointsMap::iterator iter =
joints_map.find(joint_name);
334 iter->second.temperature = 0.0;
335 iter->second.current = 0.0;
337 iter->second.force = 0.0;
346 ROS_ERROR(
"Joint %s not found.", joint_name.c_str());
388 ROS_ERROR(
"Controller %s not found", contrlr_name.c_str());
408 ROS_ERROR(
"Controller %s not found", contrlr_name.c_str());
416 ROS_WARN(
"The set config function is not implemented in the virtual shadowhand.");
422 ROS_WARN(
"The get config function is not implemented in the virtual shadowhand.");
428 std::vector<DiagnosticData> returnVect;
437 tmpDiag.
target = it->second.target;
439 tmpDiag.
position = it->second.position;
441 returnVect.push_back(tmpDiag);
449 void VirtualShadowhand::gazeboCallback(
const sensor_msgs::JointStateConstPtr &
msg)
454 for (
unsigned int index = 0; index < msg->name.size(); ++index)
456 std::string joint_name = msg->name[index];
457 JointsMap::iterator iter =
joints_map.find(joint_name);
468 tmpData.
force = msg->effort[index];
479 std::string joint_name = it->first;
480 double position = 0.0;
virtual int16_t setContrl(std::string contrlr_name, JointControllerData ctrlr_data)
virtual JointControllerData getContrl(std::string ctrlr_name)
ros::NodeHandle node
ROS Node handles.
virtual int16_t setConfig(std::vector< std::string > myConfig)
URDF_EXPORT bool initString(const std::string &xmlstring)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string flags
a string containing flags: FORCE, TEMPERATURE, ... indicating the different cutouts / warning sent by...
std::string joint_name
the name of the joint
std::map< std::string, JointData > JointsMap
int target_sensor_num
the channel number of the target sensor
int position_sensor_num
the channel number of the position sensor
virtual std::vector< DiagnosticData > getDiagnostics()
static double to_degrees(double rad)
virtual void getConfig(std::string joint_name)
boost::mutex parameters_map_mutex
ControllersMap controllers_map
Contains the mapping between the controller names and their data.
bool searchParam(const std::string &key, std::string &result) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
JointsMap joints_map
A mapping between the joint names and the information regarding those joints.
virtual ~VirtualShadowhand()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
ParametersMap parameters_map
A mapping between the parameter names and their values.
This is a parent class for the different types of Shadowhand we can have. It makes it possible to swa...
virtual JointsMap getAllJointsData()
double toDegrees(double rad)
boost::mutex joints_map_mutex
virtual int16_t sendupdate(std::string joint_name, double target)
int16_t level
the level of alert: 0 = OK, 1 = WARNING, 2 = ERROR
boost::mutex controllers_map_mutex
double target
the actual value of the target
virtual JointData getJointData(std::string joint_name)
double position
the actual value of the position
The Virtual Shadowhand can be used as a simulator. As both the real hand and the virtual hand are chi...