git project: rc-joystick
RemoteControl
JSTestG29
(1) Check the port and read steering wheel data
Reference blog
The project requires the use of a Logitech G29 gaming steering wheel to demonstrate remote driving.
The Logitech G29 gaming steering wheel and window system have special “logitech gaming software” that can be driven and set up. However, the window system needs to obtain the steering wheel data and carry out customized development with the help of Unity. This is related to our main research. The directions are inconsistent, so don’t take this path if you don’t have to.
Is there any way to obtain steering wheel data under a linux system? The answer is yes.
When we connect G29 to the computer, there will be an additional device in /proc/bus/input/devices: /dev/input/event11 (or /dev/input/js0)
This device file is the input node of our G29. When we turn the direction or step on the accelerator, data will be generated on this node.
You can view it with the following command:
cat /dev/input/js0 | hexdump
But what is printed is the original hex data, which is not readable. So the question now is: how to parse this data into specific readable data?
I searched for information on the Internet for a long time, but couldn’t find any reference. I accidentally discovered a joystick calibration tool: jstest-gtk
It can be installed via the command:
apt-get install jstest-gtk
After running (jstest-gtk /dev/input/js0), there is a graphical interface. You can see that when operating g29, the data is displayed correspondingly on the interface.
The steering wheel, throttle, brake, etc. all have data bars, which means that this tool has helped us convert cat /dev/input/js0 | hexdump.
Then we can develop based on this source code, (source code download address: https://download.csdn.net/download/amlinsan/12274982)
After getting jstest-gtk-0.1.0, you need to install the following tools:
apt-get install scons
apt-get install cmake
apt-get install sigc++
apt-get install gtkmm-2.4
apt-get install libboost-all-dev
If it is ubuntu 14.04, you need to install it in the software center: gtkglextmm
An error may be reported during compilation. Add the header file to joystick.cpp.
#include
#include
Compilation mode, execution: scons
Running mode: jstest-gtk /dev/input/event11
The interface corresponding to data such as the steering wheel and buttons is:
In joystick_test_widget.cpp:
void
JoystickTestWidget::axis_move(int number, int value)
{
axes.at(number)->set_fraction((value + 32767) / (double)(2*32767));
std::ostringstream str;
str << value;
axes.at(number)->set_text(str.str());
axis_callbacks[number](value / 32767.0);
std::cout << “amlinsan axis_move-number:” << number << “; value:” << value << std::endl;
}
void
JoystickTestWidget::button_move(int number, bool value)
{
if(value)
buttons.at(number)->set_down(true);
else
buttons.at(number)->set_down(false);
std::cout << “amlinsan button_move-number:” << number << “; value:” << value << std::endl;
}
Just change it here next.
2. Use the joy package of ros for development
- Operating environment
Operating system: Ubuntu 18.04
ROS version: ROS Melodic - Install handle drivers and packages
Enter the following commands in order to install
sudo apt-get install ros-melodic-joy (ROS related items, Jetson TK1 only installs this one) sudo apt-get install ros-melodic-joystick-drivers rosdep install joy rosmake joy
- Steps for usage
3.1 Change the user group of the game controller interface to the dialout group
After the game controller is plugged into the computer, the game controller interface name is js0 by default, and its default owner and group are root, which means root permission is required to operate. You can enter the following command to view:
ls -l /dev/input/js0
Enter the following command to change the root group of js0 to the dialout group:
sudo chgrp dialout /dev/input/js0
Enter again: ls -l /dev/input/js0
to check. If the following information is output, the change is successful:
crw-rw-r-- + 1 root dialout 13, 0 October 5 09:03 /dev/input/js0
3.2 Test whether the handle is set successfully
Make sure the controller receiver is plugged into the computer and enter the following command to test:
sudo jstest /dev/input/js0
Press the handle button, and the button information will be displayed on the terminal. If it does not appear, execute the following command:
sudo apt-get install joystick
The information is displayed as follows:
Driver version is 2.1.0.
Joystick (Xbox 360 Wireless Receiver) has 4 axes (X, Y, Rx, Ry)
and 17 buttons (BtnX, BtnY, BtnTL, BtnTR, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR, ?, ?, ?, (null), (null), (null), (null)).
Testing… (interrupt to exit)
Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11 :off 12:off 13:off 14:off Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7: off 8:off 9:off 10:off 11:off 12:off 13:off 14:off Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11:off 12:off 13:off 14:off Axes: 0: 0 1: 0 2: 0 3: 0 Buttons: 0 :off 1:off 2:off 3:o
3.3 Run the handle node
Enter the following commands in the two terminals to open the ROS and joy_node nodes:
roscore rosrun joy joy_node
The following command can view the topic content:
rostopic echo joy
If you press the button and receive the following message, it means success. When working on the project, you only need to subscribe to this topic:
header: seq: 1 stamp: secs: 1525826012 nsecs: 692879198 frame_id: '' axes: [0.0, -0.0, 0.0, 0.0] buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] --- header: seq: 2 stamp: secs: 1525826012 nsecs: 696846275 frame_id: '' axes: [0.0, -0.0, 0.0, 0.0] buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] --- header: seq: 3 stamp: secs: 1525826012 nsecs: 700968664 frame_id: '' axes: [0.0, -0.0, 0.0, 0.0] buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Original link: https://blog.csdn.net/hengheng_51/article/details/80246918
3. Debugging stage – find the action interface corresponding to the steering wheel
The joy data format of ros is
--- header: seq: 1275 stamp: secs: 1631168393 nsecs: 841879898 frame_id: "/dev/input/js0" axes: [-0.46589395403862, -1.0, 0.0, 0.0, 0.0, 0.0] buttons: [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] ---
The steering wheel corresponds to axes[0] from left to right, which is [-32767,32767]. In ros, from left to right, it is only [-1,1].
The clutch corresponds to axes[1] from top to bottom, which is [32767,-32767] and in ros, it is [-1,1] from top to bottom.
Brake corresponding axes[3] from top to bottom is [32767,-32767]
The throttle corresponds to axes[2] from top to bottom: [32767,-32767]
Left paddle buttons[5]
Right paddle buttons[4]
Enter key buttons[23] surrounded by a red ring
plus sign buttons[19]
Minus button buttons[20]
Arrow key up axes[5] -32767 Arrow key down axes[5] 32767
Arrow key left axes[4] -32767 Arrow key right axes[4] 32767
L2 keys buttons[7]
L3 keys buttons[11]
R2 button buttons[6]
R3 keys buttons[10]