Bird
Raised Fist0
ROSframework~20 mins

Gazebo physics and collision in ROS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Gazebo Physics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when two Gazebo models collide with default physics settings?

Consider two models in Gazebo with default physics parameters. What is the expected behavior when they collide?

AThey merge into a single model upon contact.
BThey pass through each other without any interaction.
CThey bounce off each other based on their mass and friction properties.
DThey stop moving immediately and remain stuck together.
Attempts:
2 left
💡 Hint

Think about how physics engines handle collisions with mass and friction.

📝 Syntax
intermediate
2:00remaining
Which SDF snippet correctly defines a collision element with a box shape?

Identify the correct SDF XML snippet that defines a collision element with a box shape of size 1 2 3 meters.

A<collision name="col"><geometry><box><size>1 2 3</size></box></geometry></collision>
B<collision><geometry><box size="1 2 3"/></geometry></collision>
C<collision name="col"><box><geometry><size>1 2 3</size></geometry></box></collision>
D<collision name="col"><geometry><box><dimensions>1 2 3</dimensions></box></geometry></collision>
Attempts:
2 left
💡 Hint

Remember the SDF structure for geometry inside collision.

🔧 Debug
advanced
2:00remaining
Why does this Gazebo plugin fail to detect collisions?

Given the following plugin snippet, why does it not detect collisions as expected?

void MyPlugin::OnUpdate() {
  if (this->model->GetWorld()->Physics()->GetContactCount() > 0) {
    std::cout << "Collision detected!" << std::endl;
  }
}
ROS
void MyPlugin::OnUpdate() {
  if (this->model->GetWorld()->Physics()->GetContactCount() > 0) {
    std::cout << "Collision detected!" << std::endl;
  }
}
ACollision detection requires enabling the contact sensor in the SDF, which is missing.
BGetContactCount() is deprecated and returns always zero.
CThe OnUpdate function is never called because the plugin is not loaded.
DThe plugin does not subscribe to contact sensor updates, so contact count remains zero.
Attempts:
2 left
💡 Hint

Check if contact sensors are enabled in the model description.

state_output
advanced
2:00remaining
What is the effect of setting friction coefficients to zero on a Gazebo model's collision behavior?

If a model's collision surface friction coefficients (mu and mu2) are set to zero, what will happen when it slides on another surface?

AThe model will bounce off the surface with high energy loss.
BThe model will slide indefinitely without slowing down.
CThe model will stick to the surface and not move.
DThe model will behave normally with some friction.
Attempts:
2 left
💡 Hint

Think about what friction does in real life.

🧠 Conceptual
expert
2:00remaining
How does Gazebo handle collision filtering to optimize physics calculations?

Gazebo uses collision filtering to avoid unnecessary collision checks. Which method does it primarily use?

AIt merges all collision shapes into one to reduce checks.
BIt disables collisions for all static models automatically.
CIt performs collision checks only for models within a fixed radius of the camera.
DIt uses collision bitmasks to selectively enable or disable collisions between groups of objects.
Attempts:
2 left
💡 Hint

Consider how groups and masks help in filtering collisions.

Practice

(1/5)
1. What is the main purpose of physics in Gazebo simulations?
easy
A. To define the color and texture of objects
B. To control how objects move and react to forces like gravity
C. To create user interfaces for robot control
D. To store sensor data from the robot

Solution

  1. Step 1: Understand the role of physics in Gazebo

    Physics in Gazebo simulates real-world forces like gravity and friction affecting objects.
  2. Step 2: Identify the correct purpose

    Physics controls object movement and reactions, not appearance or data storage.
  3. Final Answer:

    To control how objects move and react to forces like gravity -> Option B
  4. Quick Check:

    Physics = object movement and forces [OK]
Hint: Physics = movement and forces, not visuals or data [OK]
Common Mistakes:
  • Confusing physics with visual appearance
  • Thinking physics stores sensor data
  • Assuming physics creates user interfaces
