Skip to content

A package that allows you to control a wide variety of robots using the DualShock4 controller, while also providing a set of additional features to enhance the user experience.

License

Notifications You must be signed in to change notification settings

StressOverflow/robot_with_ds4_controller

Repository files navigation

Control robot with DS4 Controller 🎮

distro distro Language main

Motivation 💡

We (StressOverflow), as students of Universidad Rey Juan Carlos, are starting to cut our teeth with Nav2. Basically, the first step you have to accomplish if you want to navigate is to have a map to navigate with!

We have been told that the best practice is to map manually by moving around the robot so that the perceived environment is as realistic as possible. So we started to operate the robot using the keyboard of our laptops; however, there was a problem. We are currently using TurtleBot, and we lay our laptops right above the robot. So, in order to access the keyboard, we have to lay down every few steps to maneuver the robot. After a couple of hours, we realized that we will not be Forever Young, so we need to take care of our backs!

That was when we thought of using a controller to maneuver the robot from a comfortable and civilized position... And here we are.

controller_demo_ws.mp4

Installation 💾

Main requirements ✅

  1. First of all, we need Ubuntu. It is a Linux Debian-based operating system, A.K.A Linux Distro. We are working with the 22.04 Jammy Jellyfish 🪼 version. You might be already familiar with it, however here you have a step-by-step tutorial on how to install it on your machine.

  2. ROS. ROS stands for Robot Operating System, and it is the middleware that the vast majority of robots out there use nowadays, and so are we! We are focusing on the latest stable release, which is ROS 2 Humble Hawksbill 🐢. From there you can navigate through all the documentation, but here is a shorcut to the installation page.

Dependencies

  • Python 2.7 or 3.3+ (for Debian/Ubuntu you need to install the python2.7-dev or python3.3-dev package)
  • python-setuptools
  • hcitool (usually available in the bluez-utils or equivalent package)

These packages will normally be installed automatically by the setup script, but you may want to use your distro's packages if available:

Stable release

Installing the latest release is simple by using pip:

sudo pip install ds4drv

Once we have everything installed, clone this repo to your src path, like so:

cd <your-workspace-path>/src
git clone https://github.com/dgarcu/mapwithcontroller.git

Once finished, you need to import the third party repos that we will need. This will clone into your ThirdParty dir the ds4_driver package:

vcs import --recursive < mapwithcontroller/thirdparty.repos

Installation

This driver depends on ds4drv. Some features of this driver depend on pull requests have not yet been merged upstream. Until they are merged, use naoki-mizuno/ds4drv (devel branch).

cd ThirdParty/ds4drv
mkdir -p ~/.local/lib/python3.10/site-packages
python3 setup.py install --prefix ~/.local
sudo cp udev/50-ds4drv.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger
sed -i '5d;6d;15d' setup.py

Compile and source this package just like any other ROS package. To run,

ros2 launch map_with_controller controller.launch.py

Using 💭

ds4drv has two different modes to find DS4 devices, decide which one to use depending on your use case. Raw bluetooth mode and hidraw mode. The fisrt one is not supported yet beacuse the bluetooth protocolos are not as fast as de USB portocols. So we use Hidraw mode

This mode uses the Linux kernel feature hidraw to talk to already existing devices on the system.

To use the DS4 via USB in this mode, simply connect your DS4 to your computer via a micro USB cable.

When the controller is paired, the launcher will show it, then you can start to use it.

Controls 🕹️

There is a dead-man button added as a safety feature. The robot will only move while said button is pressed.

  • dead-man button: X
  • Clear emergencies: L1 + R1
  • Move forward: R2
  • Move backward: L2
  • Turn: Left joystick

There is a timestamp with the last message received from the controller. If this timestamp exceeds a reasonable time, the robot will be stopped until new messages are detected. This could happen when the controller suddenly disconnects from the PC.

UPDATE. Now you will be able to change this timeout in the params file.

Be SPECIALLY CAREFUL with this parameter, since it is the only number between you and a runaway robot. If the controller is disconnected, the robot will continue to move with the last speed commanded. You have been warned!

User feedback

The controller will use some signals to indicate the status of the node.

Controller connected

The controller will softly rumble for 1s. Also, the LED bar will iluminate in steady blue light. 🔵

This state will not change until the first press of the dead-man button.

blue

Controller enabled

The controller will hardly rumble for 250ms. Also, the LED bar will iluminate in steady green light. 🟢

This is the only mode where the robot will actually move! Is activated by HOLDING the dead-man button.

green

Controller disabled

The controller will hardly rumble for 500ms. Also, the LED bar will iluminate in slowly blinking yellow light. 🟡

After a while in this state, the controller will change to IDLE mode. The light will became steady dim blue 🔵.

blinking_yellow

Controller error

The controller will iluminate it's LED bar with fast blinking red light. 🔴

You will see in the terminal more detailed instructions about how to exit from this state.

[controller-1] [WARN] [1682360892.578366918] [controller_node]: [EMERGENCY STOP] Release both triggers to clear.

blinking_red

Params

In params.yaml you will be able to modify the maximum velocity of the robot.

However, as a security feature, it will be clamped by a maximum absolute velocity which is hardcoded.

Friendly reminder The average walking speed for a human is around 1-1.5 m/s. Remember that you are a human wired to a robot which uses your laptop as a hat.

controller_node:
  ros__parameters:
    max_linear_vel: 0.5
    max_angular_vel: 1.0
    controller_timeout: 0.25

If you need it, you could also change the velocity topic. You will find it on the launcher.

controller_cmd = Node(package='map_with_controller',
                          executable='controller',
                          output='screen',
                          parameters=[{
                            'use_sim_time': False
                          }, params_file],
                          remappings=[
                            ('output_vel', '/cmd_vel'), # HERE!
                            ('controller_status', '/status'),
                            ('controller_feedback', '/set_feedback'),
                          ])

Features

https://github.com/naoki-mizuno/ds4_driver.git

https://github.com/naoki-mizuno/ds4drv.git

https://github.com/chrippa/ds4drv.git

Tests 🧾

This package was tested on the following scenarios:

Original DS4 Controller

Kobuki Tiago
Real World 🌍 ✔️ 〰️
Simulation 🖥️ ✔️ ✔️
demokobuki.mp4
demotiago.mp4

Important notes

  • This package was only tested with an original DS4 Controller via USB. Bluetooth was not tested. DS4 Compatible Controllers were not tested either.
  • The controller rumble function temporary fails if multiple events try to activate it in a short period of time.

Future improvements ✔️

  • Parameters. The maximum speed of the robot in each of the maneuvers should be modifiable without the need to recompile the code. Other types of parameters of interest would also be added if needed.
  • "Dead-man" button. The controller should only work if one of the buttons is held down, as a safety feature.
  • Feedback. The controller should notify the user when it is ready to operate the robot, either with lights or vibration, as well as the output of the terminal.
  • Kobuki dedicated branch. Although the package is designed for any robot, a specific branch for the Kobuki TurtleBot would allow it to use its resources, such as the speaker or the LEDs, to emit signals and feedback to the user.

About

This is a project made by the StressOverflow, a student group from the Universidad Rey Juan Carlos. Copyright © 2023.

Maintainers:

License

License

This work is licensed under a APACHE LICENSE, VERSION 2.0.

About

A package that allows you to control a wide variety of robots using the DualShock4 controller, while also providing a set of additional features to enhance the user experience.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •