Problem with MoveGroupInterface::getRobotModel() providing only const version [closed]
I'm trying to get my own instance of JointModelGroup from code equivalent to this:
auto move_group = moveit::planning_interface::MoveGroupInterface {"panda_arm"};
auto robot_model_constptr = move_group.getRobotModel();
auto joint_model_group = std::unique_ptr<moveit::core::JointModelGroup> {robot_model_constptr->getJointModelGroup("panda_arm")};
However this doesn't compile (long error omitted for brevity):
error: no matching function for call to ‘std::unique_ptr<moveit::core::JointModelGroup>::unique_ptr(<brace-enclosed initializer list>)’
auto joint_model_group = std::unique_ptr<moveit::core::JointModelGroup> {robot_model_constptr->getJointModelGroup("panda_arm")};
which ultimately boils down to
error: invalid conversion from ‘const moveit::core::JointModelGroup*’ to ‘std::unique_ptr<moveit::core::JointModelGroup>::pointer {aka moveit::core::JointModelGroup*}’ [-fpermissive]
auto joint_model_group = std::unique_ptr<moveit::core::JointModelGroup> {robot_model_constptr->getJointModelGroup("panda_arm")};
This stems apparently from getRobotModel
either being a const function or returning a ConstPtr (likely the first), as that leads to calling the const version of getJointModelGroup
(instead of the existing non-const) which makes it impossible to get the unique_ptr.
I have found however that this does compile:
auto move_group = moveit::planning_interface::MoveGroupInterface {"panda_arm"};
auto robot_model_constptr = move_group.getRobotModel();
auto robot_model = * robot_model_constptr;
auto joint_model_group = std::unique_ptr<moveit::core::JointModelGroup> {robot_model.getJointModelGroup("panda_arm")};
and I'm therefore left wondering if I'm doing something I shouldn't or if there is a better way to get joint_model_group without declaring things I don't necessarily need myself.
EDIT: from what I can gather e.g. here I get the const version of getJointModelGroup
because getRobotModel
is const, is what I'm trying to say.