새소식

ROS & Robotics

Height map 을 이용하여 Gazebo world 구성하기

  • -

Heightmap 은 지형의 높이 정보를 저장하는 이미지입니다. 이 이미지는 픽셀의 흑백 값으로 표현됩니다. 밝을 수록 지형이 높아지고, 어두울 수록 낮은 지형을 뜻합니다. 

Heightmap 예시

Gazebo world 의 sdf 파일에서는 Heightmap 을 이용해서 지형을 모델링할 수 있습니다. 

 

1) Heightmap 사용을 위한 이미지 생성

import os import numpy as np from PIL import Image # 이미지 크기와 sin 함수의 주기, 진폭, 위상 등을 설정 width = 129 height = 129 period = 10 amplitude = 0.1 phase = 0 y, x = np.indices((height, width)) data = amplitude * np.sin(2 * np.pi * (1.0 / period) * x + phase) img = Image.fromarray(np.uint8(data * 255)) path = os.path.expanduser('/usr/share/gazebo-11/media/sin_wave.png') img.save(path)

 

이 코드를 실행하면 다음과 같은 이미지가 생성됩니다. 이때 주의할 것은 크기가 129x129 사이즈여야, sdf 파일로 불러왔을 때 정상적으로 지형이 생성됩니다. (왠지는 아직 잘 모르겠...)

 

2) Gazebo 에 불러오기

 

Gazebo 에서 불러올 수 있는 world 는 /usr/share/gazebo/media 에 저장할 수 있습니다. 

ㄴ gazebo-11 ㄴ models ㄴ sin_wave ㄴ model.config ㄴ model.sdf

이와 같이 구성하면 Gazebo 환경에서 모델을 불러올 수 있습니다. 이때 model.sdf 에서 아까 만든 사진을 불러오도록 uri 부분만 수정해 주면 됩니다. 

 

model.config

<?xml version="1.0"?> <model> <name>Sine Wave</name> <version>1.0</version> <sdf version="1.5">model.sdf</sdf> <author> <name>zzziito</name> </author> <description> sine-wave ground </description> </model>

 

model.sdf

<?xml version="1.0" ?> <sdf version="1.5"> <model name="heightmap"> <static>true</static> <link name="link"> <collision name="collision"> <geometry> <heightmap> <uri>file://media/sin_wave.png</uri> <size>10 10 0.1</size> <pos>0 0 0</pos> </heightmap> </geometry> <surface> <contact> <collide_bitmask>0xffff</collide_bitmask> </contact> </surface> </collision> <visual name="visual"> <geometry> <heightmap> <use_terrain_paging>false</use_terrain_paging> <texture> <diffuse>file://media/materials/textures/dirt_diffusespecular.png</diffuse> <normal>file://media/materials/textures/flat_normal.png</normal> <size>1</size> </texture> <texture> <diffuse>file://media/materials/textures/grass_diffusespecular.png</diffuse> <normal>file://media/materials/textures/flat_normal.png</normal> <size>1</size> </texture> <texture> <diffuse>file://media/materials/textures/fungus_diffusespecular.png</diffuse> <normal>file://media/materials/textures/flat_normal.png</normal> <size>1</size> </texture> <blend> <min_height>2</min_height> <fade_dist>5</fade_dist> </blend> <blend> <min_height>4</min_height> <fade_dist>5</fade_dist> </blend> <uri>file://media/sin_wave.png</uri> <size>10 10 0.1</size> <pos>0 0 0</pos> </heightmap> </geometry> </visual> </link> </model> </sdf>

그러면, 이와 같이 sine wave 모델의 높낮이를 가지는 바닥을 생성할 수 있습니다. 

 

이를 다양하게 응용하면 원하는 형태의 지면을 생성할 수 있습니다. 

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.