linux安装xbox无线手柄,ROS配置和使用Xbox One无线手柄
標(biāo)簽:
ROS配置和使用Xbox One無線手柄
環(huán)境:Ubuntu16.04 + ROS kinetic
安裝joy package
joy package為通用的Linux操縱桿提供了ROS驅(qū)動(dòng),它包括了一個(gè)joy_node節(jié)點(diǎn),可以讓Linux操縱桿和ROS交互.這個(gè)節(jié)點(diǎn)發(fā)布一個(gè)”Joy”消息,包含了操縱桿每一個(gè)按鈕和軸的當(dāng)前狀態(tài).
安裝這個(gè)joy package:
$ sudo apt-get install ros-kinetic-joy
配置Xbox One無線手柄
安裝好后先用usb線將手柄與電腦連接,測試有線連接的情況下,Linux是否能夠識(shí)別你的游戲手柄.
$ ls /dev/input/
你會(huì)看到所有輸入設(shè)備的列表,如果出現(xiàn)了jsX的話(在我的電腦中顯示的是js0),說明Linux成功識(shí)別了你的游戲手柄.
下面對(duì)手柄進(jìn)行測試:
sudo jstest /dev/input/jsX
你會(huì)在終端中看到手柄的輸出信息,移動(dòng)手柄的可以看到數(shù)據(jù)的變化.
Axes: 0: 1982 1: 894 2:-32767 3: 392 4: 438 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
每個(gè)按鈕和軸對(duì)應(yīng)的索引可以在http://wiki.ros.org/joy查到,當(dāng)然也可以直接試出來.
接下來,要讓ROS的節(jié)點(diǎn)joy_node可以使用手柄,我們需要更改手柄的權(quán)限.
$ ls -l /dev/input/jsX
你會(huì)看到跟這樣類似的輸出:
crw-rw-XX-+ 1 root input 13, 0 9月 12 14:45 /dev/input/js0
如果XX是rw的話,說明設(shè)備配置成功.
如果XX是–或者其他的話,說明沒有配置成功,你需要:
$ sudo chmod a+rw /dev/input/jsX
啟動(dòng)joy_node節(jié)點(diǎn)
要使手柄的數(shù)據(jù)發(fā)布在ROS上,我們需要啟動(dòng)joy package中的joy_node節(jié)點(diǎn).首先,我們需要將設(shè)備名這個(gè)參數(shù)設(shè)置為當(dāng)前的設(shè)備名,默認(rèn)為js0.
$ roscore
$ rosparam set joy_node/dev "/dev/input/jsX"
然后可以啟動(dòng)joy_node這個(gè)節(jié)點(diǎn):
$ rosrun joy joy_node
終端的輸出如下:
然后在新的終端用rostopic echo查看joy這個(gè)話題的數(shù)據(jù):
rostopic echo joy
移動(dòng)你的手柄,你會(huì)看到數(shù)據(jù)在不斷變化,說明你的手柄有線配置成功.
藍(lán)牙無線連接
打開Ubuntu16.04的藍(lán)牙,找到Xbox Wireless Controller連接.
如果藍(lán)牙連上之后馬上掉線的話,可以嘗試一下步驟:
在終端中運(yùn)行下面的命令
sudo apt-get update
sudo apt-get install build-essential linux-headers-generic
下載這個(gè)repo的zip文件,解壓到桌面
將終端的當(dāng)前工作目錄更改為解壓的目錄
在終端運(yùn)行以下命令
make
sudo make install
sudo cp -r ~/Desktop/rtbth-dkms /usr/src/rtbth-3.9.3
sudo apt-get install dkms
sudo dkms install rtbth/3.9.3
sudo nano /etc/modules
修改/etc/modules文件,添加這一行
rtbth
退出,重啟
測試和校準(zhǔn)
jstest-gtk是一個(gè)可以測試手柄的工具,可以顯示哪個(gè)按鈕和軸被按下,可以校準(zhǔn)和重新為手柄設(shè)置每個(gè)按鈕的索引
安裝jstest-gtk:
sudo apt-get install jstest-gtk
在終端輸入以下命令,打開jstest-gtk的GUI:
$ jstest-gtk
點(diǎn)擊屬性按鈕,可以進(jìn)行測試
Xbox One手柄無線控制turtlesim中的小龜
在catkin工作空間創(chuàng)建一個(gè)package
$ cd ~/catkin_ws/src
$ catkin_create_pkg learning_joy roscpp turtlesim joy
$ cd ~/catkin_ws/
$ catkin_make
寫一個(gè)節(jié)點(diǎn)
在learning_joy/src/下創(chuàng)建一個(gè)文件turtle_teleop_joy.cpp.
#include
#include
#include
// create the TeleopTurtle class and define the joyCallback function that will take a joy msg
class TeleopTurtle
{
public:
TeleopTurtle();
private:
void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
ros::NodeHandle nh_;
int linear_, angular_; // used to define which axes of the joystick will control our turtle
double l_scale_, a_scale_;
ros::Publisher vel_pub_;
ros::Subscriber joy_sub_;
};
TeleopTurtle::TeleopTurtle(): linear_(1), angular_(2)
{
// initialize some parameters
nh_.param("axis_linear", linear_, linear_);
nh_.param("axis_angular", angular_, angular_);
nh_.param("scale_angular", a_scale_, a_scale_);
nh_.param("scale_linear", l_scale_, l_scale_);
// create a publisher that will advertise on the command_velocity topic of the turtle
vel_pub_ = nh_.advertise<:twist>("turtle1/cmd_vel", 1);
// subscribe to the joystick topic for the input to drive the turtle
joy_sub_ = nh_.subscribe<:joy>("joy", 10, &TeleopTurtle::joyCallback, this);
}
void TeleopTurtle::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
geometry_msgs::Twist twist;
// take the data from the joystick and manipulate it by scaling it and using independent axes to control the linear and angular velocities of the turtle
twist.angular.z = a_scale_*joy->axes[angular_];
twist.linear.x = l_scale_*joy->axes[linear_];
vel_pub_.publish(twist);
}
int main(int argc, char** argv)
{
// initialize our ROS node, create a teleop_turtle, and spin our node until Ctrl-C is pressed
ros::init(argc, argv, "teleop_turtle");
TeleopTurtle teleop_turtle;
ros::spin();
}
編譯和運(yùn)行
在CMakeLists.txt中加入以下行:
add_executable(turtle_teleop_joy src/turtle_teleop_joy.cpp)
target_link_libraries(turtle_teleop_joy ${catkin_LIBRARIES})
創(chuàng)建一個(gè)launch文件夾,并新建一個(gè)launch文件turtle_joy.launch.
type="joy_node" name="turtle_joy" >
不能忘了,還要catkin_make一下.
最后一步,launch!
$ roslaunch learning_joy turtle_joy.launch
移動(dòng)游戲手柄,可以看到小龜在移動(dòng).
參考資料
歡迎關(guān)注我的公眾號(hào)
標(biāo)簽:
來源: https://blog.csdn.net/weixin_38501796/article/details/82669944
總結(jié)
以上是生活随笔為你收集整理的linux安装xbox无线手柄,ROS配置和使用Xbox One无线手柄的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单位弹性需求曲线形状_2021经济学考研
- 下一篇: 系统服务器Fedora和Red Hat