Bind controller buttons to a package

I have built a package that avoids obstacles on my robot and I wonder if its possible to run this package using my ps4 controller, the controller is connected using ds4drv .
I run my package by entering to the robot’s pc and then “rosrun xx xx”

Hi @shahad78 ,

I am not sure if I could give an exact answer but I can give you some helpful tips.

You can accomplish your task in two methods - the easy way and the hard way.

Easy Way:
You can map your PS4 Controller / Joystick keys to the movement keys on a keyboard. Something like mapping your joystick directions to keyboard W/A/S/D and your action keys to I/J/K/L. You can later test your robot with the teleop program and check if joystick-keyboard key mapping works. However, this may or may not be viable.

Hard Way:
If you are using wired or wireless PS4 controller that can be connected to a PC, you can find a driver package that would transform incoming joystick actions to control signals. You can use a python or c++ library to transport thsese control signals into ROS by writing a program with publisher, that would send these control signals from the joystick driver to ROS core.

You can finally use a subscriber script in your ROS package and utilize these joystick signals to move your robot - either in simulation or the real one!

I hope these tips were helpful to you!


This topic was automatically closed after 3 days. New replies are no longer allowed.