Bird
Raised Fist0
ROSframework~20 mins

Collision avoidance in planning in ROS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Collision Avoidance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output behavior of this ROS node snippet for collision avoidance?
Consider a ROS node that subscribes to a laser scan topic and publishes velocity commands to avoid obstacles. What will the robot do when an obstacle is detected within 0.5 meters?
ROS
def scan_callback(data):
    min_distance = min(data.ranges)
    if min_distance < 0.5:
        cmd.linear.x = 0.0
        cmd.angular.z = 0.5
    else:
        cmd.linear.x = 0.5
        cmd.angular.z = 0.0
    pub.publish(cmd)
AThe robot stops moving forward and turns left slowly when an obstacle is closer than 0.5 meters.
BThe robot speeds up forward and turns right when an obstacle is detected within 0.5 meters.
CThe robot continues moving forward without turning regardless of obstacles.
DThe robot stops all movement immediately when any obstacle is detected.
Attempts:
2 left
💡 Hint
Think about how linear and angular velocities control robot movement.
📝 Syntax
intermediate
1:30remaining
Which option correctly initializes a ROS publisher for velocity commands in Python?
You want to publish velocity commands to the topic '/cmd_vel' using geometry_msgs/Twist messages. Which code snippet correctly creates the publisher?
Apub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
Bpub = rospy.Publisher('/cmd_vel', 'Twist', 10)
Cpub = rospy.Publisher('/cmd_vel', geometry_msgs.Twist, 10)
Dpub = rospy.Publisher('/cmd_vel', Twist(), queue_size=10)
Attempts:
2 left
💡 Hint
Check the correct way to specify message type and queue size in rospy.Publisher.
🔧 Debug
advanced
2:00remaining
What error does this ROS Python code raise when running?
Examine the code below that attempts to subscribe to a laser scan topic and print the minimum distance. Identify the error raised at runtime.
ROS
def callback(msg):
    print(min(msg.range))

rospy.Subscriber('/scan', LaserScan, callback)
rospy.spin()
ANo error, prints minimum distance correctly
BAttributeError: 'LaserScan' object has no attribute 'range'
CNameError: name 'LaserScan' is not defined
DTypeError: 'min' argument must be an iterable
Attempts:
2 left
💡 Hint
Check the attribute name for laser scan ranges in the message.
❓ state_output
advanced
1:30remaining
What is the value of 'avoidance_active' after this ROS node callback runs?
Given the following callback that sets a signal to True if an obstacle is detected within 1 meter, what is the value of 'avoidance_active' after receiving a LaserScan with ranges [1.2, 0.8, 1.5]?
ROS
avoidance_active = False

def scan_cb(msg):
    global avoidance_active
    if any(distance < 1.0 for distance in msg.ranges):
        avoidance_active = True
    else:
        avoidance_active = False

# Simulated call
class Msg:
    ranges = [1.2, 0.8, 1.5]
scan_cb(Msg())
ANone
BFalse
CTrue
DRaises an error
Attempts:
2 left
💡 Hint
Check if any value in the list is less than 1.0.
🧠 Conceptual
expert
2:30remaining
Which option best describes the role of the costmap in ROS navigation for collision avoidance?
In ROS navigation, the costmap is used to represent obstacles and free space around the robot. What is the primary purpose of the costmap in collision avoidance planning?
AIt manages communication between different ROS nodes.
BIt stores the robot's velocity commands to execute smooth turns.
CIt records sensor data history for offline analysis only.
DIt provides a grid-based map marking obstacles and safe zones to help the planner avoid collisions.
Attempts:
2 left
💡 Hint
Think about how the planner knows where obstacles are.

Practice

(1/5)
1. What is the main purpose of collision avoidance in ROS planning?
easy
A. To make the robot ignore obstacles and move freely
B. To prevent the robot from hitting obstacles while moving
C. To speed up the robot's movement regardless of obstacles
D. To stop the robot from moving at all

Solution

  1. Step 1: Understand collision avoidance goal

    Collision avoidance means the robot should not bump into objects while moving.
  2. Step 2: Identify correct purpose

    The main goal is to keep the robot safe by avoiding obstacles during planning.
  3. Final Answer:

    To prevent the robot from hitting obstacles while moving -> Option B
  4. Quick Check:

    Collision avoidance = prevent hitting obstacles [OK]
