ps3 joystick 连不上蓝牙接收器解决办法:
1、参考ps3joy 官文
2、拔下蓝牙接收器,再插入蓝牙接收器,按下p键,按一下就好
发现每次连上之后第二次就连不上了,发现拔下接收器之后再连就可以了。。
发布 cmd_vel, 订阅 Joy,,数据从摇杆进来,转换成速度发布出去,,,前提是摇杆connection active,,,sudo jstest /dev/input/js0 对按下按钮应数据有变化。
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg importJoy
class Ps3Learning(object):
def __init__(self):
self.cmd = None
rospy.init_node("ps3joyLearning_node")
rospy.Subscriber("/gl/joy", Joy, self.callback)
rospy.on_shutdown(self.shutdown)
velpub = rospy.Publisher('/gl/cmd_vel',Twist, queue_size=10)
rate = rospy.Rate(20)
while not rospy.is_shutdown():
rate.sleep()
if self.cmd:
velpub.publish(self.cmd)
def shutdown(self):
rospy.loginfo('shut down now..')
def callback(self,data):
rospy.loginfo(data)
ccmd = Twist()
if data.buttons[4] ==1 or data.buttons[6] ==1: #go line
if data.buttons[4] ==1:
ccmd.linear.x = 1
else:
ccmd.linear.x = -1
else:
ccmd.linear.x = 0
if data.buttons[5] ==1 or data.buttons[7] ==1: #rotate
if data.buttons[7] ==1:
ccmd.angular.z = 0.6
else:
ccmd.angular.z = -0.6
else:
ccmd.angular.z = 0
self.cmd = ccmd
if __name__ == '__main__':
Ps3Learning()
<launch>
<node pkg="learning_ps3joy" type="listener.py" name="learningPs3">
<remap from="/gl/cmd_vel" to="/turtle1/cmd_vel"/>
<remap from="/gl/joy" to="/joy"/>
</node>
<node pkg="joy" type="joy_node" name="joystick"/>
</launch>
然后我早上摇了半天。。