===============
Demo
===============

Connect the Synapticon device configured with OBLAC Tools to your ethernet port as shown in Figure 1. For the demo, run 5 terminals in the container (``docker exec -it ros2_container bash`` and ``source /root/.bashrc``).

    Terminal 1

        If you are running demo with one motor:

        .. code:: bash

            ros2 launch synapticon_ros2_control elevated_permissions_1_dof.launch.py

        If you are running demo with two motors:

        .. code:: bash

            ros2 launch synapticon_ros2_control elevated_permissions_2_dof.launch.py

    Terminal 2 - this one will open RViZ (if it fails, you forgot to execute ``xhost +`` on your host machine). 
    If you spin the motor by hand, you should see the movement in RViZ.

        If you are running demo with one motor:

        .. code:: bash

            ros2 launch synapticon_ros2_control single_dof.launch.py

        If you are running demo with two motors:

        .. code:: bash

            ros2 launch synapticon_ros2_control two_dof.launch.py

    Terminal 3 - to show the running controllers

        .. code:: bash

            ros2 control list_controllers

        (Information does not automatically refresh - it can be
        refreshed each M seconds using
        ``watch -n M ros2 control list_controllers``, but the output format
        might be ugly)

    Running the motor with different controllers

        CSV (Cyclic Sync Velocity) mode

            Terminal 4 to turn on the controller:

            .. code:: bash

                ros2 service call /controller_manager/switch_controller controller_manager_msgs/srv/SwitchController "{activate_controllers: ['forward_velocity_controller'], deactivate_controllers: []}"

            Terminal 5 to create a publisher:

                If you are running demo with one motor:

                .. code:: bash

                    ros2 topic pub /forward_velocity_controller/commands std_msgs/msg/Float64MultiArray data:\ [100]

                If you are running demo with two motors:

                .. code:: bash

                    ros2 topic pub /forward_velocity_controller/commands std_msgs/msg/Float64MultiArray data:\ [100,100]

            Stopping it: CTRL+C on Terminal 5 and in Terminal 4:

            .. code:: bash

                ros2 service call /controller_manager/switch_controller controller_manager_msgs/srv/SwitchController "{activate_controllers: ['quick_stop_controller'], deactivate_controllers: ['forward_velocity_controller']}"

        CSP (Cyclic Sync Position) mode

            Terminal 4 to turn on the controller:

            .. code:: bash

                ros2 service call /controller_manager/switch_controller controller_manager_msgs/srv/SwitchController "{activate_controllers: ['forward_position_controller'], deactivate_controllers: ['quick_stop_controller']}"

            Terminal 5 to create a publisher:

                If you are running demo with one motor:

                .. code:: bash

                    ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray data:\ [140]

                If you are running demo with two motors:

                .. code:: bash

                    ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray data:\ [140,140]

            Stopping it: CTRL+C on Terminal 5 and in Terminal 4:

            .. code:: bash

                ros2 service call /controller_manager/switch_controller controller_manager_msgs/srv/SwitchController "{activate_controllers: ['quick_stop_controller'], deactivate_controllers: ['forward_position_controller']}"

        CST (Cyclic Sync Torque) mode

            Terminal 4 to turn on the controller:

            .. code:: bash

                ros2 service call /controller_manager/switch_controller controller_manager_msgs/srv/SwitchController "{activate_controllers: ['forward_torque_controller'], deactivate_controllers: ['quick_stop_controller']}"

            Terminal 5 to create a publisher (value is in per mille of torque):

                If you are running demo with one motor:

                .. code:: bash

                    ros2 topic pub /forward_torque_controller/commands std_msgs/msg/Float64MultiArray data:\ [100]

                If you are running demo with two motors:

                .. code:: bash

                    ros2 topic pub /forward_torque_controller/commands std_msgs/msg/Float64MultiArray data:\ [100,100]

            Stopping it: CTRL+C on Terminal 5 and in Terminal 4:

            .. code:: bash

                ros2 service call /controller_manager/switch_controller controller_manager_msgs/srv/SwitchController "{activate_controllers: ['quick_stop_controller'], deactivate_controllers: ['forward_torque_controller']}"

