.. .. rubric:: ROS2 Modules for G1

.. .. note::
..    Please ensure that the arms are straight down when you power on the robot.  
..    If the orientation is different, it will affect the ROS2 control operation.

.. The ROS2 modules start drivers for operating G1 in **high-level mode** for legs and arms.

.. .. important::
..    During initialization, the arms will move such that the **forearms will face forward**.

.. .. rubric:: Launch G1 ROS2 Driver

.. The driver includes the following modules:

.. - Domain Bridge
.. - Joint States
.. - Robot Description
.. - Arm Control
.. - Leg Control (High-level)
.. - Inertial Measurement Unit Publisher
.. - Sensor Fusion
.. - Twist Mux
.. - Logitech F710 Control
.. - D435i Depth Camera Driver
.. - Livox Mid360 Lidar Driver

.. |

.. These modules can also be viewed, activated, or deactivated from the **Webserver**.

.. .. code:: bash

..     ros2 launch g1_platform highlevel_ros.launch.py


.. .. rubric:: Core Launch Files

.. These launch files can also be managed from the webserver. Ensure the **Webserver** is running. Follow the installation procedure first.

.. .. code:: bash

..     ros2 launch g1_platform highlevel_ros.launch.py
..     ros2 launch g1_platform domain_bridge.launch.py
..     ros2 launch g1_platform state_publisher.launch.py
..     ros2 launch g1_webserver webserver.launch.py
..     ros2 launch g1_control twistmux.launch.py
..     ros2 launch g1_lidar livox_mid360.launch.py
..     ros2 launch g1_platform audio.launch.py
..     ros2 launch g1_platform led.launch.py
..     ros2 launch g1_platform videostream.launch.py

.. .. rubric:: Arms 7Dof Core Launch Files

.. .. code:: bash

..     ros2 launch g1_description g1_29_description.launch.py
..     ros2 launch g1_platform arm_7dof.launch.py

.. .. rubric:: Arms 5Dof Core Launch Files

.. .. code:: bash

..     ros2 launch g1_description g1_23_description.launch.py
..     ros2 launch g1_platform arm_5dof.launch.py

.. .. rubric:: G1 Modes Selection

.. .. rubric:: Posture & State Commands


.. The table below lists commands for controlling the robot's posture and state:

.. +------------------------+------------------------------------------------------------+
.. | Command                | Description                                                |
.. +========================+============================================================+
.. | damp                   | Set all motors to damping mode.                            |
.. +------------------------+------------------------------------------------------------+
.. | start                  | Start locomotion control.                                  |
.. +------------------------+------------------------------------------------------------+
.. | squat                  | Transition to squat posture.                               |
.. +------------------------+------------------------------------------------------------+
.. | sit                    | Sit down.                                                  |
.. +------------------------+------------------------------------------------------------+
.. | stand_up               | Stand up from sitting/squatting.                           |
.. +------------------------+------------------------------------------------------------+
.. | zero_torque            | Disable torque on all motors.                              |
.. +------------------------+------------------------------------------------------------+
.. | stop_move              | Stop all motion immediately.                               |
.. +------------------------+------------------------------------------------------------+
.. | high_stand             | Stand at high position.                                    |
.. +------------------------+------------------------------------------------------------+
.. | low_stand              | Stand at low position.                                     |
.. +------------------------+------------------------------------------------------------+
.. | balance_stand          | Stand with balance mode active.                            |
.. +------------------------+------------------------------------------------------------+
.. | shake_hand             | Perform handshake sequence (auto-start and stop).          |
.. +------------------------+------------------------------------------------------------+
.. | wave_hand              | Perform wave motion.                                       |
.. +------------------------+------------------------------------------------------------+
.. | wave_hand_with_turn    | Wave hand and turn simultaneously.                         |
.. +------------------------+------------------------------------------------------------+

.. .. rubric:: Setter Commands (Change Robot State)


.. +-----------------------------------+--------------------------------------------------+
.. | Command                           | Parameters                                       |
.. +===================================+==================================================+
.. | set_fsm_id=<id>                   | Integer FSM ID to switch to.                     |
.. +-----------------------------------+--------------------------------------------------+
.. | set_balance_mode=<0/1>            | Enable (1) or disable (0) balance mode.          |
.. +-----------------------------------+--------------------------------------------------+
.. | set_swing_height=<value>          | Set swing height in meters.                      |
.. +-----------------------------------+--------------------------------------------------+
.. | set_stand_height=<value>          | Set stand height in meters.                      |
.. +-----------------------------------+--------------------------------------------------+
.. | set_velocity="vx vy ω [duration]" | Set velocity (m/s, m/s, rad/s, [duration in s]). |
.. +-----------------------------------+--------------------------------------------------+
.. | move="vx vy ω"                    | Command motion without duration.                 |
.. +-----------------------------------+--------------------------------------------------+
.. | set_task_id=<id>                  | Set active task ID.                              |
.. +-----------------------------------+--------------------------------------------------+
.. | set_speed_mode=<mode>             | Change locomotion speed mode.                    |
.. +-----------------------------------+--------------------------------------------------+

