
.. warning::
   ROS 2 Foxy Fitzroy reached end-of-life in June 2023. We recommend upgrading to ROS 2 Humble for continued support.

Debugging
---------

This section covers debugging tools and techniques for the B2W ROS 2 system.

No Topics Visible
^^^^^^^^^^^^^^^^^

.. code-block:: bash

   # Verify ROS_DOMAIN_ID
   echo $ROS_DOMAIN_ID  # Should be 10

   # Check network
   ping 192.168.123.165

Dynamixel Communication Error
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash

   # Check USB device
   ls -la /dev/b2/dynamixel

   # Reboot servos
   ros2 service call /dynamixel/reboot std_srvs/srv/Trigger

LiDAR Not Connecting
^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash

   # Verify network
   ping 192.168.123.120  # Front
   ping 192.168.123.121  # Rear

Service Environment Issues
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash

   # Check what environment the service sees
   sudo systemctl show b2-hardware --property=Environment

   # Verify startup.bash sources correctly
   cat /opt/mybotshop/src/mybotshop/b2_bringup/config/setup.bash

Troubleshooting Duplicate Node Issues
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. warning::
   Do not run duplicate nodes! If a service is running (e.g., ``b2-hardware`` is active), the corresponding launch file is already running.

**Check Before Manual Launch:**

.. code-block:: bash

   # Quick check - shows all active b2 services
   systemctl list-units --type=service --state=active | grep b2

   # Or check specific service
   systemctl is-active b2-hardware && \
     echo "SERVICE RUNNING - DO NOT LAUNCH MANUALLY"

If you accidentally ran duplicate nodes:

.. code-block:: bash

   # Kill all ROS2 nodes in namespace
   pkill -f "ros2.*b2_unit_001"

   # Restart the service
   sudo systemctl restart b2-hardware

Restart Services
^^^^^^^^^^^^^^^^

.. code-block:: bash

   sudo systemctl restart b2-hardware
   sudo systemctl restart b2-webserver

View Service Logs
^^^^^^^^^^^^^^^^^

.. code-block:: bash

   # View recent logs
   journalctl -u b2-hardware -n 50

   # Follow logs in real-time
   journalctl -u b2-webserver -f
