TUTORIAL 7: Erle-Brain SLAM (Simultaneous Localization and Mapping)

Blockly is a ROS package that provides web-based visualization and block programming tools for robots and drones.

In order to move the spider while creating the map, 'Avoid Obstacles' function is used. Those blocks are the same used in the sixth tutorial.

The workspace is a simple infinite loop where 'SLAM' and 'Avoid Obstacles' blocks are executed secuentially.

Latest SLAM image can be visualized at /pages/maps/imageViewer.html .

Notes: load the corresponding laser initialization block before using the SLAM block.

The following code initializes hector_mapping and hector_geotiff nodes which are in charge of creating the map and saving the image with the trajectory. Further explanation in the configuration section below.

After that .tif image is converted to .png using OpenCv.

Finally old files are removed.

imports ...
# Ros Messages   
from sensor_msgs.msg import CompressedImage

ros_nodes = rosnode.get_node_names()
if not '/hector_mapping' in ros_nodes:
    command='roslaunch hector_mapping mapping_default.launch'
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
if not '/hector_geotiff_node' in ros_nodes:
    command='roslaunch hector_geotiff geotiff_mapper.launch'
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)

rospack = rospkg.RosPack()
tiff_path = rospack.get_path('robot_blockly') + '/frontend/pages/maps/'

pub_img = rospy.Publisher('syscommand', String, queue_size=10, latch=2)

for img in glob.glob(tiff_path+"*.tif"):
    im_name = img.replace('tif', 'png')
    cv_img = cv2.imread(img)
    cv2.imwrite(im_name, cv_img)

os.system("ls -t "+tiff_path+"*tfw | tail -n +2 | xargs rm --")#remove all tfw but latest
os.system("ls -t "+tiff_path+"*tif | tail -n +2 | xargs rm --")#remove all tif but latest
os.system("ls -t "+tiff_path+"*png | tail -n +2 | xargs rm --")#remove all png but latest

Hector_slam is the ros package we used here, information about the packages needed can be found here:



You will need to install the following packages inside each container:

hector_compressed_map_transport, hector_geotiff, hector_geotiff_plugins, hector_map_tools, hector_mapping, hector_nav_msgs, hector_slam, hector_slam_launch, hector_trajectory_server, hector_worldmodel, hector_worldmodel_geotiff_plugins, hector_worldmodel_msgs

Once the packages have been built successfully, the following changes need to be made:


-  <arg name="base_frame" default="base_footprint"/>
-  <arg name="odom_frame" default="nav"/>
+  <arg name="base_frame" default="laser"/>
+  <arg name="odom_frame" default="laser"/>


-  <arg name="trajectory_source_frame_name" default="/base_link"/>
+  <arg name="trajectory_source_frame_name" default="laser"/>

-  <arg name="map_file_path" default="$(find hector_geotiff)/maps"/>
+  <arg name="map_file_path" default="$(find robot_blockly)/frontend/pages/maps"/>

If you are installing the packages make sure you build these two again.

Notice that 'laser' is the frame_id specified by the urg_node package used to control the Hokuyo laser.

blockly comes preinstalled in Erle-Brain 2.0. Acquire this artificial brain for making robots and drones here