Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robot: Report mesh loading issues #1629

Merged
merged 4 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/rviz/default_plugin/robot_model_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "rviz/display_context.h"
#include "rviz/robot/robot.h"
#include "rviz/robot/robot_link.h"
#include "rviz/robot/tf_link_updater.h"
#include "rviz/properties/float_property.h"
#include "rviz/properties/property.h"
Expand Down Expand Up @@ -192,6 +193,17 @@ void RobotModelDisplay::load()

setStatus(StatusProperty::Ok, "URDF", "URDF parsed OK");
robot_->load(descr);
std::stringstream ss;
for (const auto& name_link_pair : robot_->getLinks())
{
const std::string& err = name_link_pair.second->getGeometryErrors();
if (!err.empty())
ss << "\n• for link '" << name_link_pair.first << "':\n" << err;
}
if (ss.tellp())
setStatus(StatusProperty::Error, "URDF",
QString("Errors loading geometries:").append(ss.str().c_str()));

robot_->update(TFLinkUpdater(context_->getFrameManager(),
boost::bind(linkUpdaterStatusFunction, _1, _2, _3, this),
tf_prefix_property_->getStdString()));
Expand Down
1 change: 1 addition & 0 deletions src/rviz/properties/property_tree_with_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void PropertyTreeWithHelp::showHelpForProperty(const Property* property)
{
QString body_text = property->getDescription();
QString heading = property->getName();
body_text.replace("\n", "<br>");
QString html = "<html><body><strong>" + heading + "</strong><br>" + body_text + "</body></html>";
help_->setHtml(html);
}
Expand Down
39 changes: 30 additions & 9 deletions src/rviz/robot/robot_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void RobotLinkSelectionHandler::postRenderPass(uint32_t /*pass*/)
}
}

static std::map<const RobotLink*, std::string> errors;

RobotLink::RobotLink(Robot* robot,
const urdf::LinkConstSharedPtr& link,
Expand Down Expand Up @@ -318,6 +319,26 @@ RobotLink::~RobotLink()
delete axes_;
delete details_;
delete link_property_;
errors.erase(this);
}

void RobotLink::addError(const char* format, ...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to this variadic function that could be simplified by using QString or QStringList

{
char buffer[256];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);

std::string& err = const_cast<std::string&>(getGeometryErrors());
if (!err.empty())
err.append("\n");
err.append(buffer);
}

const std::string& RobotLink::getGeometryErrors() const
{
return errors[this];
}

bool RobotLink::hasGeometry() const
Expand Down Expand Up @@ -595,22 +616,22 @@ void RobotLink::createEntityForGeometryElement(const urdf::LinkConstSharedPtr& l

scale = Ogre::Vector3(mesh.scale.x, mesh.scale.y, mesh.scale.z);

std::string model_name = mesh.filename;
const std::string& model_name = mesh.filename;

try
{
loadMeshFromResource(model_name);
entity = scene_manager_->createEntity(ss.str(), model_name);
if (loadMeshFromResource(model_name).isNull())
addError("Could not load mesh resource '%s'", model_name.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addError("Could not load mesh resource '%s'", model_name.c_str());
addError(QString("Could not load mesh resource '%1'").arg(model_name.c_str()));

or so, just a suggestion to keep things simple

else
entity = scene_manager_->createEntity(ss.str(), model_name);
}
catch (Ogre::InvalidParametersException& e)
{
ROS_ERROR("Could not convert mesh resource '%s' for link '%s'. It might be an empty mesh: %s",
model_name.c_str(), link->name.c_str(), e.what());
addError("Could not convert mesh resource '%s': %s", model_name.c_str(), e.what());
}
catch (Ogre::Exception& e)
{
ROS_ERROR("Could not load model '%s' for link '%s': %s", model_name.c_str(), link->name.c_str(),
e.what());
addError("Could not load model '%s': %s", model_name.c_str(), e.what());
}
break;
}
Expand Down Expand Up @@ -695,8 +716,8 @@ void RobotLink::createCollision(const urdf::LinkConstSharedPtr& link)
if (collision_mesh)
{
collision_meshes_.push_back(collision_mesh);
valid_collision_found = true;
}
valid_collision_found |= collision == link->collision; // don't consider the same geometry twice
}
}
#endif
Expand Down Expand Up @@ -755,8 +776,8 @@ void RobotLink::createVisual(const urdf::LinkConstSharedPtr& link)
if (visual_mesh)
{
visual_meshes_.push_back(visual_mesh);
valid_visual_found = true;
}
valid_visual_found |= visual == link->visual; // don't consider the same geometry again
}
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/robot/robot_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class RobotLink : public QObject
{
return robot_;
}
const std::string& getGeometryErrors() const;

// Remove link_property_ from its old parent and add to new_parent. If new_parent==NULL then leav
// unparented.
Expand Down Expand Up @@ -189,6 +190,7 @@ private Q_SLOTS:
const urdf::Pose& origin,
Ogre::SceneNode* scene_node,
Ogre::Entity*& entity);
void addError(const char* format, ...);

void createVisual(const urdf::LinkConstSharedPtr& link);
void createCollision(const urdf::LinkConstSharedPtr& link);
Expand Down