📖 Scenario: You are programming a robot that moves in a room. The robot must plan its path without hitting obstacles.
🎯 Goal: Build a simple ROS node that plans a path avoiding collisions with obstacles using a list of obstacle coordinates.
📋 What You'll Learn
Create a list of obstacle positions as tuples
Define a safe distance threshold variable
Write a function to check if a point is too close to any obstacle
Publish a planned path that avoids obstacles
💡 Why This Matters
🌍 Real World
Robots need to plan paths that avoid bumping into things to move safely in homes, factories, or warehouses.
💼 Career
Collision avoidance is a key skill for robotics engineers and developers working on autonomous systems.
Progress0 / 4 steps
1
Create obstacle data
Create a list called obstacles with these exact tuples representing obstacle positions: (2, 3), (5, 5), and (7, 2).
ROS
Hint
Use a Python list with tuples for each obstacle position.
2
Set safe distance threshold
Create a variable called safe_distance and set it to 1.5 to represent the minimum distance the robot must keep from obstacles.
ROS
Hint
Use a simple float variable for the safe distance.
3
Write collision check function
Write a function called is_collision_free that takes a point (x, y) and returns True if the point is at least safe_distance away from all obstacles in obstacles, otherwise returns False. Use Euclidean distance calculation.
ROS
Hint
Loop over obstacles and calculate distance to each. Return False if too close.
4
Publish safe path points
Create a list called planned_path with points (1,1), (3,3), (6,4), and (8,2). Then filter this list to keep only points where is_collision_free returns True. Assign the filtered list back to planned_path.
ROS
Hint
Use a list comprehension to filter points with the collision check function.
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
Step 1: Understand collision avoidance goal
Collision avoidance means the robot should not bump into objects while moving.
Step 2: Identify correct purpose
The main goal is to keep the robot safe by avoiding obstacles during planning.
Final Answer:
To prevent the robot from hitting obstacles while moving -> Option B
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
Step 1: Identify obstacle representation in ROS planning
Obstacles are added to the planning scene to inform the planner about their presence.
Step 2: Match component to function
The Planning Scene holds information about obstacles and environment for collision checking.
Final Answer:
Planning Scene -> Option A
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
Step 1: Analyze the plan check condition
The code checks if plan is valid (truthy). If not, it prints a message.
Step 2: Understand behavior when no path found
If no valid path, the else block runs, printing "No valid path found" and skipping execution.
Final Answer:
The robot prints "No valid path found" and does not move -> Option C
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
Step 1: Check obstacle definition
The obstacle lacks shape and pose, so it has no physical presence.
Step 2: Understand impact on collision avoidance
Without shape and pose, the planner cannot detect or avoid the obstacle.
Final Answer:
The obstacle has no shape or pose defined -> Option A
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
Step 1: Add obstacle to Planning Scene
Adding the obstacle updates the environment for collision checking.
Step 2: Plan and check validity before execution
Call plan() to find a path avoiding obstacles, then verify plan is valid before executing.
Step 3: Avoid unsafe execution
Executing without a valid plan or before adding obstacles risks collisions or errors.
Final Answer:
Add obstacle to Planning Scene, call plan(), check if plan valid, then execute plan -> Option D
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 unknownstrongwhile earning +1 Grip toward your certificate.