************* Questions ************* Introduction =============== In this workshop you will create a ROS2 node to control the Turtlebot3 using a Gamepad. If you don't have a physical Gamepad, you can use a virtual one instead. In that case you can use the following instructions :ref:`virtual_joy`. Everyone else can now connect a Gamepad/Joypad via USB to their PC. You can check the device path of your Gamepad using: .. code-block:: bash $ ls /dev/input/js* If you are using this command before and after you plug in the device, there should appear a new device, this is your Gamepad. If your device does not appear, you might probably need to install additional drivers for it. Please follow the instructions of your Hardware device on how to install the drivers for Ubuntu. Task: ROS package =================== Create a package called **tb3_teleop** inside your workspace *robot_ws*. Task: ROS node ================ Create a node named *teleop.py* inside the **tb3_teleop** package (s. Fig. 1). The axis data provided by the node *joy_node* of the package **joy** should be used to control the turtlebot3. In case you are using the virtual joypad instead, use the *rqt_joy* node from the **rqt_joy** package. First, test the published topic of the *joy_node* or *rqt_joy*, which changes due to the input of the joystick and inform yourself about the structure of the *joy* message in the ROS wiki. Develop your node *teleop.py* in order for it to act like an interface as shown in Fig. 1. .. figure:: /_resources/image/teleop_flow.png Figure 1. Node Graph .. Setting up the Turtlebot3 - Physical robot ================================================== .. To control the turtlebot via a joystick, you must start the communication interface .. between the On-board computer and the OpenCR board to control the servo motors. .. Hence, create a package **tb3_bringup** with **roscpp**, **std_msgs**, **diagnostic_msgs**, .. **sensor_msgs**, **turtlebot3_msgs**, **rosserial_python**, **robot_state_publisher** and .. **joint_state_publisher** as dependencies. Create the following launch files in the launch directory: .. .. literalinclude:: /_resources/code/workshops/launch/turtlebot3_core.launch :language: xml :lines: 1- :caption: turtlebot3_core.launch: Launches the serial communication interface. .. .. literalinclude:: /_resources/code/workshops/launch/turtlebot3_robot.launch :language: xml :lines: 1- :caption: turtlebot3_robot.launch: Launches the various components of the real world robot. .. Now, start the complete setup: .. .. code-block:: bash .. $ roslaunch tb3_bringup turtlebot3_robot.launch Setting up the Turtlebot3 - Simulated robot ================================================== To start your Turtlebot3 Gazebo simulation, use the known command: .. code-block:: bash $ export TURTLEBOT3_MODEL=waffle $ ros2 launch turtlebot3_gazebo turtlebot3_house.launch Task: control your robot using a joypad ================================================== The *serial_node.py* contained in the physical robot launch file, enables communication with the microcontroller, which runs the code subscribing to the topic *cmd_vel* as described above. These incoming messages are interpreted to control the servo motors. This behavior is simulated in Gazebo using a plugin for differential kinematics. .. hint:: The velocity value range of *cmd_vel* is between -1 and 1 (linear x for forward and backward movement and angular z for steering). Now proceed to run the *joy_node* or *rqt_joy* and your *teleop.py* to control the turtlebot. .. Testing your code on the turtlebot: ---------------------------------------- .. If you are going to test your code with the turtlebot **on a surface**, follow these instructions: .. 1. Save your files. 2. Check your SSH connection (* refer SSH Tutorial of Day2). 3. Shutdown the On-board computer on the turtlebot. 4. Disconnect the HDMI monitor cable first. 5. Disconnect the power supply afterwards. 6. Connect your battery now. 7. Connect the 5V DC power supply from the battery to the OpenCR board. 8. Plug in the adaptor to the Odroid and boot your Odroid as usual and start your ROS nodes via SSH connection. .. Before continuing coding on your On-board computer's workspace, follow these instructions: .. 1. Save your files. 2. Shutdown via SSH: $ sudo shutdown now 3. Unplug the battery. 4. Plug in the power supply (adaptor) to your OpenCR board first. 5. Plug in the HDMI monitor cable afterwards. 6. Work as usual with on your monitor. .. *Alternatively*, the easier way: **Edit your files via SSH!** .. Task: ROS Network setup =========================== .. Setup your ROS Network between your On-board computer on the Turtlebot3 and your .. Workstation(Desktop P.C.). Therefore, use the instructions of the NetworkSetup tutorial. .. Connect the joystick to your Workstation instead of the On-board computer and .. run the node *joy_node* on the workstation. Enjoy the power of the decentralized ROS architecture. Task: Emergency stop button service ===================================== Enlarge your node by adding a stop button from your game controller. If this button on the controller is pressed, the turtlebot should stop immediately, no matter what input is coming from the joystick. → Hint: This task is made be solved with a Service.