GetElement from sdf of type std::vector<double>
I want to declare a vector of double in my gazebo.xacro file and then get the element from that file to my script.
The way I do it for, say int
type is (eg cameraWidth)
<gazebo>
<plugin name="simulate_bounding_boxes" filename="libgazebo_simulate_bounding_boxes.so">
<targetFrame>zed_right_camera_optical_frame</targetFrame>
<sourceFrame>base_footprint</sourceFrame>
<cameraInfo>zed/right/camera_info</cameraInfo>
<cameraWidth>1280</cameraWidth>
<cameraHeight>720</cameraHeight>
<simulateBoundingBoxesTopicName>simulate_bounding_boxes</simulateBoundingBoxesTopicName>
<customCameraInfo>custom_camera_info</customCameraInfo>
<D>0.0 0.0 0.0 0.0 0.0</D>
</plugin>
</gazebo>
In my plugin script;
this->width = getIntParameter(_sdf, "width", 1280, "Width of camera");
...
...
int GazeboSimulateBoundingBoxes::getIntParameter(sdf::ElementPtr _sdf, const char *element,
int default_value,
const char *default_description) {
if (!_sdf->HasElement(element)) {
RCLCPP_DEBUG(this->rosnode_->get_logger(),
"state_ground_truth plugin missing <%s>, defaults to %s", element,
default_description);
return default_value;
} else {
return _sdf->GetElement(element)->Get<int>();
}
}
But how do I do this for a std::vector<double> type? I tried to do the following. I include my vector of doubles in the plugin parameter
<vector>0.0 0.0 0.0 0.0 0.0</vector>
Then, I create a function for it where;
std::vector<double> GazeboSimulateBoundingBoxes::getVectorParameter(sdf::ElementPtr _sdf, const char *element,
std::vector<double> default_value,
const char *default_description) {
if (!_sdf->HasElement(element)) {
RCLCPP_DEBUG(this->rosnode_->get_logger(),
"state_ground_truth plugin missing <%s>, defaults to %s", element,
default_description);
return default_value;
} else {
return _sdf->GetElement(element)->Get<std::vector<double> >();
}
}
but I am getting this error;
/usr/include/sdformat-9.7/sdf/Param.hh: In instantiation of ‘bool sdf::v9::Param::Get(T&) const [with T = std::vector<double, std::allocator<double> >]’:
/usr/include/sdformat-9.7/sdf/Element.hh:620:7: required from ‘std::pair<T, bool> sdf::v9::Element::Get(const string&, const T&) const [with T = std::vector<double, std::allocator<double> >; std::string = std::__cxx11::basic_string<char>]’
/usr/include/sdformat-9.7/sdf/Element.hh:595:24: required from ‘T sdf::v9::Element::Get(const string&) const [with T = std::vector<double, std::allocator<double> >; std::string = std::__cxx11::basic_string<char>]’
/home/shenowlshoot/eufs-master/src/eufs_sim/eufs_plugins/gazebo_simulate_bounding_boxes/src/gazebo_simulate_bounding_boxes.cpp:295:63: required from here
/usr/include/sdformat-9.7/sdf/Param.hh:388:13: error: no match for ‘operator>>’ (operand types are ‘std::stringstream’ {aka ‘std::__cxx11::basic_stringstream<char>’} and ‘std::vector<double, std::allocator<double> >’)
388 | tmp >> _value;
| ~~~~^~~~~~~~~
The error is even longer than this, but I believe this is the most important one.