HAPTIX Simulation World API - modulabs/gazebo-tutorial GitHub Wiki
์ด ํํ ๋ฆฌ์ผ์์๋ haptix-comm simulation-specific API์ ์ ๋ฐ์ ์ธ ๋ด์ฉ์ ๋ค๋ฃฌ๋ค.
์ค์น ๋จ๊ณ๋ ์๋ฃํ๋ค๊ณ ๊ฐ์ ํ๋ค.
API ๋ฌธ์๋ ์ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ๋ผ.
3์ฐจ์ ์ขํ ๋ฐ ํ์ ์ ๋ํ '๋ณํ'์ pose๋ผ๊ณ ํ๋ค. world API์์ ํ์ ์ ์ฟผํฐ๋์์ผ๋ก ์ค๋ช ํ๋ค.
๋ฌธ์๋ฅผ ํตํด "๋งํฌ", "์กฐ์ธํธ"๋ฐ "๋ชจ๋ธ"์ ์ฐธ์กฐํ๋ค.
"๋งํฌ"๋ ์ ์ฒด๊ฐ ์์ง์ด๋ ๊ฐ์ฒด์ด๋ค.
"์กฐ์ธํธ"๋ ๋ ๊ฐ์ ๋งํฌ๋ฅผ ๊ฒฐํฉ์ํค๊ณ ๋ชจ์ ์ ์ ํํ๋ค. ์กฐ์ธํธ๋ ํ๊ณ๋ฅผ ์ง ์ ์๋ค.
"๋ชจ๋ธ"์ 0๊ฐ ์ด์์ ๋งํฌ์ ์กฐ์ธํธ๋ก ๊ตฌ์ฑ ๋ ์ ์๋ ๊ฐ์ฒด์ด๋ค. ์ด ์์ ์ ๋๋ถ๋ถ์ ๊ฐ์ฒด์๋ ๋๋ฌด ํ๋ธ์ ํฌ๋ฆฌ์ผ ๋ณผ๊ณผ ๊ฐ์ ํ๋์ ๋งํฌ์ 0๊ฐ์ ์กฐ์ธํธ๋ก ๋์ด์๋ค. ๊ทธ๋ฌ๋ ๋ก๋ด ์ธ๊ณต ํ์ ๋ง์ ๋งํฌ์ ๊ด์ ์ด์๋ ๋ชจ๋ธ์ ํ ์์ด๋ค.
์๋ฅผ ๋ค์ด, ์ผ๋ฐ์ ์ธ ์ถ์ ๊ตฌ์๋ ์ธ ๊ฐ์ ๋งํฌ๊ฐ ์๋ค: ๊ณ ์ ๋ ํ๋ ์, ๋ฌธ ์์ฒด, ๊ทธ๋ฆฌ๊ณ ํธ๋ค. ํ๋ ์๊ณผ ๋ฌธ์ ์ฐ๊ฒฐํ๋ ๊ฒฝ์ฒฉ์ ๋ฌธ์ ํ์ ์ํฌ ์ ์๋ ์กฐ์ธํธ๋ก ๋ชจ๋ธ๋ง๋๋ค. ๋ง์ฐฌ๊ฐ์ง๋ก ๋ฌธ๊ณผ ์์ก์ด๋ ์์ก์ด๋ฅผ ๋๋ฆด ์์๋ ์กฐ์ธํธ๋ก ์ฐ๊ฒฐ๋๋ค. ์ถ์ ๊ตฌ๋ ์ ์ฒด์ ์ผ๋ก ๋ชจ๋ธ๋ก ๊ตฌ์ฑ๋๋ค.
์ด ์์ ์์๋, ARAT world์์ ๋ฌผ์ฒด๋ฅผ ์กฐ์ํ๊ธฐ ์ํด world API๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋ค.
HAPTIX MATLAB SDK์๋ ์ด ์์ ์์ ์ฌ์ฉ ๋ hxs_example.m ์คํฌ๋ฆฝํธ๊ฐ ์ด๋ฏธ ํฌํจ๋์ด ์๋ค. ๋ง์ฝ ์ด๋์ํค๊ฑฐ๋ ์ญ์ ํ ๊ฒฝ์ฐ ์ฌ๊ธฐ์์ ๋ค์ด๋ก๋ ํ ์ ์๋ค. ๋ค์ ๋ค์ด๋ก๋ํด์ผํ๋ ๊ฒฝ์ฐ ์คํฌ๋ฆฝํธ๋ฅผ HAPTIX MATLAB SDK๊ฐ ํฌํจ ๋ ํด๋ ๋ MATLAB ๊ฒฝ๋ก์ ์์น์์ผ์ผํ๋ค.
์์ ๋ฅผ ์คํํ๋ ค๋ฉด ๋จผ์ Gazebo๊ฐ ์คํ ์ค์ธ์ง ํ์ธํ๋ค (๋ฐํ ํ๋ฉด ์์ด์ฝ์ ๋ ๋ฒ ํด๋ฆญํ๊ฑฐ๋ ํฐ๋ฏธ๋์ ์ฌ์ฉํ๋ฉด ๋๋ค).
MATLAB์ ์ด๊ณ HAPTIX SDK ํด๋๋ก ์ด๋ํ ๋ค์ hxs_example์ ๋ช
๋ น ํ๋กฌํํธ์ ์
๋ ฅํ๋ค.
๊ฐ ์์ API ํธ์ถ์ ํตํด ์คํฌ๋ฆฝํธ๊ฐ ์คํ๋ ๋ Gazebo ์ฐฝ์ ๋ณด์๋ผ.
Linux์์ haptix-comm ํจํค์ง๋ฅผ ์ค์นํ๋ฉด /usr/lib/x86_64-linux-gnu/haptix-comm์ ์ฅํ๋ธ ํด๋๊ฐ ์ค์น๋๋ค. ์ด ํด๋์๋ ์ด ์ค์ต์์ ์ฌ์ฉ ๋ hxs_example ์คํฌ๋ฆฝํธ๊ฐ ๋ค์ด์๋ค. ์ด๋ํ๊ฑฐ๋ ์ญ์ ํ ๊ฒฝ์ฐ ์ฌ๊ธฐ์์ ๋ค์ด๋ก๋ ํ ์ ์๋ค.
์์ ๋ฅผ ์คํํ๋ ค๋ฉด ๋จผ์ Gazebo๊ฐ ์คํ ์ค์ธ์ง ํ์ธํ๋ค (๋ฐํ ํ๋ฉด ์์ด์ฝ์ ๋๋ฒ ํด๋ฆญํ๊ฑฐ๋ ํฐ๋ฏธ๋์ ์ฌ์ฉํ์ฌ๋ผ).
ํฐ๋ฏธ๋์์ ์์ ์ธ๊ธ ํ haptix-comm/octave ํด๋๋ก ์ด๋ํ์ฌ octave hxs_example.m์ ์
๋ ฅํ๋ค.
๊ฐ ์์ API ํธ์ถ์ ํตํด ์คํฌ๋ฆฝํธ๊ฐ ์คํ๋ ๋ Gazebo ์ฐฝ์ ๋ณด์๋ผ.
ํ์ฌ ์นด๋ฉ๋ผ ๋ณํ๊ณผ ์๋ฎฌ๋ ์ด์ ์์ ๋ชจ๋ ๋ชจ๋ธ ๋ชฉ๋ก์ ํฌํจํ๋ ์๋ฎฌ๋ ์ด์ ์ ๋ณด๋ฅผ ๊ฒ์ํ๋ค. ์ด API ํธ์ถ์ ์๋ฎฌ๋ ์ด์ ์ ๋ชจ๋ ๋ชจ๋ธ์ ๋ฐ๋ณต์ ๊ทผํ๊ธฐ์ ์ข์ ์์์ ์ด๋ค.
info = hxs_sim_info();
์ด ์์ ์์๋ ๊ฒฐ๊ณผ ์ ๋ณด ๊ตฌ์กฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ world์ ๋ชจ๋ ๋ชจ๋ธ์ ๋ฐ๋ณต์ ๊ทผํ์ฌ ๋ชจ๋ ๋ชจ๋ธ, ๋งํฌ ๋ฐ ์กฐ์ธํธ์ ์ด๋ฆ์ ํ์ํ๋ค. ์ด ๋ฃจํ์์๋ ์์น, ์๋ ๋ฐ ๋ด/์ธ๋ถ ํ/ ํ ํฌ์ ๊ฐ์ ํ์ฌ ๋์ ์ํ์ ๋ํ ๋งํฌ์ ์ ํฉ์ ์์ฒญ ํ ์๋ ์๋ค.
์๋ฎฌ๋ ์ด์ ์นด๋ฉ๋ผ ๊ฐ๋์ ์์น์ ๋ฐฉํฅ์ ์ค์ ํ๋ค.
% Get the user camera pose
tx = hxs_camera_transform();
% Move and rotate the user camera pose
new_tx = tx;
new_tx.pos(3) = new_tx.pos(3) + 1;
% assign equvalent of Euler angles rpy(0, 0, M_PI)
new_tx.orient = [0 1 0 0]';
hxs_set_camera_transform(new_tx);์ฌ๊ธฐ์์๋ ํ์ฌ ์นด๋งค๋ผ์ ์ด๋๊ณผ ํ์ ์ ๋ํ ๋ณํ์์ ๊ตฌ์กฐ์ฒด tx์ ์ ์ฅํ๊ณ , ์นด๋ฉ๋ผ๊ฐ ์ด๋ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
์ค๋ธ์ ํธ์ ์์์ 4-tuple (๋นจ๊ฐ, ๋ น์, ํ๋, ์ํ)๋ก ๊ฐ์ ธ์ค๊ณ ์ค์ ํ. ์ฌ๊ธฐ์ ์ํ๋ ์ค๋ธ์ ํธ์ ํฌ๋ช ๋๋ฅผ ๋ํ๋ธ๋ค.์ํ ๊ฐ์ด 0 ์ธ ๊ฐ์ฒด๋ ์์ ํ ํฌ๋ช (๋ณด์ด์ง ์์)์ธ ๋ฐ๋ฉด, ์ํ ๊ฐ์ด 1์ด๋ฉด ๊ฐ์ฒด๊ฐ ์์ ํ ๋ถํฌ๋ช (์๋ฆฌ๋)์ ์๋ฏธํ๋ค.
% Change the table color.
hxs_set_model_color('table', [1;0;0;1])
pause(1);
% Row vectors work, too
hxs_set_model_color('table', [0,1,0,1])
pause(1);
hxs_set_model_color('table', [0;0;1;1])
% Get the color
color = hxs_model_color('table');์ฌ๊ธฐ์์๋ ํ ์ด๋ธ์ ์์ ๋นจ๊ฐ์์์ ์ด๋ก์์ผ๋ก, ๊ทธ๋ฆฌ๊ณ ํ๋์์ผ๋ก ์ค์ ํ์๋ค.
ํ ๋ชจ๋ธ์ด ๋ค๋ฅธ ๋ชจ๋ธ๊ณผ ์ ์ดํ๋ ์ง์ ์ ๊ฐ์ ธ์จ๋ค.
% Get contact information for the cube after it collides with the table
% Applying a force here induces a collision
hxs_apply_force('wood_cube_5cm', 'link', [0, 0, -1], 0.1);
pause(0.05);
contacts = hxs_contacts('wood_cube_5cm');์ด ์์ ์์๋ ์ ์ด ๊ตฌ์กฐ์ฒด๋ฅผ ๊ฒ์ํ๊ณ ๊ทธ๊ฒ์ ๊ฐ๋ก์ง๋ฅด๋ ๋๋ฌด ํ๋ธ์ ๋ํ ๊ฐ ์ ์ ์ ์ถ๋ ฅํ๋ค. ํ๋ธ์ "๋๊ป"๋งํฌ์ ์ ์ดํ๋ ์ ๋ฐฉ์ฒด์ ๊ฐ ๋ชจ์๋ฆฌ์ ํ๋์ฉ, 4์ ์ ์ ์ ๋ณผ ์ ์๋ค.
๋ชจ๋ธ์ ์ ์๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ค์ ํ๋ค. ์ ์๋๋ ์ด๋น ๋ฏธํฐ ๋จ์๋ก ๋ชจ๋ธ ์๋์ (x,y,z)์ฑ๋ถ์ ๋ํ๋ด๋ 3-vector ์ด๋ค.
vel = hxs_linear_velocity('wood_cube_5cm');์ด๋ฐ ๋ฐฉ์์ผ๋ก ๊ฒ์ํ ์๋๋ ๋ชจ๋ธ์ canonical link์ ์๋๋ก ํํ๋๋ค. ๋๋ฌด ํ๋ธ์ ๊ฐ์ ๋จ์ผ ๋งํฌ ๊ฐ์ฒด์ ๊ฒฝ์ฐ ์ ์ฒด ๋ชจ๋ธ์ ์๋์ด๋ค. ๊ทธ๋ฌ๋ ๋ก๋ด ํ์ ๊ฒฝ์ฐ์๋ ํ๋ ๋งํฌ(forearm link)์ ์๋์ด๋ฉฐ SDF์ ํ์ค ๋งํฌ๋ก ์ค์ ๋๋ค.
% Move by setting linear velocity
hxs_set_linear_velocity('wood_cube_5cm', [-0.5; 0; 0]);์ด ๋ฐฉ๋ฒ์ผ๋ก ๋ชจ๋ธ์ ์๋๋ฅผ ์ค์ ํ๋ฉด API๊ฐ ๋ชจ๋ธ์ ๊ฐ ๋งํฌ ์๋๋ฅผ ์ค์ ํ๋ค.
๋ชจ๋ธ์ ๊ฐ์๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ค์ ํ๋ค. ๊ฐ์๋๋ (x,y,z)์ถ์ ๋ํ ์ด๋น ๋ผ๋์ ๋จ์๋ก ๋ํ๋ด๋ 3-vector์ด๋ค.
vel = hxs_angular_velocity('wood_cube_5cm');์ด ํจ์๋ ๋ชจ๋ธ์ canonical link์ ๊ฐ์๋๋ฅผ ๋ฐํํ๋ค.
% Move by setting angular velocity
hxs_set_angular_velocity('wood_cube_5cm', [0; 0; 100]);๋จ์ผ ๋งํฌ ๋ชจ๋ธ์ ๊ฒฝ์ฐ, hxs_set_angular_velocity๋ ๋งํฌ์ ์ง๋ ์ค์ฌ์ ๊ธฐ์ค์ผ๋ก ๋ชจ๋ธ์ ๊ฐ์๋๋ฅผ ์ค์ ํ๋ค.
hxs_apply_X ํจ์๋ ๋ชจ๋ธ, ๋งํฌ, ๋ฒกํฐ ๋๋ ์ ์ฉ๋๋ ํ, ํ ํฌ, ๋ ์น ๋ฑ์ ๋ํ๋ด๋ ๊ตฌ์กฐ์ฒด, ๊ทธ๋ฆฌ๊ณ ํ์ด ์ ์ฉ๋๋ ์ง์ ์๊ฐ์ ์ฌ์ฉํฉ๋๋ค.
์ง์ ์๊ฐ์ด "0"์ด๋ฉด ํ, ํ ํฌ ๋๋ ๋ ์น์ ์ง์ ์๊ฐ์ด ๊ธธ์ด์ง๋ค.
hxs_apply_force('wood_cube_5cm', 'link', [-1.0; 0; 0], 0.2);์ด ํจ์๋ ๋ชฉ์ฌ ํ๋ธ ๋ชจ๋ธ์์ X์ ์์ ๋ฐฉํฅ์ผ๋ก 1 Newton์ ํ์ 0.2 ์ด ๋์ ์ ์ฉํ๋ ๊ฒ์ด๋ค.
hxs_apply_torque('wood_cube_5cm', 'link', [0; 0; 0.1], 0.1)
์ด ํจ์๋ ๋ชฉ์ฌ ํ๋ธ ๋ชจ๋ธ์์ 0.1 ์ด ๋์ Z ์ถ์ ๋ํด 0.1 Newton-meter์ ํ ํฌ๋ฅผ ์ ์ฉํ๋ ๊ฒ์ด๋ค.
% Apply force and torque at the same time.
wrench = struct('force', [0; 0; 1], 'torque', [0; 0; 0.1]);
hxs_apply_wrench('wood_cube_5cm', 'link', wrench, 0.1);์ด ํจ์๋ ํ๊ณผ ํ ํฌ๊ฐ ๋์์ ์๋ ๋ ์น๋ฅผ ์ ์ฉํ๋ ๊ฒ์ด๋ค. ๋ ์น๋ Z ์ถ ๋ฐฉํฅ์ผ๋ก 1 Newton์ ํ ์ฑ๋ถ๊ณผ Z ์ถ์ ๋ํด 0.1 Newton-meter์ ํ ํฌ ์ฑ๋ถ์ ๊ฐ์ง๋ค.
๋ชจ๋ธ์ ์ค๋ ฅ ๋ชจ๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ค์ ํ๋ค. ์ค๋ ฅ ๋ชจ๋๊ฐ 1์ด๋ฉด ๋ชจ๋ธ์ ์ค๋ ฅ์ด ๋ฐ์ํ๋ค(๊ธฐ๋ณธ์ ์ผ๋ก, Z์ ์์ ๋ฐฉํฅ์์ 9.81 meters/second^2). ๋ง์ฝ ์ค๋ ฅ ๋ชจ๋๊ฐ 0์ด๋ฉด ๋ชจ๋ธ์ ์ค๋ ฅ์ด ๋ฐ์ํ์ง ์์ผ๋ฉฐ, ์ธ๋ ฅ์ ์ํด ๋ฐฉํด๋ฐ์ง ์๋ ํ ๊ณต๊ธฐ์ค์ ๋ ์๊ฒ๋๋ค.
% Check gravity mode on wooden cube
gravity_mode = hxs_model_gravity_mode('wood_cube_5cm');
disp(gravity_mode);
% Turn off gravity for cube, then nudge it upward
hxs_set_model_gravity_mode('wood_cube_5cm', 0);
% Row vectors work, too.
hxs_apply_force('wood_cube_5cm', 'link', [0, 0, 0.1], 0.1);
% Let it fly
pause(1);
% Bring it back down
hxs_set_model_gravity_mode('wood_cube_5cm', gravity_mode);์ด ์์ ์์๋ ํ์ฌ ์ค๋ ฅ ๋ชจ๋๋ฅผ ๊ฒ์ํ๋ค.์ด ๋ชจ๋๋ ๊ธฐ๋ณธ์ ์ผ๋ก 1์ ๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ค๋ ฅ์ ๋๊ณ ์๋ก ๋ฐ์ด๋ณด๋ธ๋ค. ์ค๋ ฅ์ด ํ๋ธ์์ ์์ฉํ๋ฉด ํ ์ด๋ธ์ชฝ์ผ๋ก ๋ค๋ก ๋จ์ด์ง์ง๋ง ์ค๋ ฅ์ด ๊บผ์ก๊ธฐ๋๋ฌธ์ ํ ์ด๋ธ์ด ๋ ์๊ฒ๋๋ค.
๋ชจ๋ธ์ ๋ณํ์ ๊ฐ์ ธ์ค๊ณ ์ค์ ํ๋ค. ์ด๊ฒ์ canonical link์ ํ์ฌ ๋ณํ(์ผ๋ฐ์ ์ผ๋ก ๋จ์ผ ๋งํฌ ๋ชจ๋ธ์ ์ง๋ ์ค์ฌ)์ผ๋ก ์ ์๋๋ค.
% Get the pose of the cube
tx = hxs_model_transform('wood_cube_5cm');
disp('Cube position:');
disp(tx.pos);
disp('Cube orientation:');
disp(tx.orient);
% Modify and set the pose
tx.pos(2) = tx.pos(2) + 0.25;
% define a 45 deg rotation about yaw (z) axis
tx.orient = [cos(pi/8) 0 0 sin(pi/8)]';
hxs_set_model_transform('wood_cube_5cm', tx);์ด ์์ ์์๋ ํ๋ธ์ ๋ณํ์ ๊ฐ์ ธ์จ ๋ค์ ๋ค๋ฅธ ์์น์ ๋ฐฉํฅ์ผ๋ก ์์ ํ๋ค.
ํ ๋ณํ ์ค์ ๋ก๋ด ํ์ ์์น์ ๋ฐฉํฅ์ ์ค์ ํ ์๋ ์๋ค.
% Set the position of the arm. Note that if the motion tracking device is
% active and unpaused, this change will be transient.
arm_tx = struct('pos', [1.0, 0, 1.5], 'orient', [1, 0, 0, 0]);
hxs_set_model_transform(hand, arm_tx)์ด ๋ช ๋ น๋ค์ Optitrack๊ณผ ๊ฐ์ ๋ชจ์ ์ถ์ ๊ธฐ์ ์ ์ํด ๋ฌด์๋ ๊ฒ์ด๋ค. ํจ๊ณผ๋ฅผ์ ์ ์ฉํ๋ ค๋ฉด ๋ชจ์ ์ถ์ ์ด ์ผ์ ์ค์ง๋์๋์ง ๋๋ ์ฌ์ฉ ์ค์ง๋์๋์ง ํ์ธํ์ฌ๋ผ.
๋ชจ๋ธ์ ์ถฉ๋ ๋ชจ๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ค์ ํ๋ค. ์ธ ๊ฐ์ง ๊ฐ๋ฅํ ์ถฉ๋ ๋ชจ๋๊ฐ ์์ต๋๋ค.
-
hxsCOLLIDE: ๊ธฐ๋ณธ ์ถฉ๋ ๋ชจ๋. ๋ชจ๋ธ์ด ์ถฉ๋ ๋ชจ๋๋ก ์ค์ ๋ ๋ค๋ฅธ ๋ชจ๋ธ๊ณผ ์ถฉ๋ํ๋ค. -
hxsNOCOLLIDE: ๋ชจ๋ธ์ด ์๋ฌด ๊ฒ๋ ์ถฉ๋ํ์ง ์๋๋ค. ๋ค๋ฅธ ๋ชจ๋ธ์ดhxsCOLLIDE๋ก ์ค์ ๋์ด ์์ด๋ ๋ค๋ฅธ ๋ชจ๋ธ์ ํต๊ณผํฉ๋๋ค. ์ด ๋ชจ๋ธ์ด ๋ค๋ฅธ ๋ชจ๋ธ์ ํต๊ณผ ํ ๋hxs_contacts๋ ์ ์ด๋ฅผ ํ์งํ์ง ์๋๋ค. -
hxsDETECTIONONLY:hxsNOCOLLIDE์ ๊ฐ์ด ๋ชจ๋ธ์ด ๋ค๋ฅธ ๋ชจ๋ธ์ ํต๊ณผํ๊ณ ์ ์ด๋ ฅ์ด ๋ฌด์๋๋ค. ๊ทธ๋ฌ๋ ์ถฉ๋์ ์ฌ์ ํhxs_contacts์ ์ํด ๊ฐ์ง๋๋ค. ์ฆ,hxsDETECTIONONLY๋ชจ๋ธ์ด ๋ค๋ฅธ ๋ชจ๋ธ์ ํต๊ณผํ๋ฉดhxs_contacts๋ ํด๋น ํ์ ์คํ ์ ๋ชจ๋ธ์ ๋ํ ์ ์ด ์ ๋ณด๋ฅผ ๊ฐ๋๋ค (๋ชจ๋ธ์hxsNOCOLLIDE๊ฐ ์ค์ ๋ ๊ฒฝ์ฐ ์ ์ธ).
๋๋ถ๋ถ์ ์์ฉ ํ๋ก๊ทธ๋จ์์๋ hxsCOLLIDE ๋๋ hxsDETECTIONONLY๋ฅผ ๊ถ์ฅํ๋ค.
% Check collide mode on the cube
collide_mode = hxs_model_collide_mode('wood_cube_5cm');
disp(collide_mode);
% Let it drop through the table
hxs_set_model_collide_mode('wood_cube_5cm', 0);
% Hack: apply a small force to disturb the cube to make it actually fall.
hxs_apply_force('wood_cube_5cm', 'link', [0; 0; 0.1], 0.1);
pause(1);
% Turn collisions back on (won't bring the cube back, of course)
hxs_set_model_collide_mode('wood_cube_5cm', collide_mode);์ด ์์ ์์๋ ํ๋ธ์ ์ถฉ๋ ๋ชจ๋๋ฅผ ํ์ธํ๋ค. ์ถฉ๋ ๋ชจ๋๋ ๊ธฐ๋ณธ hxsCOLLIDE๋ก ์ค์ ๋๋ค. ๊ทธ๋ฐ ๋ค์ ํ
์ด๋ธ์ ํต๊ณผํ ์ ์๊ฒ hxsNOCOLLIDE`์ ํด๋นํ๋ ํญ๋ชฉ์ 0์ผ๋ก ์ค์ ํ๋ค. ๊ทธ๋ฐ ๋ค์ ์๋ ์ถฉ๋ ๋ชจ๋๋ก ๋ค์ ์ค์ ํ๋ค.
hxs_add_model์ ์์ ํ SDF ์ค๋ช
์ ๊ธฐ๋ฐ์ผ๋ก scene์ ์ ๋ชจ๋ธ์ ์ถ๊ฐํ๋ค. ๋ชจ๋ธ์ ์ ์ด๋ฆ๊ณผ ์ด๊ธฐ ์์น ๋ฐ ๋ฐฉํฅ์ ์ง์ ํ ์๋ ์๋ค.
SDF์์ ๋ชจ๋ธ์ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์์ ๋ณด๋ ค๋ฉด Gazebo ๋ชจ๋ธ ์์ฑ ์์ต์๋ฅผ ์ฐธ์กฐํ๊ฑฐ๋ ๋ชจ๋ธ ํธ์ง๊ธฐ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ฐธ๊ณ ํ๋ผ.
hxs_remove_model์ world์์ ์ผ์นํ๋ ์ด๋ฆ์ ๊ฐ์ง ๋ชจ๋ธ์ ์ ๊ฑฐํ๋ค. hxs_remove_model`์ ์กด์ฌํ์ง ์๋ ๋ชจ๋ธ์ ์ ๊ฑฐํ๋ ค๊ณ ์๋ํ๋ฉด ์ค๋ฅ๋ฅผ ๋ฐํํ๋ค.
% Define a new model. Here, we're taking the cricket_ball model from:
% https://bitbucket.org/osrf/gazebo_models/src/default/cricket_ball/model.sdf
% and tweaking it slightly (just changing the color from Red to Green).
sdf = '<sdf version="1.5"> <model name="cricket_ball"> <link name="link"> <pose>0 0 0.0375 0 0 0</pose> <inertial> <mass>0.1467</mass> <inertia> <ixx>8.251875e-05</ixx> <ixy>0</ixy> <ixz>0</ixz> <iyy>8.251875e-05</iyy> <iyz>0</iyz> <izz>8.251875e-05</izz> </inertia> </inertial> <collision name="collision"> <geometry> <sphere> <radius>0.0375</radius> </sphere> </geometry> </collision> <visual name="visual"> <geometry> <sphere> <radius>0.0375</radius> </sphere> </geometry> <material> <script> <uri>file://media/materials/scripts/gazebo.material</uri> <name>Gazebo/Green</name> </script> </material> </visual> </link> </model> </sdf>';
% Add the new model to the world, at the world origin, 5m off the ground, with
% gravity enabled. Then it will drop onto the table.
hxs_add_model(sdf, 'green_cricket_ball', [0; 0; 5], [0; 0; 0], 1);
pause(2);
% Define and add a constraint
constraint_sdf = '<sdf version="1.5"><joint name="test_constraint" type="revolute"><parent>table::link</parent><child>wood_cube_5cm::link</child><axis><xyz>0 1 0</xyz></axis></joint></sdf>';
% Enable when there's an implementation of hxs_add_constraint in Gazebo.
hxs_add_constraint(constraint_sdf, 'wood_cube_5cm');
pause(2);
% Roll the ball to the right
hxs_apply_torque('green_cricket_ball', 'link', [0; 0.05; 0], 0.1)
pause(2);
% Remove constraint
% Enable when there's an implementation of hxs_remove_constraint in Gazebo.
hxs_remove_constraint('test_constraint', 'wood_cube_5cm');
pause(2);
% Remove the model
hxs_remove_model('green_cricket_ball');์ด ์์ ์์๋ ํ๋ ์ฝ๋ ๋ SDF ๋ฌธ์์ด์ ์ฌ์ฉํ๊ณ ์๋ก์ด green_cricket_ball ๋ชจ๋ธ์ ๋ง๋ ๋ค. ๋ชจ๋ธ์ ์์น (0, 0, 5)์ ์๋ ์ ์ญ ์ขํ๊ณ ํ๋ ์์ ๋ํ๋๋ฉฐ, ์ด๋ ๋๋ฌด ์ผ์ด์ค ์๋ก ๋จ์ด์ง๋ ๊ฒ์ ์๋ฏธํ๋ค. ์ฐ๋ฆฌ๋ ๋ชจ๋ธ์ด ์ธ๋ถ ๊ต๋์ ๋ฐ์ํ๋ค๋ ๊ฒ์ ๋ณด์ฌ์ฃผ๊ธฐ ์ํด ํ ํฌ๋ฅผ ์ ์ฉํ ๋ค์ ์ด๋ฅผ world์์ ์ ๊ฑฐํ๋ค.
ํ๋ ์ด์์ ๊ด์ ์ด์๋ ๋ชจ๋ธ์ ๊ฒฝ์ฐ, ์ด ํจ์๋ ๋ชจ๋ธ, ๊ด์ ์ค ํ๋์ ์ด๋ฆ, ๋ ๊ฐ์ ์ค์นผ๋ผ ๊ฐ์ ์ฌ์ฉํ๋ค. ๊ทธ๋ฐ ๋ค์ ์ค์นผ๋ผ ์ ๋ ฅ์ ๊ธฐ๋ฐ์ผ๋ก ๋ชจ๋ธ์์ ์ง์ ๋ ์กฐ์ธํธ์ ์์น์ ์๋๋ฅผ ์ค์ ํ๋ค.
% Set the state of a wrist joint. Note that, because there's a controller
% acting on the wrist, this change will only be transient; the controller will
% restore the wrist back to the current target position.
hxs_set_model_joint_state(hand, hand_joint, 0.5, 0.0);
pause(1);
% Set the position of the arm. Note that if the motion tracking device is
% active and unpaused, this change will be transient.
arm_tx = struct('pos', [1.0, 0, 1.5], 'orient', [1, 0, 0, 0]);
hxs_set_model_transform(hand, arm_tx)
% Move the camera
hxs_set_camera_transform(new_tx);
pause(1);
% Reset the world, which will move the camera back
hxs_reset(1);
pause(1);์ด ์์ ์์๋ ๋ก๋ด ํ์ ์๋ชฉ ๊ด์ ์ํ๋ฅผ ์ค์ ํ๋ค. ํ์ ๋ชจํฐ๊ฐ ๊ด์ ์ actively controllingํ๊ธฐ ๋๋ฌธ์ ๊ด์ ์ ์๋ ์์น๋ก ๋๋์๊ฐ๋ค. ์๋ชฉ ๊ด์ ์ ๋ฐ๋ฅด๊ฒ ์ค์ ํ๋ ค๋ฉด, hx_update๋ฅผ ์ฌ์ฉํ๋ค (๋ค๋ฅธ ํํ ๋ฆฌ์ผ์์ ์ค๋ช
ํจ).
world๋ฅผ ๋ค์ ์ค์ ํ๋ค. ์ธ์๋ฅผ "0"์ผ๋ก ์ค์ ํ์ฌ ์ฌ์ค์ ํ๋ฉด ๋ก๋ด ํ๊ณผ viewpoint๋ ์ฌ์ค์ ๋์ง ์๋๋ค. reset์ 0์ด ์๋ ์ธ์๊ฐ ์ ๋ฌ๋๋ฉด ์ ์ธ๊ณ์ ๋ชจ๋ ํญ๋ชฉ์ด ์๋ ์์น๋ก ์ฌ์ค์ ๋๋ค.
% Move the camera
hxs_set_camera_transform(new_tx);
pause(1);
% Reset the world, which will move the camera back
hxs_reset(1);