The ros driver of the ps3 controller is ps3joy in the joystick_drivers package. This driver supports the original Sony handle, but there is a problem with the support of some others ps3 controllers. We have modified on the basis of ps3joy, added a
ps3joyfake_node.py script as a driver for other joysticks, the package source code address is here. Let's take Xiaoqiang as an example to demonstrate the installation steps and simple usage of this package.
ssh enters Xiaoqiang ros workspace, compile after downloading the source code. If you have install xiaoqiang system image, you can skip this step.
ssh email@example.com cd Documents/ros/src/ git clone https://github.com/BlueWhaleRobot/joystick_drivers.git cd .. catkin_make If the following error is prompted error spnav.h no such file First install the following package, then re-execute catkin_makee sudo apt-get install libspnav-dev
ps3joyfake_node.py starts, it converts the data of the joystick button received by bluetooth into the standard joy msg, and publishes it in ros with
/joy as the topic, that is, a file of
ps3joyfake_node.py is equivalent to two files of
ps3joy.py + joy_node. It is no longer necessary to open the joy_node node in actual use.
Bind the joystick to the usb bluetooth adapter, just bind once, skip this step next time.
Connect the joystick to the host through the usb data cable, and plug the USB bluetooth adapter into the host.
sudo bash rosrun ps3joy sixpair
At this point, you will get an output similar to following. The current and setting mac addresses are the same.
Current Bluetooth master: 00:22:b0:d0:5a:09 Setting master bd_addr to 00:22:b0:d0:5a:09 # If the following error occurs Current Bluetooth master: 00:1b:dc:00:07:3c Unable to retrieve local bd_addr from `hcitool dev`. Please enable Bluetooth or specify an address manually. # Run hciconfig hci0 reset # If you run hciconfig hci0 reset error # Can't init device hci0: Operation not possible due to # Run rfkill unblock all # and run hciconfig hci0 reset # rerun rosrun ps3joy sixpair
After the binding setting is completed, disconnect the handle and the usb connection of the host.
Ctrl+D exits root mode
Pair the handle with the usb Bluetooth adapter
# Make sure the Bluetooth receiver is plugged into the host usb port sudo bash rosrun ps3joy ps3joyfake_node.py
The following prompt will appear normally.
root@xiaoqiang-desktop:~# rosrun ps3joy ps3joyfake_node.py No inactivity timeout was set. (Run with --help for details.) Waiting for connection. Disconnect your PS3 joystick from USB and press the pairing button. If the following error is prompted ImportError: No module named bluethooth Please install the following packages first, then re-run sudo apt-get install libbluetooth-dev sudo pip install PyBluez
Press the joystick pairing button in the image below
If the pairing is successful, the above window will output a result similar to the following.
root@xiaoqiang-desktop:~# rosrun ps3joy ps3joyfake_node.py No inactivity timeout was set. (Run with --help for details.) Waiting for connection. Disconnect your PS3 joystick from USB and press the pairing button. Connection activated
View handle output
# Open a new window and print the button output rostopic echo /joy
Normally the following similar results will appear
header: seq: 297 stamp: secs: 1488877867 nsecs: 535818099 frame_id: '' axes: [0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.21316899359226227, 0.0] buttons: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
As we can see that the fourth button was pressed.
Start the relevant joy msg processing node
Be careful not to start the joy_node again.
# Take Xiaoqiang as an example. After launching the following launch file, you can remotely move Xiaoqiang. roslaunch turtlebot_teleop ps3fakexiaoqiang_teleop.launch
For xiaoqiang user with a joystick you can also use the joystick according to this tutorial
When step 1 is bound, if the prompt cannot find the handle device and cannot be bound, you can perform the following two steps to solve the problem: 1. Click the Bluetooth icon in the upper right corner of the system desktop to close the connected Bluetooth handle service.