Logitech G29 steering wheel development under linux

git project: rc-joystick
RemoteControl
JSTestG29

(1) Check the port and read the steering wheel data
reference blog
The project needs to use the Logitech (logitech) G29 game steering wheel to demonstrate remote driving.

Logitech G29 game steering wheel and window system have special "logitech game software", which can be driven and set, but the window system needs to obtain steering wheel data, and custom development seems to be realized with the help of unity. This is not related to our main research The directions are not consistent, so don't go this way when you don't have to.

Under the Linux system, is there a way to obtain steering wheel data? The answer is yes.

When we connect G29 to the computer, there will be an extra 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 this prints out the original hex data, which is not readable. Now the question is: how to parse this data into specific readable data?

I have searched for information on the Internet for a long time, but I can't find any references. Inadvertently found a joystick calibration tool: jstest-gtk

It can be installed by command:

apt-get install jstest-gtk

After running (jstest-gtk /dev/input/js0), there is a graphical interface, and you can see that when operating g29, the data is displayed on the interface correspondingly.

Steering wheel, accelerator, 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, it needs to be installed in the software center: gtkglextmm

An error may be reported when compiling, add the header file to joystick.cpp

#include <stdint.h>

#include <unistd.h>

Compile mode, execute: scons

Run as: jstest-gtk /dev/input/event11

The interfaces corresponding to data such as steering wheel and buttons are:

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 time.

2. Use the joy package of ros for development

  1. Operating environment
    Operating system: Ubuntu 18.04
    ROS version: ROS Melodic
  2. Install controller drivers and packages
    Enter the following commands in sequence to install
sudo apt-get install ros-melodic-joy(ROS相关项,Jetson TK1只安装这一个)
sudo apt-get install ros-melodic-joystick-drivers
rosdep install joy
rosmake joy
  1. Use step
    3.1 to change the user group of the gamepad interface to the dialout group.
    After the computer is plugged in with the gamepad, the name of the gamepad interface is js0 ​​by default, and its default owner and group are both root, which means root authority is required to proceed 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/js0view, if the following information is output, it means the change is successful:

crw-rw-r--+ 1 root dialout 13, 0 105 09:03 /dev/input/js0

3.2 Test whether the handle is set successfully
Make sure to plug in the handle receiver on the computer and enter the following command to test:

sudo jstest /dev/input/js0

Press the handle button, 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 handle nodes on two
terminals
respectively Enter the following commands in order to start 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. You only need to subscribe to this topic when you are working on a project:

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 as [-32767,32767] in ros from the left only [-1,1]
clutch corresponds to axes[1] from top to bottom as [32767,-32767] in ros From top to bottom is [-1,1]
Brake corresponds to axes[3] From top to bottom is [32767,-32767]
Accelerator corresponds to axes[2] From top to bottom is [32767,-32767]
Left paddle buttons[ 5]
Right paddle buttons[4] Enter
key buttons surrounded by red rings[23]
Plus sign buttons[19]
Minus sign buttons[20]
Arrow keys up axes[5] -32767 Arrow keys down axes[5] ] 32767
arrow keys left axes[4] -32767 arrow keys right axes[4] 32767

L2 key buttons[7]
L3 key buttons[11]
R2 key buttons[6]
R3 key buttons[10]

Guess you like

Origin blog.csdn.net/qq_21830903/article/details/120195592