0
$\begingroup$

Gazebo Answers logo

Hey guys,

I have a few questions, sorry if there are simple answers but I couldn't find them in any of the tutorials.

I am trying to create a simple walker with 8 joints to use with reinforcement learning algorithms, and so need to reset the model quickly after each episode.

The problem I am having is when I do a service call to reset the world and the model, the plugins need to restart (camera, imu, joint_states) and they take up to minutes to publish again (which is not ideal given the many episodes needed).

So instead I am trying to reset the model_state at the end of the episode back to its starting position. The problem with this is getting the joint positions back to 0.0. I am using the joint_position_controller/command as outlined in the tutorials but they obviously take some time to get back to these positions, and this time seems to be affected by gravity (even after turning up the PID values).

I thought that if I changed gravity to zero, reset the model_state, then I could send the joint commands, and then turn gravity back on.

My questions:

  • How do I reset gravity? Am I missing a gazebo_msg that I need to include in the service call? What I have so far:

from gazebo_msgs.srv import SetPhysicsProperties
set_gravity = rospy.ServiceProxy('/gazebo/set_physics_properties', SetPhysicsProperties)
set_physics = SetPhysicsProperties() # how do I set gravity? 
set_gravity(set_physics) # this call does not work (not expecting SetPhysicsProperties object)
  • Is there a better way of get the joints to go to a desired position? Currently I have to wait for the joints to reach their positions (determined by process_value_dot because some of the joints don't reach their positions when the robot has fallen over, I assume due to effort constraints):

for i in range(NUM_JOINTS):
    joints[i].publish(0.0)

data = None
while not rospy.is_shutdown():
try:
data = rospy.wait_for_message('/mybot/joint' + str(i) + '_position_controller/state', JointControllerState, timeout=1)
if abs(data.process_value_dot) < 0.01:
break
except:
pass
time.sleep(0.001)

  • This approach I am trying seems very convoluted for simply reseting the model without restarting the plugins. Is there a better way to reset the model quickly (keeping in mind the /gazebo/reset_simulation service call stops the plugins)?

Thanks for your time guys.


Originally posted by bt on Gazebo Answers with karma: 3 on 2017-09-01

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

I would like to complement the answer given by @bt.

Here you have the video that explains all the process: VideoAnswer

In this case I have created a python script (change_gravity.py) that generates a class that controlles gravity in Gazebo. It has a testing function that changes the gravity two various configurations sequentially to see the effect.

I use the different gazebo services to pause, unpause , reset and set the Gazebo Physiscs.

I have used a simple URDF difined object called simple_box.

Here you have all the main files necessary:

The Script that changes the gravity->change_gravity.py

Main that launches everything->main.launch

Launch to spawn the simple box->spawn_simple_box.launch

Launch to spawn a URDF model->spawn_robot_urdf.launch

Model of the simple box ->simple_box.urdf

The simple world with normal gravity simple.world

Hope this helps.


Originally posted by Duckfrost with karma: 209 on 2017-10-02

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by bt on 2017-10-02:
Thank you for in-depth video and response! I don't have enough rep to upvote

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.