Skip to content

Commit 3864f63

Browse files
committed
added group attribute to <sensor> tag
1 parent 04d088a commit 3864f63

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

urdf_parser/include/urdf_parser/utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
namespace urdf {
4343

44+
/* attribute parsing is accomplished by boost::lexical_cast by default */
4445
template <typename T>
4546
T parseAttribute(const char* value);
4647

@@ -62,6 +63,10 @@ inline unsigned int parseAttribute<unsigned int>(const char* value)
6263
return std::stoul(value);
6364
}
6465

66+
/** Check existence of an attribute called attr and parse its values as T.
67+
* If there is no such attribute, return *default_value if not NULL.
68+
* Otherwise throw a ParseError.
69+
*/
6570
template <typename T>
6671
T parseAttribute(const TiXmlElement &tag, const char* attr, const T* default_value=NULL)
6772
{

urdf_parser/src/sensor_parser.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "urdf_parser/sensor_parser.h"
3939

4040
#include "urdf_parser/pose.h"
41+
#include "urdf_parser/utils.h"
4142
#include <urdf_sensor/camera.h>
4243
#include <urdf_sensor/ray.h>
4344
#include <console_bridge/console.h>
@@ -84,13 +85,15 @@ bool parseSensor(Sensor &sensor, TiXmlElement* config, const SensorParserMap &pa
8485
{
8586
sensor.clear();
8687

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

9598
// parse parent link name
9699
TiXmlElement *parent_xml = config->FirstChildElement("parent");

urdf_parser/test/basic.urdf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<parent link="link1" />
77
<child link="link2" />
88
</joint>
9-
<sensor name="camera1" update_rate="20">
9+
<sensor name="camera1" group="head" update_rate="20">
1010
<parent link="link1"/>
1111
<origin xyz="0 0 0" rpy="0 0 0"/>
1212
<camera>
1313
<image width="640" height="480" hfov="1.5708" format="RGB8" near="0.01" far="50.0"/>
1414
</camera>
1515
</sensor>
16-
<sensor name="ray1" update_rate="20">
16+
<sensor name="ray1" group="head" update_rate="20">
1717
<parent link="link1"/>
1818
<origin xyz="0 0 0" rpy="0 0 0"/>
1919
<ray>

0 commit comments

Comments
 (0)