Group '' not found in model 'two_link_nonplanar'

asked 2019-07-09 11:54:57 -0500

Kolohe113 gravatar image

updated 2019-07-09 14:43:06 -0500

So I was trying to get a model group using getJointModelGroup from moveit. I was able to get the robot name by using kinematic_model->getName(), and the name is "two_link_nonplanar". However, when I try getJointModelGroup I got

Group '' not found in model 'two_link_nonplanar'

Here are part of my code: in robot.cpp

#include "robot.h"
#include <iostream>
#include <moveit_visual_tools/moveit_visual_tools.h>
#include <visualization_msgs/Marker.h>
#include <eigen_conversions/eigen_msg.h> 
Robot::Robot()
{

std::string robot_name;
robot_model_loader::RobotModelLoader robot_model_loader("robot_description");
robot_model::RobotModelPtr kinematic_model = robot_model_loader.getModel();
robot_state::RobotStatePtr kinematic_state(new robot_state::RobotState(kinematic_model));
kinematic_state->setToDefaultValues();
const robot_state::JointModelGroup* joint_model_group = kinematic_model->getJointModelGroup(robot_name);
// ... do things with joint_model_group
}

Void Robot::make_function(){
                //...
}

int main(int argc, char** argv)
{
 ros::init(argc, argv, "robot_model");
 ros::AsyncSpinner spinner(1);
spinner.start();
Robot bot1;
bot1.make_function();
 }

In my robot.h

#ifndef _ROBOT
#define _ROBOT

class Robot{
public:
    Robot();
    void make_function();
private:
    const robot_state::JointModelGroup* joint_model_group;
    robot_state::RobotStatePtr kinematic_state;
    robot_state::JointBoundsVector joint_bounds;
}; 
endif

Strange thing is, when I put everything under main, I was able to get a joint_model_group. I am not sure if this is a C++ question or a moveit question. My apology if this is entirely a C++ issue.

Edit1: Also, ROS_INFO_STREAM("JointGroup: \n" << kinematic_model->getJointModelGroup(robot_name) << "\n") gives me a value of 0. But when I put everything under main(), I got an address.

Edit2: When I change the contructor to :

Robot::Robot()
{    
std::string robot_name;
  if (!nh.getParam("robot_name", robot_name)) {
    ROS_ERROR("Failed to import parameter: robot_name.");
  }
robot_model_loader::RobotModelLoader robot_model_loader("robot_description");
robot_model::RobotModelPtr kinematic_model = robot_model_loader.getModel();
robot_state::RobotStatePtr kinematic_state(new robot_state::RobotState(kinematic_model));
kinematic_state->setToDefaultValues();
const robot_state::JointModelGroup* joint_model_group = kinematic_model->getJointModelGroup(robot_name);
// ... do things with joint_model_group
}

I was able to get a address for joint_model_group. However, I am getting a new warning saying:

SEVERE WARNING!!! Attempting to unload library while objects created by this loader exist in the heap! You should delete your objects before attempting to unload the library or destroying the ClassLoader. The library will NOT be unloaded.

And the same error exist: process has died

Edit3: I have fix the header so process has died went away and program run as expected, however, the SEVERE WARNING! in above still exist. Here are my fix:

Robot::Robot()
{

std::string robot_name;
robot_model_loader::RobotModelLoader robot_model_loader("robot_description");
kinematic_model = robot_model_loader.getModel();
//moved kinematic_state inside move_function()
 joint_model_group = kinematic_model->getJointModelGroup(robot_name);
// ... do things with joint_model_group
}
edit retag flag offensive close merge delete