电脑配置:Ubuntu20.04
ros2 galactic
Carla:0.9.12
由于Carla+G29要适配Linux系统,罗技的官网没有Linux的驱动,所以需要自己鼓捣;
可以看到罗技的G29由方向盘和油门刹车离合组成,需要将离合上的线接到方向盘上,注意,方向盘有一个电源线需要注意连接,电源线连接好,USB接口连接到计算机G29就开始旋转自检(之前就是这个坑,上机以后其他的按键和油门,刹车有反应,就是方向盘不动,你可以查看一下是不是线松了)。
查看工具:jstest-gtk
sudo apt-get install jstest-gtk #安装这个小工具
jstest-gtk #启动小工具
运行以后发现一个命名为Joystick Preferences的小窗口,发现已经识别到了罗技的设备、Device:/dev /input/js0 >>> 点击Properties进入:
我的油门对应着Axis2,踩油门就有数值变化;刹车对应着Axis3,方向盘对应的Axis0;(Axis0没数据看看有没有给方向盘上电,上电会转,还有一排灯亮起来)
固定问题
看完视频已后才知道想要固定住G29需要先把上面两个圆形的东西给拧开,然后用力朝松的方向拧开,越拧底下的卡扣越向下,然后把两个帽子给掰出来,然后就可以卡在桌子上极品飞车了;
Carla这一端的话做了两个测试验证
./CarlaUE4.sh
Carla/PythonAPI/example
./manual_control_steeringwheel.py --host <服务器地址>
这里如果报错的话,需要改一下manual_control_steeringwheel.py里面的代码
ERROR:
Welcome to CARLA manual control with steering wheel Logitech G29.
To drive start by preshing the brake pedal.
Change your wheel_config.ini according to your steering wheel.
To find out the values of your steering wheel use jstest-gtk in Ubuntu.
WARNING: Version mismatch detected: You are trying to connect to a simulator that might be incompatible with this API
WARNING: Client API version = 0.9.4-84-g889b998-dirty
WARNING: Simulator API version = 0.9.5-1-g4d1230e-dirty
Traceback (most recent call last):
File "./manual_control_steeringwheel.py", line 863, in
main()
File "./manual_control_steeringwheel.py", line 855, in main
game_loop(args)
File "./manual_control_steeringwheel.py", line 790, in game_loop
world.tick(clock)
File "./manual_control_steeringwheel.py", line 180, in tick
self.hud.tick(self, clock)
File "./manual_control_steeringwheel.py", line 426, in tick
'Map: % 20s' % world.world.map_name,
AttributeError: 'World' object has no attribute 'map_name'
解决:
map_name was removed from world, use world.get_map().name
如果是本机运行则可不加服务器地址参数
同时,需要根据测试的方向盘来设置wheel_config.init的参数
cd Carla_python_Client
gedit manual_control_steeringwheel.py
gedit wheel_config.init
这样就可以在Carla中飙车了,但是有一个问题:方向盘没有阻力,容易开飘掉,下一步给G29加force-feedback(力反馈)
解决办法:GitHub上有一个小日子过得不错的程序员做了轮子,那就用一下吧,GitHub - kuriatsu/ros-g29-force-feedback: ros package for logicool g29 steering force feedback control
支持的版本贴到下面了
ROS version |
g29 |
g923 |
ROS1 |
-- |
-- |
Kinetic |
tested |
no |
Melodic |
tested |
no |
ROS2 |
-- |
-- |
Dashing |
no |
no |
Foxy |
tested |
no |
Galactic |
tested |
no |
#看看你的电脑的内核支持力反馈不,内核版本调整成自己的
cat /boot/config-5.3.0-46-generic | grep CONFIG_LOGIWHEELS_FF
CONFIG_LOGIWHEELS_FF=y
install
1.create ros2_ws
mkdir ~p ros2_ws/src
cd /ros2_ws
colcon build
2.download and build package
cd /ros2_ws/src
git clone https://github.com/kuriatsu/ros-g29-force-feedback.git
cd ../
colcon build --symlink-install
适配:
1.配置你的驱动名字
cat /proc/bus/input/devices
看看带有Logitch G29 Driving Force Racing Wheel 的event是哪一个
2.编辑 /config/g29.yaml/device_name event X
3运行节点
source ros2_ws/install/setup.bash
ros2 run ros_g29_force_feedback g29_force_feedback --ros-args --params-file ros2_ws/src/ros_g29_force_feedback/config/g29.yaml
启动的位置应当在文件夹外面!!!
如此就可以感受到方向盘有阻力了,但是我像要方向盘自己动
4.传递信息
$ ros2 topic pub /ff_target ros_g29_force_feedback/msg/ForceFeedback "{header: {stamp: {sec: 0, nanosec: 0}, frame_id: ''}, position: 0.3, torque: 0.5}"
一旦消息被抛出,转盘旋转到0.3 * < max _ angle > (g29: max _ angle = 450 ° 顺时针,-450 ° 逆时针方向) ,发布速度不受限制。
29_force_feedback.yaml
parameter |
default |
description |
device_name |
/dev/input/event19 |
device name, change the number |
loop_rate |
0.1 |
Loop of retrieving wheel position and uploading control to the wheel |
max_torque |
1.0 |
As for g29, 1.0 = 2.5Nm (min_torque < max_torque < 1.0) |
min_torque |
0.2 |
Less than 0.2 cannot rotate wheel |
brake_torque |
0.2 |
Braking torque to stop at the position (descrived below) |
brake_position |
0.1 |
Brake angle (position-0.1*max_angle) |
auto_centering_max_torque |
0.3 |
Max torque for auto centering |
auto_centering_max_position |
0.2 |
Max torque position while auto centering (position±0.2*max_angle) |
eps |
0.01 |
Wheel in the range (position-eps to position+eps) is considered as it has reached the position |
auto_centering |
false |
Anto centering if true |
参看资料:
ubuntu20.04安装Carla并配置罗技G29方向盘使用_carla外接方向盘_冻★结♬ ☞memory☜的博客-CSDN博客
反馈模式
Carla给控制指令,G29作为接收器接收控制指令
GitHub - kuriatsu/ros-g29-force-feedback: ros package for logicool g29 steering force feedback control
源码下载,并编译
然后在example中运行 carla_contrpol.py
python3 .carla_control.py
当然,之前也要开启Carla的世界脚本
。/CarlaUE4.sh -quality-level=Epic -RenderOffScreen
cd carla/PythonAPI/example
./manual_control.py