Skip to content

Commit

Permalink
added group attribute to <sensor> tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Mar 17, 2016
1 parent 658b538 commit 8546aa0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions urdf_parser/include/urdf_parser/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@

namespace urdf {

/* attribute parsing is accomplished by boost::lexical_cast by default */
template <typename T>
T parseAttribute(const char* value)
{
return boost::lexical_cast<T>(value);
}

/** Check existence of an attribute called attr and parse its values as T.
* If there is no such attribute, return *default_value if not NULL.
* Otherwise throw a ParseError.
*/
template <typename T>
T parseAttribute(const TiXmlElement &tag, const char* attr, const T* default_value=NULL)
{
Expand Down
13 changes: 8 additions & 5 deletions urdf_parser/src/sensor_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "urdf_parser/sensor_parser.h"

#include "urdf_parser/pose.h"
#include "urdf_parser/utils.h"
#include <urdf_sensor/camera.h>
#include <urdf_sensor/ray.h>
#include <console_bridge/console.h>
Expand Down Expand Up @@ -84,13 +85,15 @@ bool parseSensor(Sensor &sensor, TiXmlElement* config, const SensorParserMap &pa
{
sensor.clear();

const char *name_char = config->Attribute("name");
if (!name_char)
{
CONSOLE_BRIDGE_logError("No name given for the sensor.");
try {
const std::string empty;
sensor.name_ = parseAttribute<std::string>(*config, "name");
sensor.group_ = parseAttribute<std::string>(*config, "group", &empty);
} catch (const std::exception &e) {
CONSOLE_BRIDGE_logError("Failed to parse sensor attributes: %s", e.what());
return false;
}
sensor.name_ = std::string(name_char);


// parse parent link name
TiXmlElement *parent_xml = config->FirstChildElement("parent");
Expand Down
4 changes: 2 additions & 2 deletions urdf_parser/test/basic.urdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<parent link="link1" />
<child link="link2" />
</joint>
<sensor name="camera1" update_rate="20">
<sensor name="camera1" group="head" update_rate="20">
<parent link="link1"/>
<origin xyz="0 0 0" rpy="0 0 0"/>
<camera>
<image width="640" height="480" hfov="1.5708" format="RGB8" near="0.01" far="50.0"/>
</camera>
</sensor>
<sensor name="ray1" update_rate="20">
<sensor name="ray1" group="head" update_rate="20">
<parent link="link1"/>
<origin xyz="0 0 0" rpy="0 0 0"/>
<ray>
Expand Down

0 comments on commit 8546aa0

Please sign in to comment.