Skip to content

YehiaElkh/APF_Obstacle_Avoidance_ROS2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Évitement d'obstacles en temps réel — Champs de Potentiel Artificiel (APF)

Environnement : Ubuntu 22.04 | ROS2 Humble | Gazebo Classic


Structure du workspace

apf_ws/
├── src/
│   ├── diff_drive_description/       # Package URDF + monde Gazebo
│   │   ├── urdf/
│   │   │   └── diff_drive_robot.urdf.xacro   # Robot + LiDAR
│   │   ├── worlds/
│   │   │   └── apf_world.world               # Environnement + obstacles
│   │   ├── launch/
│   │   │   └── gazebo.launch.py              # Lance Gazebo + robot
│   │   └── config/
│   │       └── rviz_config.rviz              # Config RViz2
│   │
│   └── diff_drive_control/           # Package contrôleur APF
│       ├── diff_drive_control/
│       │   ├── apf_controller.py     # Nœud APF (tâches 3, 4)
│       │   └── scan_verifier.py     # Vérificateur LiDAR (tâche 2)
│       ├── launch/
│       │   └── apf.launch.py        # Lance le contrôleur
│       └── config/
│           └── apf.yaml             # Paramètres (goal, gains k_att, k_rep)
└── build_and_run.sh                  # Script d'aide

Installation rapide

1. Prérequis

# ROS2 Humble doit être installé
source /opt/ros/humble/setup.bash

# Gazebo Classic (Gazebo 11)
sudo apt install ros-humble-gazebo-ros-pkgs ros-humble-gazebo-ros

# Autres dépendances
sudo apt install ros-humble-robot-state-publisher \
                 ros-humble-joint-state-publisher \
                 ros-humble-xacro \
                 ros-humble-rviz2

2. Cloner / copier le workspace

cd ~/
# Si vous avez cloné : git clone <repo> apf_ws
# Sinon copiez le dossier apf_ws dans ~/

3. Compiler

cd ~/apf_ws
chmod +x build_and_run.sh
./build_and_run.sh build
# OU manuellement :
source /opt/ros/humble/setup.bash
colcon build --symlink-install
source install/setup.bash

Lancement (3 terminaux)

Terminal 1 — Simulation Gazebo

cd ~/apf_ws && source install/setup.bash
ros2 launch diff_drive_description gazebo.launch.py

Gazebo s'ouvre avec le robot placé en (-3.5, 0) et 6 obstacles statiques.

Terminal 2 — Tâche 2 : Vérification LiDAR

cd ~/apf_ws && source install/setup.bash
ros2 run diff_drive_control scan_verifier
# Ou avec paramètres :
ros2 run diff_drive_control scan_verifier \
    --ros-args -p close_threshold:=0.4 -p max_scans:=30

Affichage typique :

[scan_verifier] [Scan #1] rayons_valides=358/360 | min=0.423m @45.0° | max=3.487m | mean=2.341m | std=0.987m | proches(<0.5m)=3

Terminal 3 — Tâches 3 & 4 : Contrôleur APF

cd ~/apf_ws && source install/setup.bash
ros2 launch diff_drive_control apf.launch.py

Paramètres APF (config/apf.yaml)

Paramètre Valeur défaut Description
goal_x 4.0 Position X du goal [m]
goal_y 3.0 Position Y du goal [m]
k_att 0.8 Gain d'attraction
k_rep 1.5 Gain de répulsion
d0 0.8 Distance seuil de répulsion [m]
max_v 0.30 Vitesse linéaire max [m/s]
max_omega 1.50 Vitesse angulaire max [rad/s]
goal_tol 0.20 Tolérance goal [m]

Modifier les paramètres en temps réel

ros2 param set /apf_controller goal_x 3.5
ros2 param set /apf_controller k_att 1.2
ros2 param set /apf_controller k_rep 2.0

Théorie — Méthode des Champs de Potentiel

Potentiel attractif

$$U_{att}(q) = \frac{1}{2} k_{att} \cdot d_{goal}^2$$

$$\vec{F}_{att} = -\nabla U_{att} = k_{att} \cdot (q_{goal} - q_{robot})$$

Potentiel répulsif

$$U_{rep}(q) = \begin{cases} \frac{1}{2} k_{rep} \left(\frac{1}{d} - \frac{1}{d_0}\right)^2 & \text{si } d \leq d_0 \ 0 & \text{si } d > d_0 \end{cases}$$

$$\vec{F}_{rep} = k_{rep} \left(\frac{1}{d} - \frac{1}{d_0}\right) \frac{1}{d^2} \hat{n}$$

Force totale → commandes

$$\vec{F}_{total} = \vec{F}_{att} + \vec{F}_{rep}$$

$$v = v_{max} \cdot |\vec{F}_{total}| \cdot \cos(\theta_{err})$$ $$\omega = k_\omega \cdot \theta_{err}$$


Commandes de débogage

# Topics actifs
ros2 topic list

# Fréquence du scan
ros2 topic hz /scan

# Données scan (1 message)
ros2 topic echo /scan --once

# Commandes envoyées au robot
ros2 topic echo /cmd_vel

# Odométrie
ros2 topic echo /odom

# Graphe ROS2
rqt_graph

# Arrêt d'urgence
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist \
    '{linear: {x: 0.0}, angular: {z: 0.0}}' -1

Limitations connues (APF)

  1. Minima locaux : le robot peut se bloquer entre plusieurs obstacles.
    Solution : ajouter une composante de rotation aléatoire détectée sur timeout.

  2. Oscillations : en couloir étroit, le robot peut osciller.
    Solution : filtrage passe-bas sur cmd_vel (moyenne glissante).

  3. Convergence au goal : avec d0 grand, la force répulsive peut dépasser l'attractive.
    Solution : réduire k_rep ou d0 près du goal.


Références

About

Real-time obstacle avoidance using Artificial Potential Fields — ROS2 Humble + Gazebo Classic

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors