
This section covers debugging tools and techniques for the B2W ROS2 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. Manually launching the same file will create duplicate nodes, causing conflicts.

**Check Before Manual Launch:**

Always run this before manually launching any ROS2 nodes:

.. 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

Service Status Indicators
-------------------------

- **Red marker** - The startup job has failed
- **Green marker** - Everything is working correctly
- **Grey marker** - The service has not started yet

Restart Services
----------------

.. code-block:: bash

   # Restart B2 services
   sudo systemctl restart b2-hardware
   sudo systemctl restart b2-webserver

View Service Logs
-----------------

.. code-block:: bash

   # View recent logs for a service
   journalctl -u b2-hardware -n 50

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

   # View logs since last boot
   journalctl -u b2-hardware -b
