GO1 Software Setup
==================

.. image:: media/gifs/go1_rviz.gif
   :width: 100%
   :align: center

Requirements
------------

This driver requires a system setup with ROS. It is recommended to use
Ubuntu 18.04/Ubuntu 20.04 with ROS melodic/noetic.

To make sure that robot control isn't affected by system latencies, it
is highly recommended to connect the robot via lan. The driver should
run intially on remote PC but can also be run on Rasberry Pi/Nvidia
board on robot.

Building
--------

Please follow the pre-requisite section.

- `ROS Melodic <http://wiki.ros.org/melodic/Installation/Ubuntu>`__
- `ROS Noetic <http://wiki.ros.org/noetic/Installation/Ubuntu>`__
- GO1 package `Email <support@mybotshop.de>`

Optional
--------

- `Gazebo9 <https://classic.gazebosim.org/tutorials?cat=install&tut=install_ubuntu&ver=9.0>`__ (melodic)
- `Gazebo11 <https://classic.gazebosim.org/tutorials?tut=install_ubuntu>`__ (noetic)

Software Overview
-----------------

Quadruped robots work in two modes:

 1. High level mode
 2. Low level mode

User can be in one of these modes and they can not be switched after
running.

High level mode
~~~~~~~~~~~~~~~

 .. image:: media/a1_launch.gif

High level mode is mainly for walking and running. This mode too has two
modes normal and motion mode which can be distinguished from their
ips (For more details see Quadruped software guide). At the moment this
driver is working with default configuration.

In high level mode the robot can walk/run. To run the robot in high
level mode run the following command as root user (after turning on the
robot and connecting through lan, the robot will be standing):

.. code:: bash

    sudo su
    source ~/catkin_ws/devel/setup.bash
    roslaunch go1_base base.launch

.. Note:: 

    Note that in the ''base.launch'' file the target ip needs to be 
    changed to 192.168.123.161 when connect to Go1 via LAN where as 
    ip will be ``192.168.12.1`` when connected via WLAN. Similarly,
    target port should be 8082 and working mode will be high_level.


With ``base.launch``  launches a communication channel between the robot and remote PC. Then
later in */base_node/cmd_vel* a ROS node is run.
 
::

    Node [high_level_driver]

    Publications: state [go1_legged_msgs/HighState]

    Subscriptions: cmd_vel [geometry_msgs/Twist]

    Services: set_body_pose [go1_legged_msgs/SetMode]

The robot pose can be set using the robot ``set_body_pose`` service.
Robot state is published in ``state`` topic. This message contains a lot
of information. For more information see 
`high state message <https://github.com/unitreerobotics/unitree_ros_to_real/blob/master/unitree_legged_msgs/msg/HighState.msg>`__.


**Using the driver**

The node subscribes to ``base_cmd_vel`` topic. Here special attention needs
to be paid. As the robot is holonimic so different ``Twist`` message
fields determine different movement. A nice tool here would be
`teleop\_twist\_keyboard <http://wiki.ros.org/teleop_twist_keyboard>`__.
Here in the teleop holonomic and non holonomic modes can be used(Be
aware key strokes and their usage).


Low level mode
~~~~~~~~~~~~~~

In this mode all the motors can be controlled directly. For that one
needs to first change the operation mode either to Servo mode or
Electronic brake mode. 

When using the lowlevel it is necessary to switch the robot to normal mode:.
When the robot is turned on and stands up on its own:

1. L2+B (Together) robot will get down
2. L1+L2+START (Together)

At this point you can run the routine

.. important:: 
    
   The robot will fall over when running the low-level routine, please suspend the robot before using it!

Low level mode has again three control modes:

1. Position
2. Velocity
3. Torque

In low level mode joint level control can be achieved. In Quadruped Go1
this low level mode can be in three different levels i.e. Position,
Velocity, Torque. All three of them can be used with this driver by
publishing appropriate messages. Unlike high level mode robot
communication is achieved inside the driver node so no seperate nodeshould run.
After turning on the robot and connecting through lan run the followingcommand:

