[ROS] G29 Steering Wheel Feedback

何を学習するのか?

ROS経由で G29 Steering Wheel を回転させる。
PS4コントローラーからG29ステアリングを回転させる。

インストール

$ cd catkin_ws/src 
$ git clone https://github.com/kuriatsu/ros-g29-force-feedback.git
$ cd ../ 
$ catkin_make

G29デバイスの確認

$ cat /proc/bus/input/devices
I: Bus=0003 Vendor=046d Product=c24f Version=0111
N: Name="Logitech G29 Driving Force Racing Wheel"
P: Phys=usb-0000:0a:00.3-3/input0
S: Sysfs=/devices/pci0000:00/0000:00:07.1/0000:0a:00.3/usb3/3-3/3-3:1.0/0003:046D:C24F.000E/input/input30
U: Uniq=
H: Handlers=event2 js0 
B: PROP=0
B: EV=20001b
B: KEY=1ff 0 0 0 0 0 0 ffff00000000 0 0 0 0
B: ABS=30027
B: MSC=10
B: FF=300040000 0

設定ファイルを編集

$ emacs ~/catkin_ws2/src/ros-g29-force-feedback/g29_force_feedback.yaml 
device_name: "/dev/input/event19"
を
device_name: "/dev/input/event2"

起動

$ source ~/catkin_ws2/devel/setup.bash
$ rosparam load ~/catkin_ws2/src/ros-g29-force-feedback/g29_force_feedback.yaml
$ rosrun g29_force_feedback node

ROS トピックス確認

$ rosnode list
$ rosnode info /g29_force_feedback_node

命令を送信

Once the message is thrown, the wheel rotates to 0.3*2.5π (from -1.0 to 1.0) with 0.6 rotation power (from 0.0 to 1.0).

$ rostopic pub /ff_target g29_force_feedback/ForceFeedback "angle: 0.3 force: 0.6"

Python から命令を送る

#!/usr/bin/env python                                                                                                                 
import rospy

from std_msgs.msg import String
from g29_force_feedback.msg import ForceFeedback

def talker():
    rospy.init_node('talker')
    pub = rospy.Publisher('ff_target', ForceFeedback, queue_size=20)
#    pub = rospy.Publisher('g29test', String, queue_size=20)                                                                          

    r = rospy.Rate(0.5)
    while not rospy.is_shutdown():
      # str = "angle: 0.5 force: 0.6"                                                                                                 
      g29msg = ForceFeedback()
      g29msg.angle = 0.0
      g29msg.force = 0.6
      rospy.loginfo(g29msg)
      pub.publish(g29msg)
      #break                                                                                                                          
      r.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException: pass

PS4 コントローラからG29を操作

$ cat /proc/bus/input/devices
I: Bus=0003 Vendor=054c Product=09cc Version=8111
N: Name="Sony Interactive Entertainment Wireless Controller"
P: Phys=usb-0000:0a:00.3-4/input3
S: Sysfs=/devices/pci0000:00/0000:00:07.1/0000:0a:00.3/usb3/3-4/3-4:1.3/0003:054C:09CC.0014/input/input44
U: Uniq=f4:93:9f:32:ba:78
H: Handlers=event22 js1 
B: PROP=0
B: EV=20001b
B: KEY=7fdb000000000000 0 0 0 0
B: ABS=3003f
B: MSC=10
B: FF=107030000 0

デバイスを確認して引数に設定する

$ rosrun joy joy_node _dev:=/dev/input/js1
$ rostopic echo /joy

ROS Joy経由でPS4コントローラの値を取得し、G29のステアリングを回す

#!/usr/bin/env python                                                                                                                            
import rospy

from sensor_msgs.msg import Joy
from g29_force_feedback.msg import ForceFeedback

pub = None

def joy_callback(joy_msg):
    rospy.loginfo("recieved axes0: %s", joy_msg.axes[0])
    g29msg = ForceFeedback()
    g29msg.angle = joy_msg.axes[0] * -1.0
    g29msg.force = 0.5
    rospy.loginfo(g29msg)
    pub.publish(g29msg)
    # now = rospy.Time.now()                                                                                                                     
    # rospy.loginfo("now: %f", now.to_sec())                                                                                                     

if __name__ == '__main__':
    rospy.init_node('ps4tog29')
    rospy.Subscriber("joy", Joy, joy_callback, queue_size=1)
    pub = rospy.Publisher('ff_target', ForceFeedback, queue_size=20)
    rospy.spin()

参考サイト

kuriatsu/ros-g29-force-feedback: ros package of logicool g29 steering force feedback control
ROS講座31 python基礎 – Qiita
ROSを使ってルンバが操作できるまで feat. Raspberry Pi3とPS4コントローラーとUSBカメラ – Qiita

投稿者: yoshimax

Software Engineer #Unity #iOS