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

Gazebo: disable physics or enable kinematics through code/command line

asked 2015-10-06 22:25:45 -0600

LevAva gravatar image

I know that Gazebo has its own answers page, but it doesn't seem to be up anymore so I thought I might try here.

I am trying to send model state information to gazebo for my robot, and control it using a teleop_twist_keyboard. The model state is sent and received fine, but then the robot starts rubberbanding around on the axis where I changed its position (I am sending absolute xyz/orientation, not velocity commands from the teleop keyboard). I noticed that if I either disable physics under the Physics tab on the gui, or set Models/MyRobot/link1/kinematic true, also through the gui, everything behaves much much better.

The problem is, I can't find a way to change either of those options through the command line or through ROS. The options are neither in the physics properties message nor the link properties message, and I haven't seen any other way to change them other than the gui.

Pausing and unpausing physics does not work, since that turns off the simulation timer altogether which means model state positions aren't updated, nor are laser scans. If I try to set my model to static, then my laser link stops updating rayscans, which is not helpful. Doing <kinematic>true</kinematic> on my .gazebo for the .urdf did nothing at all.

Is there a way to either disable physics (but keep the simulation running) or make my link/robot kinematic through command line arguments or through ROS service calls/messages? Preferably the disabling physics one, though, since it's running on a VM and disabling physics gives a massive speed boost.

ROS Version: Jade Gazebo Version: 5.0

edit retag flag offensive close merge delete

Comments

Create a WorldPlugin, like this


void Load(physics::WorldPtr _parent, sdf::ElementPtr _sdf)
{
       //disable physics
       _parent->SetPhysicsEnabled(false);
}

If you are using ModelPlugin, like this


void BuildingEdit::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
{
       _parent->GetWorld()->SetPhysicsEnabled(false);
}
Tony10012 gravatar image Tony10012  ( 2021-01-18 21:54:03 -0600 )edit

3 Answers

Sort by » oldest newest most voted
0

answered 2015-10-08 19:39:38 -0600

LevAva gravatar image

I have found a solution of sorts, instead of disabling physics directly I just set the solver iterations to 0 which has the same effect and can be done through messages. Of course this is the nuclear option, since this turns off all physics, not just for the link you want.

Here's a rosservice call to do it:

rosservice call /gazebo/set_physics_properties "
time_step: 0.001
max_update_rate: 1000.0
gravity:
  x: 0.0
  y: 0.0
  z: 0.0
ode_config:
  auto_disable_bodies: False
  sor_pgs_precon_iters: 0
  <!--SET THIS TO ZERO TO DISABLE PHYSICS-->
  sor_pgs_iters: 0
  sor_pgs_w: 1.3
  sor_pgs_rms_error_tol: 0.0
  contact_surface_layer: 0.001
  contact_max_correcting_vel: 100.0
  cfm: 0.0
  erp: 0.2
  max_contacts: 20"
edit flag offensive delete link more
2

answered 2016-12-08 03:28:27 -0600

mnschulz gravatar image

This might be an old thread but I haven't seen a direct answer. I solved it by defining a world plugin that exposes the WorldPtr (see Gazebo World Class Reference) in the Load function and disabling the Physics Engine in the on_update method:

void DisablePlugin::Load(gazebo::physics::WorldPtr ptr, sdf::ElementPtr sdf) {
    _world = ptr;
    _update_connection = gazebo::event::Events::ConnectWorldUpdateBegin(
            boost::bind(&DisablePlugin::on_update, this, _1));
} 
void DisablePlugin::on_update(const gazebo::common::UpdateInfo& /*info*/) {
    if (_world->GetEnablePhysicsEngine())
        _world->EnablePhysicsEngine(false);
}

You can then set the pose of a model for example by using the SetLinkWorldPose method.

edit flag offensive delete link more

Comments

To extend on your answer, you do not need to disable it on the on_update method, on the Load is OK, otherwise you are executing this every iteration.

Javier V. Gómez gravatar image Javier V. Gómez  ( 2016-12-14 11:52:12 -0600 )edit

You are not executing it at every iteration, as it is only executed if the Physics Engine is enabled. Having the disable in the on_update ensures that no iteration will be done with the Phyiscs Engine enabled as you have no guarantee on the order of the Load Method. It depends on the logic you want.

mnschulz gravatar image mnschulz  ( 2016-12-15 02:47:28 -0600 )edit
1

Thanks, this seems like an ok solution. However it would be nice to just start the simulator without any physics engine.

reinzor gravatar image reinzor  ( 2017-01-27 04:53:13 -0600 )edit
0

answered 2023-02-10 09:52:50 -0600

Divelix gravatar image

It is really weird that there is no way in gazebo to disable physics gracefully on startup, so people need to find various workarounds to do that. I also found another nasty hack to disable physics (inspired by this answer) and want to share it here.

Disable physics through world SDF: set ode solver iterations to 0.

Example empty.world with disabled physics:

<?xml version="1.0" ?>
<sdf version="1.5">
    <world name="default">
        <gravity>0 0 0</gravity>
        <physics type="ode">
            <max_step_size>0.001</max_step_size>
            <real_time_factor>1</real_time_factor>
            <real_time_update_rate>1000</real_time_update_rate>
            <ode>
                <solver>
                    <type>quick</type>
                    <iters>0</iters> <!-- 0 iterations to stop physics -->
                    <sor>1.4</sor>
                </solver>
                <constraints>
                    <cfm>0</cfm>
                    <erp>1</erp>
                    <contact_max_correcting_vel>0</contact_max_correcting_vel>
                    <contact_surface_layer>0</contact_surface_layer>
                </constraints>
            </ode>
        </physics>

        <!-- A global light source -->
        <include>
            <uri>model://sun</uri>
        </include>
        <!-- A ground plane -->
        <include>
            <uri>model://ground_plane</uri>
        </include>
    </world>
</sdf>
edit flag offensive delete link more

Question Tools

Stats

Asked: 2015-10-06 22:25:45 -0600

Seen: 7,158 times

Last updated: Feb 10 '23