.. code:: bash

    sudo su
    source ~/catkin_ws/devel/setup.bash
    roslaunch go1_base base.launch

.. Note:: 

    The ``base.launch`` file the target ip needs to be changed to ``192.168.123.10`` when connect to Go1 via LAN.
    Similarly, target port should be ``8007`` and working mode will be high_level.


A node with follwoing information will be run:

::

    Node [low_level_driver]

    Publications: state [unitree_legged_msgs/LowState]
                  joint_states [sensor_msgs/JointState]

    Subscriptions: joint_cmd [qre_msgs/JointCMD]

    Services: set_body_pose [qre_msgs/SetBodyPose] -> Not implemented yet
              set_control [qre_msgs/SetControl]

The node subscribes to ``joint_cmd`` topic. Again here special attention
to be paid as well for the joints. For joint sequence see
`qre\_msgs <https://my.hidrive.com/share/6kxgj8nox2>`__
README. The driver publishes two topics state topic pubslihes the
information from the robot. For more details see `low state
.. message <https://github.com/unitreerobotics/unitree_ros_to_real/blob/master/unitree_legged_msgs/msg/LowState.msg>`__.
Joint state messages are also published. ``set_control`` service is can
change the robot three modes namely i.e. Position, Velocity, Torque(Case
sensitive). For every control level here similar joint messages need to
be filled in ``joint_cmd`` topic other fields are not considered.

::

    Position -> JointCMD.q
                JointCMD.Kd
                JointCMD.Kd
    Velocity -> JointCMD.dq
                JointCMD.Kp
                JointCMD.Kd
    Torque   -> JointCMD.tau




GO1 Base
========

This ros package contains the hardware drivers that communicate with motors of the GO1.
This driver can be run on a remote PC. 

- For WLAN, High-level mode.

.. code:: bash

   roslaunch go1_base base.launch working_mode:=high_level target_ip:=192.168.12.1 target_port:=8082 local_port:=8090 


- For LAN, High-level mode.

.. code:: bash

   roslaunch go1_base base.launch working_mode:=high_level target_ip:=192.168.123.161 target_port:=8082 local_port:=8090 

- For LAN, Low-level mode.

.. code:: bash

   roslaunch go1_base base.launch working_mode:=low_level target_ip:=192.168.123.10 target_port:=8007 local_port:=8090 

GO1 Camera
==========

This ros package contains the camera drivers that communicate with the GO1 cameras.

.. code:: bash

   roslaunch go1_camera camera_13.launch
   roslaunch go1_camera camera_14.launch
   roslaunch go1_camera camera_15.launch

GO1 Control
===========

This ros package enables teleop for the Logitech controller.

.. This ros package fuses the robots tracked wheels movement with the inertial measurment unit (IMU) using the extended kalman filter.
.. Moreover, it provides the transforms from the robots base link to the odometry frame.

.. code:: bash

   roslaunch go1_control teleop.launch

GO1 Description
===============

This is a ros package that contains the 3D models of the GO1. Additionally, the seperate 3D models are stitched together into a single 
entity via the universal robot description format (URDF). It contains the models for auxiliary components such as lidars as well. Additions
to the robot's 3D model can be made in the ``xacro/robot.urdf.xacro``. To view the robot with simulated dummy drivers. You can
run:

.. code:: bash
   
   roslaunch go1_description bringup.launch

.. note::

   It is ideal to run this on your own PC when the robot is not attached just to adjust the position of your
   auxiliary components.


The description is automatically launched with the base driver to show the perceived position of the legs with the robot.

.. code:: bash
   
   roslaunch go1_description description.launch

GO1 Legged Msgs
---------------

This ros package contains custom ros messages used by the GO1 Base.

GO1 Viz
-------

This ros package is used for visualization of the robots current state both in simulation and in the real-hardware.

.. code:: bash

   roslaunch go1_viz view_robot.launch
