1.首先安装joy这个节点,通过
sudo apt-get install ros-kinetic-joy
2.配置JoyStick
ls /dev/input/
你会看到
by-id event1 event12 event15 event18 event3 event6 event9 mouse0
by-path event10 event13 event16 event19 event4 event7 js0 mouse1
event0 event11 event14 event17 event2 event5 event8 mice mouse2
js0即为罗技键盘输入
3.测试
sudo jstest /dev/input/js0
即可看到各通道的值以及按钮的通断情况
4.使用
赋值权限
sudo chmod a+rw /dev/input/js0
启动ROS驱动节点
roscore
rosparam set joy_node/dev "/dev/input/js0"
rosrun joy joy_node
接收ROS( sensor_msgs/Joy)消息
rostopic echo joy
5.将其应用到ROS
安装turtlebot_teleop包
sudo apt-get install ros-kinetic-turtlebot-teleop
然后将/opt/ros/kinetic/share/turtlebot_teleop/launch文件夹里面的logitech.launch文件修改为
<!--
Driver for the logitech rumblepad2 joystick.
Use the D pad while pressing and holding the left trigger button (5) to control.
-->
<launch>
<!-- smooths inputs from cmd_vel_mux/input/teleop_raw to cmd_vel_mux/input/teleop -->
<include file="$(find turtlebot_teleop)/launch/includes/velocity_smoother.launch.xml"/>
<node pkg="turtlebot_teleop" type="turtlebot_teleop_joy" name="turtlebot_teleop_joystick">
<param name="scale_angular" value="1.5"/>
<param name="scale_linear" value="0.5"/>
<param name="axis_deadman" value="4"/>
<param name="axis_linear" value="5"/>
<param name="axis_angular" value="4"/>
<remap from="turtlebot_teleop_joystick/cmd_vel" to="/xqserial_server/Twist"/>
</node>
<node pkg="joy" type="joy_node" name="joystick">
<param name="dev" type="string" value="/dev/input/js0" />
</node>
</launch>
6.安装蓝鲸小强驱动代码(编译前请切到轮毂电机)
cd ~/catkin_ws/src
git clone https://github.com/BlueWhaleRobot/xqserial_server.git
git checkout lungu
cd ..
catkin_make
修改其xqserial.launch文件
原
<launch>
<node pkg="xqserial_server" type="xqserial_server" name="motor_driver">
<param name="debug_flag" value="false"/>
<param name="wheel_separation" value="0.360"/>
<param name="wheel_radius" value="0.0825"/>
<param name="max_speed" value="5.0"/>
<param name="port" value="/dev/ttyUSB001"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="baselink_broadcaster" args="0 0 0.15 0 0 0 1 base_footprint base_link 50">
</node>
<node pkg="tf" type="static_transform_publisher" name="baselinkSonar_broadcaster1" args="0.135 -0.130 0.24 0 0 0 base_link sonar1 50"/>
<node pkg="tf" type="static_transform_publisher" name="baselinkSonar_broadcaster2" args="0.135 0.130 0.24 0 0 0 base_link sonar2 50"/>
<node pkg="tf" type="static_transform_publisher" name="imulink_broadcaster" args="0.07 -0.03 0 0 0 0 1 base_link imu 50"/>
</launch>
改: wheel_radius:轮子半径,wheel_separation:两轮轴距,max_speed:最大线速度,
<launch>
<node pkg="xqserial_server" type="xqserial_server" name="motor_driver">
<param name="debug_flag" value="false"/>
<param name="wheel_separation" value="0.360"/>
<param name="wheel_radius" value="0.0825"/>
<param name="max_speed" value="5.0"/>
<param name="port" value="/dev/ttyUSB0"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="baselink_broadcaster" args="0 0 0.15 0 0 0 1 base_footprint base_link 50">
</node>
<node pkg="tf" type="static_transform_publisher" name="baselinkSonar_broadcaster1" args="0.135 -0.130 0.24 0 0 0 base_link sonar1 50"/>
<node pkg="tf" type="static_transform_publisher" name="baselinkSonar_broadcaster2" args="0.135 0.130 0.24 0 0 0 base_link sonar2 50"/>
<node pkg="tf" type="static_transform_publisher" name="imulink_broadcaster" args="0.07 -0.03 0 0 0 0 1 base_link imu 50"/>
</launch>