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

reset robot location in rviz

asked 2017-10-31 11:23:41 -0500

SRD gravatar image

updated 2017-10-31 14:07:54 -0500

Normally when opening RViz, my robot starts at 0, 0, 0. Then I move it, and then I'd like to reset it back to 0, 0, 0 without closing and then reopening RViz and, I think, restarting ros core.

How does one reset the robot in RViz to start back at 0, 0, 0 while it's running?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-11-01 02:41:43 -0500

l4ncelot gravatar image

You can delete the model and respawn it. Have a look at how to spawn model here.

You can also use python script to do it for your. In gazebo_ros_pkgs package there is spawn_model python script that takes care of it (it's the same one used with roslaunch command).

You can spawn model using python like this:

from gazebo_msgs.srv import SpawnModel

def spawn():
    req = SpawnModelRequest()
    req.model_name = "model"
    req.model_xml = model_xml
    req.robot_namespace = "namespace"
    req.initial_pose.position.x = 0.0
    req.initial_pose.position.y = 0.0
    req.initial_pose.position.z = 0.0
    req.initial_pose.orientation.x = 0.0
    req.initial_pose.orientation.y = 0.0
    req.initial_pose.orientation.z = 0.0
    req.initial_pose.orientation.w = 1.0
    req.reference_frame = ''

    try:
        srv = ServiceProxy('/gazebo/spawn_sdf_model', SpawnModel)
        resp = srv(req)
    except ServiceException, e:
        print("   Service call failed: %s" % e)
        sys.exit(1)

    if resp.success:
        print(resp.status_message)
        return 0
    else:
        print(resp.status_message)
        return 1

Where model_xml is your urdf or sdf file.

Then you can delete models like this:

def delete():
    try:
        srv = ServiceProxy('/gazebo/delete_model', DeleteModel)
        req = DeleteModelRequest()
        req.model_name = "model"
        resp = srv(req)
    except ServiceException, e:
        print("Service call failed: %s" % e)
        sys.exit(2)

    if resp.success:
        print(resp.status_message)
        return 0
    else:
        print(resp.status_message)
        return 1

So if you want you can create your own python script which takes care of it. Using roslaunch command is fine as well, but you're limited sometimes.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-10-31 11:23:41 -0500

Seen: 1,385 times

Last updated: Nov 01 '17