2. Which of the following is the correct way to define a collision shape in a Gazebo SDF file?
easy
A. 1 1 1
B. red
C. camera
D. metal

Solution

  1. Step 1: Review SDF collision shape syntax

    Collision shapes use <geometry> tags with shape types like <box>, <sphere>, or <cylinder>.
  2. Step 2: Identify the valid collision definition

    <collision><geometry><box><size>1 1 1</size></box></geometry></collision> correctly defines a box size inside geometry within collision tags.
  3. Final Answer:

    <collision><geometry><box><size>1 1 1</size></box></geometry></collision> -> Option A
  4. Quick Check:

    Collision shape = geometry + shape tags [OK]
Hint: Collision needs geometry and shape tags, not color or sensor [OK]
Common Mistakes:
  • Using color or material tags inside collision
  • Confusing sensors with collision shapes
  • Omitting geometry tag inside collision
3. Given this SDF snippet, what will happen when the robot collides with the box?
<collision name="box_collision">
  <geometry>
    <box><size>1 1 1</size></box>
  </geometry>
</collision>
medium
A. The box will change color on collision
B. The robot will pass through the box without any effect
C. The simulation will crash due to missing physics
D. The robot will detect collision and stop or react physically

Solution

  1. Step 1: Understand collision shape effect

    The collision shape defines where objects physically interact and block each other.
  2. Step 2: Predict behavior on collision

    When the robot hits the box collision shape, physics will cause it to stop or react realistically.
  3. Final Answer:

    The robot will detect collision and stop or react physically -> Option D
  4. Quick Check:

    Collision shape causes physical interaction [OK]
Hint: Collision shapes cause physical blocking, not visual changes [OK]
Common Mistakes:
  • Thinking collision changes color
  • Assuming robot passes through objects with collision
  • Believing simulation crashes without physics tag
4. You wrote this collision tag in your Gazebo model but the robot passes through the object. What is the likely error?
<collision>
  <geometry>
    <sphere><radius>0.5</radius></sphere>
  </geometry>
</collision>
medium
A. The physics engine is not enabled or configured properly
B. The collision tag is missing a name attribute
C. The sphere radius is too small to detect collision
D. The geometry tag should be outside the collision tag

Solution

  1. Step 1: Check collision tag correctness

    The collision tag syntax is correct and includes geometry with a sphere shape.
  2. Step 2: Identify common cause of passing through objects

    If physics is disabled or misconfigured, collisions won't be processed, causing objects to pass through.
  3. Final Answer:

    The physics engine is not enabled or configured properly -> Option A
  4. Quick Check:

    Physics engine must be active for collisions [OK]
Hint: Collision needs physics engine enabled to work [OK]
Common Mistakes:
  • Thinking missing name attribute breaks collision
  • Assuming small radius disables collision
  • Placing geometry outside collision tag
5. You want to simulate a robot pushing a box realistically in Gazebo. Which combination of settings is best to achieve this?
hard
A. Only define visual shapes and manually move the box in code
B. Disable physics engine, use only visual shapes for robot and box
C. Enable physics engine with friction, define collision shapes for both robot and box
D. Use collision shapes but set friction to zero in physics settings

Solution

  1. Step 1: Understand realistic pushing requires physics and collision

    Physics engine simulates forces like friction and collision shapes define contact areas.
  2. Step 2: Evaluate options for realistic interaction

    Enable physics engine with friction, define collision shapes for both robot and box enables physics with friction and collision shapes, allowing realistic pushing behavior.
  3. Step 3: Reject options disabling physics or friction

    Disabling physics or friction or using only visuals prevents realistic physical interaction.
  4. Final Answer:

    Enable physics engine with friction, define collision shapes for both robot and box -> Option C
  5. Quick Check:

    Physics + friction + collision = realistic pushing [OK]
Hint: Physics + friction + collision shapes = realistic object interaction [OK]
Common Mistakes:
  • Disabling physics engine expecting realistic forces
  • Setting friction to zero for pushing
  • Using only visual shapes without collision