【ROS】シミュレータでロボット駆動
$ sudo apt-get install -y ros-kinetic-kobuki-gazebo $ roslaunch kobuki_gazebo kobuki_playground.launch
$ vi vel_publisher.py
#!/usr/bin/env python import rospy from geometry_msgs.msg import Twist #Used for robot speed command rospy.init_node( 'vel_publisher' ) #node name # Topicname : /mobile_base/commands/velocity # Type : Twist pub = rospy.Publisher( '/mobile_base/commands/velocity', Twist, queue_size = 10 ) while not rospy.is_shutdown(): vel = Twist() # keybord inputs direction = raw_input( 'f: forward, b: backward, l: left, r: right >' ) if 'f' in direction: vel.linear.x = 0.5 if 'b' in direction: vel.linear.x = -0.5 if 'l' in direction: vel.angular.z = 1.0 if 'r' in direction: vel.angular.z = -1.0 if 'q' in direction: break print vel pub.publish(vel)
$ chmod 755 vel_publisher.py $ ./vel_publisher.py f: forward, b: backward, l: left, r: right >f linear: x: 0.5 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0 f: forward, b: backward, l: left, r: right >fr linear: x: 0.5 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: -1.0