.. .. rubric:: Getter Commands (Query Current Robot State)

.. +--------------------+----------------------------------+
.. | Command            | Returns                          |
.. +====================+==================================+
.. | get_fsm_id         | Current finite state machine ID. |
.. +--------------------+----------------------------------+
.. | get_fsm_mode       | Current FSM mode.                |
.. +--------------------+----------------------------------+
.. | get_balance_mode   | Current balance mode (0/1).      |
.. +--------------------+----------------------------------+
.. | get_swing_height   | Current swing foot height.       |
.. +--------------------+----------------------------------+
.. | get_stand_height   | Current standing height.         |
.. +--------------------+----------------------------------+
.. | get_phase          | Current gait phase vector.       |
.. +--------------------+----------------------------------+

.. .. rubric:: Toggle Commands

.. +-------------------------------+------------+-------------------------------------------------+
.. | Command                       | Parameters | Description                                     |
.. +===============================+============+=================================================+
.. | continous_gait=<true/false>   | bool       | Enable or disable continuous gait mode.         |
.. +-------------------------------+------------+-------------------------------------------------+
.. | switch_move_mode=<true/false> | bool       | Switch between movement mode and standing mode. |
.. +-------------------------------+------------+-------------------------------------------------+

.. .. rubric:: G1 Mode Examples


.. .. rubric:: Start the robot

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "start"}'

.. .. rubric:: Shake hand


.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "shake_hand"}'

.. .. rubric:: Wave hand


.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "wave_hand_with_turn"}'

.. .. rubric:: Set swing height


.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "set_swing_height=0.12"}'

.. .. rubric:: Move forward

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "set_velocity=0.3 0.0 0.0 2.0"}'

.. .. rubric:: Query current FSM mode


.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "get_fsm_mode"}'

.. .. rubric:: Enable continuous gait


.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware_modes g1_interface/srv/G1Modes \
..     '{"request_data": "continous_gait=true"}'

.. .. rubric:: G1 LED Selection

.. .. rubric:: Set color


.. .. code-block:: bash

..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'color=green'}"
..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'color=red'}"
..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'color=white'}"
..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'color=blue'}"

.. .. rubric:: Set color with hex and brightness

.. .. code-block:: bash

..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'color=#00a0a0;brightness=60'}"

.. .. rubric:: Set color with RGB

.. .. code-block:: bash

..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'color=rgb(128,32,200)'}"

.. .. rubric:: Query LED state

.. .. code-block:: bash

..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'get_brightness'}"
..     ros2 service call /g1_unit_001/hardware/led g1_interface/srv/G1Modes "{request_data: 'get_color'}"

.. .. rubric:: G1 Audio Selection

.. .. rubric:: Set volume

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware/audio g1_interface/srv/G1Modes "{request_data: 'volume=80'}"

.. .. rubric:: Speak English

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware/audio g1_interface/srv/G1Modes "{request_data: 'speak=Hello from MY BOT SHOP'}"

.. .. rubric:: Volume + Text

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware/audio g1_interface/srv/G1Modes "{request_data: 'volume=100;speak= Hello from my bot shop. My name is Danny'}"

.. .. rubric:: Get current volume

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware/audio g1_interface/srv/G1Modes "{request_data: 'get_volume'}"

.. .. rubric:: Self Intro

.. .. code-block:: bash

..     ROS_DOMAIN_ID=10 ros2 service call /g1_unit_001/hardware/audio g1_interface/srv/G1Modes "{request_data: 'volume=100;speak= Hello from my bot shop. I am Danny, a compact humanoid robot for research and education. My height is 1.32 meters, and my weight is 35 kg. I walk up to 2 meters per second, climb stairs, and keep balance. Hehehe climbing stairs not really. My base model has 23 degrees of freedom where as my educational + version has 43 degrees of freedom. I have 3D liDAR specifically Livox Mid360 and depth camera Intel RealSense D435i. Battery lasts about 2 hours +'}"

.. .. note::

..     More info on these commands is available in the Unitree documentation.

.. .. rubric:: Robot Description

.. The G1 robot description package is named **g1_description**. It contains the
.. URDF and mesh files necessary to visualize and simulate the G1 robot in various ROS2 tools.

.. .. rubric:: Twist Mux

.. The twist mux package for the G1 is named **g1_control**. It manages multiple velocity 
.. command inputs and prioritizes them to ensure smooth and safe robot operation.

.. .. rubric:: EKF Localization

.. The Extended Kalman Filter (EKF) localization package for the G1 is named **g1_control**. 
.. It fuses sensor data to provide accurate and reliable robot pose estimates.