1 #include <OgreSceneNode.h> 2 #include <OgreSceneManager.h> 11 #include <boost/foreach.hpp> 75 M_JointInfo::iterator it = joints_.find(joint);
76 if (it == joints_.end())
87 joints_.insert(std::make_pair(joint, info));
94 alpha_property_ =
new rviz::FloatProperty(
"Alpha", 1.0,
"0 is fully transparent, 1.0 is fully opaque.",
95 this, SLOT(updateColorAndAlpha()));
97 width_property_ =
new rviz::FloatProperty(
"Width", 0.02,
"Width to drow effort circle",
this,
98 SLOT(updateColorAndAlpha()));
100 scale_property_ =
new rviz::FloatProperty(
"Scale", 1.0,
"Scale to drow effort circle",
this,
101 SLOT(updateColorAndAlpha()));
103 history_length_property_ =
104 new rviz::IntProperty(
"History Length", 1,
"Number of prior measurements to display.",
this,
105 SLOT(updateHistoryLength()));
106 history_length_property_->setMin(1);
107 history_length_property_->setMax(100000);
110 robot_description_property_ =
112 "Name of the parameter to search for to load the robot description.",
113 this, SLOT(updateRobotDescription()));
117 "Robot Model normally assumes the link name is the same as the tf frame name. " 118 " This option allows you to set a prefix. Mainly useful for multi-robot situations.",
119 this, SLOT(updateTfPrefix()));
121 joints_category_ =
new rviz::Property(
"Joints", QVariant(),
"",
this);
126 MFDClass::onInitialize();
127 updateHistoryLength();
145 context_->queueRender();
151 robot_description_.clear();
157 float width = width_property_->getFloat();
158 float scale = scale_property_->getFloat();
160 for (
size_t i = 0; i < visuals_.size(); i++)
162 visuals_[i]->setWidth(width);
163 visuals_[i]->setScale(scale);
172 context_->queueRender();
179 visuals_.rset_capacity(history_length_property_->getInt());
188 if (!update_nh_.getParam(robot_description_property_->getStdString(), content))
191 if (update_nh_.searchParam(robot_description_property_->getStdString(), loc))
192 update_nh_.getParam(loc, content);
197 QString(
"Parameter [%1] does not exist, and was not found by searchParam()")
198 .arg(robot_description_property_->getString()));
200 QTimer::singleShot(1000,
this, SLOT(updateRobotDescription()));
209 QString(
"Invalid parameter name: %1.\n%2")
210 .arg(robot_description_property_->getString(), e.what()));
221 if (content == robot_description_)
226 robot_description_ = content;
230 if (!robot_model_->initString(content))
232 ROS_ERROR(
"Unable to parse URDF description!");
237 for (std::map<std::string, urdf::JointSharedPtr>::iterator it = robot_model_->joints_.begin();
238 it != robot_model_->joints_.end(); it++)
240 urdf::JointSharedPtr joint = it->second;
241 if (joint->type == urdf::Joint::REVOLUTE)
243 std::string joint_name = it->first;
244 urdf::JointLimitsSharedPtr
limit = joint->limits;
245 joints_[joint_name] = createJoint(joint_name);
246 joints_[joint_name]->setMaxEffort(limit->effort);
262 void EffortDisplay::setRobotDescription(
const std::string& description_param )
264 description_param_ = description_param;
266 propertyChanged(robot_description_property_);
277 void EffortDisplay::setAllEnabled(
bool enabled)
279 all_enabled_ = enabled;
281 M_JointInfo::iterator it = joints_.begin();
282 M_JointInfo::iterator end = joints_.end();
283 for (; it != end; ++it)
287 setJointEnabled(joint, enabled);
290 propertyChanged(all_enabled_property_);
307 visual = visuals_.front();
311 visual.reset(
new EffortVisual(context_->getSceneManager(), scene_node_, robot_model_));
315 size_t joint_num = msg->name.size();
316 if (joint_num != msg->effort.size())
318 std::string tmp_error =
"Received a joint state msg with different joint names and efforts size!";
323 for (
size_t i = 0; i < joint_num; ++i)
325 std::string joint_name = msg->name[i];
326 JointInfo* joint_info = getJointInfo(joint_name);
339 const urdf::Joint* joint = robot_model_->getJoint(joint_name).get();
340 int joint_type = joint->type;
341 if (joint_type == urdf::Joint::REVOLUTE)
343 std::string tf_prefix = tf_prefix_property_->getStdString();
344 std::string tf_frame_id = (tf_prefix.empty() ?
"" : tf_prefix +
"/") + joint->child_link_name;
345 Ogre::Quaternion orientation;
346 Ogre::Vector3 position;
351 if (!context_->getFrameManager()->getTransform(tf_frame_id,
ros::Time(),
353 position, orientation))
355 ROS_DEBUG(
"Error transforming from frame '%s' to frame '%s'", tf_frame_id.c_str(),
356 qPrintable(fixed_frame_));
359 tf::Vector3 axis_joint(joint->axis.x, joint->axis.y, joint->axis.z);
360 tf::Vector3 axis_z(0, 0, 1);
362 if (std::isnan(axis_rotation.x()) || std::isnan(axis_rotation.y()) || std::isnan(axis_rotation.z()))
365 tf::Quaternion axis_orientation(orientation.x, orientation.y, orientation.z, orientation.w);
367 Ogre::Quaternion joint_orientation(Ogre::Real(axis_rot.w()), Ogre::Real(axis_rot.x()),
368 Ogre::Real(axis_rot.y()), Ogre::Real(axis_rot.z()));
369 visual->setFramePosition(joint_name, position);
370 visual->setFrameOrientation(joint_name, joint_orientation);
371 visual->setFrameEnabled(joint_name, joint_info->
getEnabled());
377 float scale = scale_property_->getFloat();
378 float width = width_property_->getFloat();
379 visual->setWidth(width);
380 visual->setScale(scale);
381 visual->setMessage(msg);
383 visuals_.push_back(visual);
void onDisable() override
Derived classes override this to do the actual work of disabling themselves.
void processMessage(const sensor_msgs::JointState::ConstPtr &msg) override
Implement this to process the contents of a message.
void updateRobotDescription()
void updateColorAndAlpha()
void reset() override
Called to tell the display to clear its state.
A single element of a property tree, with a name, value, description, and possibly children...
JointInfo(const std::string name, rviz::Property *parent_category)
Property specialized to enforce floating point max/min.
Property specialized to provide max/min enforcement for integers.
void setMaxEffort(double m)
void updateHistoryLength()
void onEnable() override
Derived classes override this to do the actual work of enabling themselves.
bool setFloat(float new_value)
Float-typed "SLOT" version of setValue().
JointInfo * getJointInfo(const std::string &joint)
JointInfo * createJoint(const std::string &joint)
static const Quaternion & getIdentity()
TFSIMD_FORCE_INLINE Vector3 tfCross(const Vector3 &v1, const Vector3 &v2)
rviz::FloatProperty * max_effort_property_
std::vector< std::string > V_string
~EffortDisplay() override
TFSIMD_FORCE_INLINE tfScalar tfAngle(const Vector3 &v1, const Vector3 &v2)
Property specialized for string values.
rviz::FloatProperty * effort_property_
rviz::Property * category_
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
void onInitialize() override
Override this function to do subclass-specific initialization.
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)