Reputation: 83
I am trying to integrate drake as a physics simulator with in my code. My code does have ros2 as IPC, but the code itself is ROS agnostic. I am using colcon to build the code and I am using CMakeList with drake installed using apt on ubuntu 22.04.
I am trying to load the urdf in drake with in my class structure. I my header file, I defined the following parameters:
drake::systems::DiagramBuilder<double> builder_;
drake::multibody::MultibodyPlant<double>* plant_{};
drake::geometry::SceneGraph<double>* scene_graph_{};`
In my source file, my code is
std::tie(plant_, scene_graph_) = AddMultibodyPlantSceneGraph(&builder_, std::make_unique<MultibodyPlant<double>>(1e-3));
const std::string urdf = drake::FindResourceOrThrow("path_to_urdf/urdf.urdf");
drake::multibody::Parser(plant_).AddModelFromFile(urdf);
However, when I run the code, I get the following message
[****] terminate called after throwing an instance of 'std::runtime_error'
[***] what(): Drake resource_path '~/path_to_urdf/urdf.urdf' does not start with drake/.
I verified that file is available on the link. I tried creating the manual drake folder as well, but it keeps complaining.
I did saw the issue https://github.com/RobotLocomotion/drake-external-examples/issues/170 open but I am not sure if it is related to that. Any help or guidance will be highly appreciated.
Upvotes: 0
Views: 86
Reputation: 2449
In general, don't use FindResourceOrThrow
to load models. It's intended only for Drake build system resources.
To use AddModelFromFile
, just pass it an absolute path:
std::tie(plant_, scene_graph_) = ...
drake::multibody::Parser(plant_).AddModels("/full/path/to/myproject/urdf/foo.urdf");
You can also use ROS package paths, if you are using package.xml
files:
std::tie(plant_, scene_graph_) = ...
drake::multibody::Parser parser(plant_);
parser.package_map().PopulateFromRosPackagePath();
std::string package_dir = parser.package_map().GetPath("myproject");
parser.AddModels(package_dir + "/urdf/foo.urdf");
In the next version of Drake (v1.13.0), there will also be a AddModelsFromUrl
function to make ROS package paths even easier.
Upvotes: 0