ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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

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 = ''

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

    if resp.success:
        return 0
        return 1

Where model_xml is your urdf or sdf file.

Then you can delete models like this:

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

    if resp.success:
        return 0
        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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 1,072 times

Last updated: Nov 01 '17