LoopSense is a ROS2 patrol node that:
- moves a mobile robot forward,
- avoids nearby obstacles using
LaserScan, - tracks patrol loops using odometry (distance from start point).
This package was developed in The Construct ROS2 environment and can also run locally on a ROS2 machine with simulator or real robot.
Required files:
robot_patrol/patrol.py(main node logic)launch/start_patrolling.launch.py(launch entry point)package.xml,setup.py,setup.cfg,resource/robot_patrol
Included for quality checks:
test/linters
Ignored by default:
build/,install/,log/, Python cachesLoopSense DOC.pdf(kept local as optional report file)
The node expects:
- Subscribe:
/scan(sensor_msgs/msg/LaserScan) - Subscribe:
/odom(nav_msgs/msg/Odometry) - Publish:
/cmd_vel(geometry_msgs/msg/Twist)
- ROS2 (tested workflow: Humble)
- Python 3
- A robot/simulator that provides
/scanand/odom, and accepts/cmd_vel
Install common dependencies (Ubuntu):
sudo apt update
sudo apt install -y python3-colcon-common-extensions python3-rosdepIf first time using rosdep:
sudo rosdep init
rosdep update- Open your ROS2 workspace terminal.
- Put this repository inside
~/ros2_ws/src. - Build and run:
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -y
colcon build --packages-select robot_patrol
source install/setup.bash
ros2 launch robot_patrol start_patrolling.launch.py- Create workspace and clone:
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone https://github.com/mak4x13/LoopSense.git- Install dependencies, build, source:
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -y
colcon build --packages-select robot_patrol
source install/setup.bash- Start your robot/simulator (must provide
/scanand/odom), then run:
ros2 launch robot_patrol start_patrolling.launch.pyros2 run robot_patrol patrol_node --ros-args \
-r scan:=/your_scan_topic \
-r odom:=/your_odom_topic \
-r cmd_vel:=/your_cmd_vel_topic- The obstacle logic uses fixed scan indices (
0,230,360,400), so your LaserScan must have enough rays and a similar angular layout. - For different sensors, adjust index mapping in
robot_patrol/patrol.py. - Loop counting threshold is controlled by
rev_thresholdinrobot_patrol/patrol.py.
You should see logs like:
[INFO] [patrol_node]: Completed revolution #1
[INFO] [patrol_node]: Completed revolution #2