ROS环境--构建gamepad 环境

用键盘控制小乌龟

转自:https://blog.csdn.net/u014587147/article/details/75673110

小乌龟控制的msg数据格式:

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

用graph查看ROS的节点和msg
rqt_graph
在这里插入图片描述
查看一下ROS上的话题:rostopic list

/rosout
/rosout_agg
/statistics
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose

查看turtlesim定义的消息类型:rostopic info /turtle1/cmd_vel

Type: geometry_msgs/Twist
Publishers:

  • /teleop_turtle (http://expect-GE62-2QC:37025/)

Subscribers:

  • /turtlesim (http://expect-GE62-2QC:40027/)

查看Twist的数据类型:rosmsg show geometry_msgs/Twist

geometry_msgs/Vector3 linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z

所以需要重新创建一个node,接受joy的数据,并且订阅/cmd_vel这个topic,使用Twist这个消息控制机器人运动。

手柄的控制指令

我购买的是sony ps4 游戏手柄,先在windows 下验证手柄的类型。通过steam上,进行验证。
https://jingyan.baidu.com/article/1876c8522d6b31890b1376cf.html
查看手柄可以操作的命令:

sudo jstest /dev/input/js0
Axes:  0:     0  1:     0  2:-32767  3:     0  4:     0  5:-32767  6:     0  7:     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

在ubuntu 上需要下载ds4drv才能让ps4 正常工作
安装方法使用:https://github.com/chrippa/ds4drv
然后使用ds4drv进行检测(实验证明如果只有一个游戏手柄时,不需要按住PS4上的share和hold上面)

sudo ds4drv --hidraw

使用jstest-gtk检测遥控器是否正常工作,查看使用的手柄对应的是js_X_(默认是0)

使用ps4 node测试

修改js_X_的权限

chmod a+rw /dev/input/js_X_

从git下载ps4_node:https://github.com/solbach/ps4-ros
将下载的文件夹复制~/catkin_ws/src/
在~/catkin_ws/ 进行$catkin_make -j4 对ps4_node进行编译
查看ps4 node,并且查看一下/joy 这个topic是否现在记录手柄的数据
在这里插入图片描述

rostopic echo /joy   #查看topic的内容,通过验证,

/joy已经能获取PS4的数据,现在需要知道PS4_ROS是否产生/TUrtle1/cmd_vel相同类型的message

Node [/PS4_ROS]
Publications:

  • /rosout [rosgraph_msgs/Log]
  • /searchbot/p3at/vel_cmd [geometry_msgs/Twist]

Subscriptions:

  • /joy [sensor_msgs/Joy]

Services:

  • /PS4_ROS/get_loggers
  • /PS4_ROS/set_logger_level

contacting node http://expect-GE62-2QC:42771/ …
Pid: 11572
Connections:

  • topic: /rosout
    * to: /rosout
    * direction: outbound
    * transport: TCPROS
  • topic: /joy
    * to: /joy_node (http://expect-GE62-2QC:44569/)
    * direction: inbound
    * transport: TCPROS

根据验证:/PS4_ROS已经产生了vel_cmd的消息

思路

只需要修改ps4_ros中的topic名称即可,修改成/turtle1/cmd_vel.
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值