LIFE LOG(ここにはあなたのブログ名)

あつあつ備忘録

ソフトやハード、時にはメカの備忘録をまとめていきます

【ROS】シミュレータでロボット駆動

f:id:AtsuyaKoike:20190421152613p:plain
画像元

$ sudo apt-get install -y ros-kinetic-kobuki-gazebo
$ roslaunch kobuki_gazebo kobuki_playground.launch 

f:id:AtsuyaKoike:20190507150750p:plain

$ 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

f:id:AtsuyaKoike:20190507150617p:plain