Hint: Collision avoidance means safety, not speed or stopping [OK]
Common Mistakes:
  • Thinking collision avoidance speeds up movement
  • Believing robot ignores obstacles
  • Assuming robot should stop moving
2. Which ROS component is used to add obstacles for collision avoidance during planning?
easy
A. Planning Scene
B. Move Group Interface
C. Robot State Publisher
D. Joint State Listener

Solution

  1. Step 1: Identify obstacle representation in ROS planning

    Obstacles are added to the planning scene to inform the planner about their presence.
  2. Step 2: Match component to function

    The Planning Scene holds information about obstacles and environment for collision checking.
  3. Final Answer:

    Planning Scene -> Option A
  4. Quick Check:

    Obstacles added via Planning Scene [OK]
Hint: Obstacles go into the Planning Scene, not robot state [OK]
Common Mistakes:
  • Confusing Move Group Interface with obstacle storage
  • Thinking Robot State Publisher manages obstacles
  • Assuming Joint State Listener adds obstacles
3. Given this ROS planning code snippet, what will happen if the planner finds no valid path?
move_group.setStartStateToCurrentState()
move_group.setPoseTarget(target_pose)
plan = move_group.plan()
if plan:
    move_group.execute(plan)
else:
    print("No valid path found")
medium
A. The robot moves to the target pose anyway
B. The robot moves to a random position
C. The robot prints "No valid path found" and does not move
D. The planner crashes with an error

Solution

  1. Step 1: Analyze the plan check condition

    The code checks if plan is valid (truthy). If not, it prints a message.
  2. Step 2: Understand behavior when no path found

    If no valid path, the else block runs, printing "No valid path found" and skipping execution.
  3. Final Answer:

    The robot prints "No valid path found" and does not move -> Option C
  4. Quick Check:

    No path means print message, no movement [OK]
Hint: Check plan validity before execute to avoid errors [OK]
Common Mistakes:
  • Assuming robot moves without a valid plan
  • Expecting a crash instead of safe handling
  • Thinking robot moves randomly
4. Identify the error in this ROS planning snippet that prevents collision avoidance:
planning_scene = PlanningSceneInterface()
obstacle = CollisionObject()
obstacle.id = "box"
obstacle.header.frame_id = "world"
# Missing shape and pose assignment here
planning_scene.addCollisionObjects([obstacle])
medium
A. The obstacle has no shape or pose defined
B. The planning scene is not initialized
C. The obstacle ID is missing
D. The frame_id should be "base_link"

Solution

  1. Step 1: Check obstacle definition

    The obstacle lacks shape and pose, so it has no physical presence.
  2. Step 2: Understand impact on collision avoidance

    Without shape and pose, the planner cannot detect or avoid the obstacle.
  3. Final Answer:

    The obstacle has no shape or pose defined -> Option A
  4. Quick Check:

    Obstacle needs shape and pose to exist [OK]
Hint: Always define shape and pose for obstacles [OK]
Common Mistakes:
  • Ignoring shape and pose assignment
  • Thinking frame_id must be base_link always
  • Assuming missing ID causes failure
5. You want to ensure your robot avoids a newly added obstacle during planning. Which sequence correctly updates the planning scene and checks for a valid path before moving?
hard
A. Only call plan() without adding obstacle
B. Call execute() first, then add obstacle, then plan()
C. Add obstacle, execute plan without checking validity
D. Add obstacle to Planning Scene, call plan(), check if plan valid, then execute plan

Solution

  1. Step 1: Add obstacle to Planning Scene

    Adding the obstacle updates the environment for collision checking.
  2. Step 2: Plan and check validity before execution

    Call plan() to find a path avoiding obstacles, then verify plan is valid before executing.
  3. Step 3: Avoid unsafe execution

    Executing without a valid plan or before adding obstacles risks collisions or errors.
  4. Final Answer:

    Add obstacle to Planning Scene, call plan(), check if plan valid, then execute plan -> Option D
  5. Quick Check:

    Update scene, plan, validate, then execute [OK]
Hint: Always add obstacles before planning and check plan validity [OK]
Common Mistakes:
  • Executing before planning
  • Not adding obstacles before planning
  • Skipping plan validity check
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard