Ask Your Question
0

Reset model poses in a python script

asked 2017-07-20 09:51:10 -0500

kchledowski gravatar image

Hi!

I wrote a script with a for loop, where inside I navigate a robot and save the camera output/trajectories.

At the end of the loop I would like to reset the poses of the model, but unfortunately trying

self.reset = rospy.Publisher("gazebo/reset_models", Empty, queue_size=10) self.reset.publish(Empty())

does not work. Do you have an idea on what might work there? Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2017-07-21 01:27:01 -0500

gvdhoorn gravatar image

updated 2017-07-24 11:02:18 -0500

Isn't /gazebo/reset_models a service, not a topic?


I am sorry, could you please help me by telling what should I type into my for loop in order to get the model poses reset?

I don't know about "get model poses reset", but for invoking the /gazebo/reset_simulation service, the following should work:

import rospy
from std_srvs.srv import Empty

# maybe do some 'wait for service' here
reset_simulation = rospy.ServiceProxy('/gazebo/reset_simulation', Empty)

# invoke
reset_simulation()

See also the Writing a Simple Service and Client (Python) tutorial, specifically the Writing the Client Node section.

edit flag offensive delete link more

Comments

You are right, thanks for pointing this out :)

Unfortunately, I still didn't manage to reset the world inside my script. I tried to do the following: self.reset = rospy.Service('gazebo/reset_simulation', Empty); self.reset(Empty)

However, rosservice call /gazebo/reset_world "{}" works fine.

kchledowski gravatar imagekchledowski ( 2017-07-21 05:09:07 -0500 )edit

I think you'll need to add the / prefix, otherwise you're specifying a relative name.

gvdhoorn gravatar imagegvdhoorn ( 2017-07-21 05:24:04 -0500 )edit

Thanks, but unfortunately, it does not work. I have tried self.reset = rospy.Service('reset', "/gazebo/reset_simulation", Empty), but I get AttributeError: 'str' object has no attribute '_request_class'

kchledowski gravatar imagekchledowski ( 2017-07-21 05:42:40 -0500 )edit

I can find /gazebo/reset_simulation in the rosservice list, but when I go to the folder gazebo_msgs.srv, there is no reset_simulation.srv :( any idea on what can I do to import this service?

kchledowski gravatar imagekchledowski ( 2017-07-21 06:16:46 -0500 )edit

Moreover, I could not find any file "reset_simulation" on my computer.

kchledowski gravatar imagekchledowski ( 2017-07-21 06:29:46 -0500 )edit
1

I'm not sure what you are trying to do. rospy.Service('reset', "/gazebo/reset_simulation", Empty) that is not how you should initialise any service object, neither server nor client.

gvdhoorn gravatar imagegvdhoorn ( 2017-07-21 06:44:20 -0500 )edit
1

I could not find any file "reset_simulation" on my computer.

Where are you expecting to find it? The service is of type Empty apparently, so you'd have to look for Empty.srv, which is in std_srvs.

gvdhoorn gravatar imagegvdhoorn ( 2017-07-21 06:45:22 -0500 )edit

I am sorry, could you please help me by telling what should I type into my for loop in order to get the model poses reset?

kchledowski gravatar imagekchledowski ( 2017-07-21 06:46:41 -0500 )edit
1

answered 2017-07-24 06:19:10 -0500

Alberto E. gravatar image

updated 2017-07-24 11:13:48 -0500

Hello!

I've created this very short Video that shows exactly how to do this. Maybe by watching how to do it step by step it's easier to understand. Hope it helps!

EDIT: In the Video, I just show an example of how to implement a solution to the question. It might be helpful for someone to visualize step by step how it can be done. Code used:

#! /usr/bin/env python

import rospy
from std_srvs.srv import Empty

rospy.init_node('reset_world')

rospy.wait_for_service('/gazebo/reset_world')
reset_world = rospy.ServiceProxy('/gazebo/reset_world', Empty)

reset_world()
edit flag offensive delete link more

Comments

Although I have already done that, I think it might help other people with the same problem. Thanks for your contribution, Alberto! :)

kchledowski gravatar imagekchledowski ( 2017-07-24 06:27:19 -0500 )edit
1

Whenever referring to a video, please include a short description of what it shows. In case the video ever disappears, your answer basically becomes useless.

gvdhoorn gravatar imagegvdhoorn ( 2017-07-24 06:40:34 -0500 )edit
1

Well, basically I've implemented a solution to the question

so that is basically what I already had in my answer, right?

gvdhoorn gravatar imagegvdhoorn ( 2017-07-24 11:01:53 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-07-20 09:51:10 -0500

Seen: 1,361 times

Last updated: Jul 24 '17