ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Spawning Objects in RVIZ

asked 2012-11-06 09:45:38 -0500

ncr7 gravatar image

updated 2012-11-06 19:53:15 -0500

Eric Perko gravatar image

Is there a simple way to place objects in RVIZ? I am just trying to use the position of a detected object in a point cloud and spawn an object in that pose. But so far I haven't found a way to even spawn simple objects... Sphere, Cylinder, Box. Do I have to create a URDF file/launch file for this?

I have seen this Tutorial. But I get no such file or directory...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-11-06 22:19:24 -0500

Lorenz gravatar image

The simplest way to visualize objects in rviz are markers. Have a look at this and this tutorial. This page will give you an overview of the currently supported marker types.

edit flag offensive delete link more
3

answered 2012-11-06 19:02:15 -0500

updated 2012-11-06 19:06:47 -0500

the tutorial you mentioned almost works except some minor changes.

try the following code:

#include <ros/ros.h>
#include <planning_environment/models/collision_models.h>
#include <arm_navigation_msgs/PlanningScene.h>
#include <arm_navigation_msgs/GetPlanningScene.h>
#include <geometric_shapes/shape_operations.h>
#include <planning_environment/util/construct_object.h>

static const std::string SET_PLANNING_SCENE_DIFF_NAME = "/environment_server/set_planning_scene_diff";

class PlanningSceneTest
{
public:
    PlanningSceneTest()
    {
        collision_object_pub_  = nh_.advertise<arm_navigation_msgs::CollisionObject>("collision_object", 10);
        cm_ = new planning_environment::CollisionModels("robot_description");
        kinematic_state_ = new planning_models::KinematicState(cm_->getKinematicModel());
        kinematic_state_->setKinematicStateToDefault();
        while(!ros::service::waitForService(SET_PLANNING_SCENE_DIFF_NAME, ros::Duration(1.0)))
        {
          ROS_INFO_STREAM("Waiting for set_planning_scene_diff service " << SET_PLANNING_SCENE_DIFF_NAME);
        }
        get_planning_scene_client_ = nh_.serviceClient<arm_navigation_msgs::GetPlanningScene> (SET_PLANNING_SCENE_DIFF_NAME);
    }
    ~PlanningSceneTest()
    {

    }

    bool getPlanningScene()
    {
        arm_navigation_msgs::CollisionObject collision_objects;
        collision_objects.operation.operation = arm_navigation_msgs::CollisionObjectOperation::ADD;
        collision_objects.header.stamp = ros::Time::now();
        collision_objects.header.frame_id = "/" + cm_->getWorldFrameId();
        collision_objects.id = "testObj";

        geometry_msgs::Pose cylinderPose;
        cylinderPose.position.x = 0.4;
        cylinderPose.position.y = 0.4;
        cylinderPose.position.z = 0.95;//0.93
        cylinderPose.orientation.x = 0;
        cylinderPose.orientation.y = 0;
        cylinderPose.orientation.z = 0;
        cylinderPose.orientation.w = 1;
        arm_navigation_msgs::Shape cylinder_shape;
        cylinder_shape.type = arm_navigation_msgs::Shape::CYLINDER;
        cylinder_shape.dimensions.resize(2);
        cylinder_shape.dimensions[0] = 0.028;//radius
        cylinder_shape.dimensions[1] = 0.12;//height
        collision_objects.shapes.push_back(cylinder_shape);
        collision_objects.poses.push_back(cylinderPose);

        collision_object_pub_.publish(collision_objects);

        //must call the set_planning_scene_diff service to notify other nodes
        if(kinematic_state_ != NULL)
        {
          ROS_INFO("Reverting planning scene to default.");
          cm_->revertPlanningScene(kinematic_state_);
          kinematic_state_ = NULL;
        }
        arm_navigation_msgs::GetPlanningScene::Request planning_scene_req;
        arm_navigation_msgs::GetPlanningScene::Response planning_scene_res;
        if(!get_planning_scene_client_.call(planning_scene_req, planning_scene_res)) {
            ROS_ERROR("Can't get planning scene");
            return false;
        }
        kinematic_state_ = cm_->setPlanningScene(planning_scene_res.planning_scene);
        if(kinematic_state_ == NULL)
        {
          ROS_ERROR("Something wrong with planning scene");
          return false;
        }

        return true;
    }

    ros::NodeHandle nh_;
    ros::ServiceClient get_planning_scene_client_;
    ros::Publisher collision_object_pub_;

    planning_environment::CollisionModels* cm_;
    planning_models::KinematicState* kinematic_state_;

};

int main(int argc, char** argv)
{
    ros::init(argc, argv, "CollisionObjectPub", ros::init_options::NoSigintHandler);

    PlanningSceneTest* pTest = new PlanningSceneTest();
    ros::Duration(5.0).sleep();//must sleep, otherwise the published info may get lost

    pTest->getPlanningScene();
    ros::waitForShutdown();
    return 0;
}

in rviz, you need to add display type "Marker", and subscribe to the topic "/planning_scene_markers"

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-06 09:45:38 -0500

Seen: 3,733 times

Last updated: Nov 06 '12