Environment and ready
- Ubuntu 16.04 (blogger is VM virtual machine)
- kinetic version of the ROS platform
- Handle (blogger is Sony's PS4 handle)
- Something on this blog can realize simulation robot ready
First, the connection handle
if you are using a VM virtual machine, after connecting the handle, there may be prompted to connect the hardware. Without prompt you need to find in the lower right corner of your VM handle, if the handle is bright already connected. If not, click on the icon handle, click connections on it.
If you are prompted not connected, first check whether the VM to the latest version
after the update is complete, then update Tools
click on 更新 VMware Tools
the pop-up window, the inside of the archive decompression to a home inside, then run inside the terminal
sudo ./vmware-install.pl
and then has been Enter on the line, and finally restart under VM, find the handle in the lower right corner, connect virtual machines to see if it was successful.
Second, write Python programs handle control
After connecting the handle /dev/input
should appear in js0
this document, this is the handle device, evdev Python's module can read event. But here we have a complete package of ROS nodes, joy_node node Joy bag.
rosrun joy joy_node #启动joy_node
rostopic echo joy #然后我们监听这个节点,看看有没有输出手柄事件
These are joy_node transmission data format
header #Header 类型
axes #摇杆数据
buttons #按钮数据
This data is sensor_msgs / msg / Joy.msg this msg file format.
Now that we have a handle data, then only need to handle data sent to the car simulation node, can make the car move.
This time we still use rbx_vol_1 as car simulation, it is unclear friends can look uppermost Article preparation work .
Want to make the car move rbx_vol_1 in simulation, we need to know the type of car moving Msg received, we start the simulation robot
roscore
roslaunch rbx1_bringup fake_pi_robot.launch
rosrun rqt_graph rqt_graph
You will see an icon like this
Obviously our car node arbotic subscribed cmd_vel topic (topic), we only need to look at msg cmd_vel what type of transmission is on the line.
rostopic type cmd_vel #查看cmd_vel 类型
Output geometry_msgs/Twist
, and then looking at specific types
rosmsg info geometry_msgs/Twist
The next job is to write Python node.
#!/usr/bin/env python3#我用的是python3,如果你用的是2,删掉3就行了
#coding=utf-8
import rospy
from sensor_msgs.msg import Joy
from geometry_msgs.msg import Twist
class JoyRob():
"""docstring for JoyRob"""
listener_joy = None#监听joy话题
talker_rob = None#向机器人话题发布数据
joy_msg = None
def __init__(self):
self.theNode = rospy.init_node('wtmsb')
self.listener_joy = rospy.Subscriber('joy',Joy,self.callback)
self.talker_rob = rospy.Publisher('cmd_vel',Twist,queue_size=10)
self.rate = rospy.Rate(50) # 定义hz
while not rospy.is_shutdown():
self.publish()
self.rate.sleep()
def publish(self):
if self.joy_msg:
self.talker_rob.publish(self.joy_msg)
def callback(self,date):
cmd = Twist()
cmd.linear.x = date.axes[3]#axes是摇杆数据
cmd.linear.y = date.axes[4]#右摇杆控制移动
cmd.angular.z = date.axes[0]#左摇杆用来控制方向
cmd.angular.y = date.axes[1]
self.joy_msg = cmd
if __name__ == '__main__':
JoyRob()
Because we use in Python scripts
from sensor_msgs.msg import Joy
from geometry_msgs.msg import Twist
So we want to CMakeLists.txt modify something in the file
add these two dependencies, and then re-catkin_make on the line.
Third, run
roscore
rosrun joy joy_node
roslaunch rbx1_bringup fake_pi_robot.launch
rosrun 你的工作空间 刚写的节点名称.py#运行刚写好的Python节点
rosrun rviz rviz -d `rospack find rbx1_nav`/sim.rviz
Not surprisingly, you should see the simulation robot rviz
Push joystick left and right can make the robot move up