Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamepad tutorial #461

Merged
merged 17 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
How to Teleoperate with a Gamepad
=================================

This guide will introduce you to using a gamepad to move the panda arm.

Prerequisites
-------------
If you haven't already done so, make sure you've completed the steps in :doc:`Visualizing in RViz </doc/tutorials/visualizing_in_rviz/visualizing_in_rviz>`.

Requirements
------------
- Ubuntu 22.04
- ROS 2 Humble
- MoveIt 2
- MoveIt 2 Tutorials
- `ROS2 joy <https://index.ros.org/p/joy/>`_

Steps
-----

1. Build the MoveIt2 workspace

First, ``cd`` to the root directory of the moveit2 workspace. (if you followed the :doc:`Getting Started </doc/tutorials/getting_started/getting_started>` tutorial, this will be ``~/ws_moveit/``).

Then, run ``colcon build``.

2. Plug in your gamepad.
3. Source the install script and run the ``moveit_servo`` example file.

Run ``source install/setup.bash``, then ``ros2 launch moveit_servo servo_example.launch.py``

4. Move the arm around, using the below image as a guide.

.. image:: xboxcontroller.png
:width: 600px

The drawio document can be seen `here <https://drive.google.com/file/d/1Hr3ZLvkYo0y0fA3Qb1Nk_y7wag4UO8Al/view?usp=sharing>`__.

Explanation
-----------

This section explains the launch file and the node that translates gamepad inputs to motion commands.

Launch File
^^^^^^^^^^^

The file that launches this example is
``ws_moveit2/src/moveit2/moveit_ros/moveit_servo/launch/servo_example.launch.py``

This launch file launches everything needed for the panda arm planning, and also launches the ``joy`` node and the ``JoyToServoPub`` node (which is explained below).

Of primary interest is the section of code that launches the joy and ``JoyToServoPub`` nodes.
They are both created as ``ComposableNode``\s. More information about ``ComposableNode``\s can be found `here <https://roscon.ros.org/2019/talks/roscon2019_composablenodes.pdf>`__ and `here <https://medium.com/@waleedmansoor/understanding-ros-nodelets-c43a11c8169e>`__.

.. code-block:: python

ComposableNode(
package="moveit_servo",
plugin="moveit_servo::JoyToServoPub",
name="controller_to_servo_node",
),
ComposableNode(
package="joy",
plugin="joy::Joy",
name="joy_node",
)

JoyToServoPub
^^^^^^^^^^^^^

The node that translates gamepad inputs to motion commands is
``ws_moveit2/src/moveit2/moveit_ros/moveit_servo/src/teleop_demo/joystick_servo_example.cpp``

This node subscribes to the joy node (which publishes messages giving the state of the controller). It publishes ``TwistStamped`` messages, ``JointJog`` messages, and ``PlanningScene`` messages.

The ``PlanningScene`` message is only published once, when the JoyToServoPub is first constructed. It simply adds some obstacles into the planning scene.

The difference between the ``JointJog`` and ``TwistStamped`` messages is
that the inverse kinematic solver moves the joints to achieve the end
effector motions defined by the ``TwistStamped`` messages, while the
``JointJog`` messages directly move individual joints.

The ``joyCB`` function is called when a message is published to the ``joy``
topic, and translates the button presses from the gamepad into commands
for the arm. If both ``JointJog`` and ``TwistStamped`` messages would be
published by the inputs, only ``JointJog`` messages are published.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/how_to_guides/how_to_guides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ These how-to guides will help you quickly solve specific problems using MoveIt.
how_to_setup_docker_containers_in_ubuntu
how_to_write_doxygen
using_ompl_constrained_planning/ompl_constrained_planning
controller_teleoperation/controller_teleoperation.rst
2 changes: 2 additions & 0 deletions doc/how_to_guides/how_to_write_doxygen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ One of the primary benefits of Doxygen is that it allows for automatic generatio


Plugins exist to automate the creation of Doxygen documentation for


- `SublimeText <https://packagecontrol.io/packages/DoxyDoxygen>`_
- `VIM <https://www.vim.org/scripts/script.php?script_id=987>`_
- `VSCode <https://marketplace.visualstudio.com/items?itemName=cschlosser.doxdocgen>`_
Expand Down