[PYTHON] Try running Kobuki's 3D simulator on ROS

It is a continuation from Try running ROS sample easily on a virtual machine. Let's run Kobuki (a robot like Rumba) 3D simulator in Gazebo. (The black one in ↓ moves) Finally, I'm becoming more like a robot.

スクリーンショット 2016-12-16 3.19.16.png

Installation of kobuki simulator

Add Gazebo repository

I installed it to the end and started it, but the version did not match and I could not start it. Refer to the following and add and update the repository first. Reference: Problem with Indigo and Gazebo 2.2 --ROS Answers: Open Source Q & A Forum

$ sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu trusty main" > /etc/apt/sources.list.d/gazebo-latest.list'
$ wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
$ sudo apt-get update

Installation

$ sudo apt-get install -y ros-indigo-kobuki-gazebo

Start (command confirmation only)

At the end, it starts all at once, so for now, just check the commands.

$ roslaunch kobuki_gazebo kobuki_playground.launch

Creating an operation program

Creating a package template

Create a package template as follows. kobuki_sample is arbitrary because it is the name of the package to be created. rospy and std_msgs specify dependent packages, but you can add them later so you don't have to worry too much.

$ cd ~/catkin_ws/src
$ catkin_create_pkg kobuki_sample rospy std_msgs

catkin_make

$ cd ~/catkin_ws
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash

Creating an operation program

It seems to be a good idea to put the source code under <package> / scripts.

$ mkdir -p ~/catkin_ws/src/kobuki_sample/scripts
$ roscd kobuki_sample/scripts
$ vi sample.py

The program below is a slightly modified version of the program in the following books. By the way, it is a BSD license. Amazon is highly rated, and it's actually an easy-to-read and easy-to-understand introductory book. Recommended.

 ROS Robot Programming Beginning with-Free Robot Robot programming started with ROS-a "framework" for free robots ( I ・ O BOOKS)
Takashi Ogura

Engineering Co., Ltd. 2015-06-25
Sales Ranking: 15436

See details on Amazon by G-Tools >

sample.py


#!/usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

# Node name
rospy.init_node("sample")

# Topic   : /mobile_base/commands/velocity
# Type    : Twist
# Options : queue_size=10
pub = rospy.Publisher("/mobile_base/commands/velocity", Twist, queue_size=10)

# Loop while not shutdown
while not rospy.is_shutdown():
	# construct Twist object
	vel  = Twist()
	
	# wait user input
	direction = raw_input("f: forward, b: backward, l: left, r: right q: quit > ")
	
	# decode commands
	if "f" in direction:
		vel.linear.x = +0.5 # forward
	
	if "b" in direction:
		vel.linear.x = -0.5 # backward
	
	if "l" in direction:
		vel.angular.z = +1.0 # rotate left
	
	if "r" in direction:
		vel.angular.z = -1.0 # rotate right
	
	if "q" in direction:
		break # quit program
	
	# print detail
	print vel
	
	# publish
	pub.publish(vel)

Give execute permission

$ roscd kobuki_sample/scripts
$ chmod 755 sample.py

Try running the simulator

Execute the following in the GUI environment.

$ roslaunch kobuki_gazebo kobuki_playground.launch

Execute the following in another terminal.

$ roscd kobuki_sample/scripts
$ ./sample.py

It works when you do fl or rb.

By the way

As a continuation of Try running the ROS sample easily on a virtual machine, install the Kobuki simulator and operation program on another host as shown below. I tried it, but it worked without any additional settings. It is convenient to do something good behind the scenes.

--192.168.33.10: Installation of Kobuki simulator --192.168.33.11: Creating an operation program