HAPTIX Matlab and Octave API - modulabs/gazebo-tutorial GitHub Wiki
Overview
์ด๋ฒ ํํ ๋ฆฌ์ผ์์๋ ์์ ์ค๋ช ์ ์์ฒญํ๊ณ ์กฐ์ธํธ ๋ช ๋ น์ ๋ณด๋ด๊ณ ์ํ ์ ๋ฐ์ดํธ๋ฅผ ๋ฐ๊ธฐ์ํ์ฌ ์ฌ์ฉํ๋ Matlab(์๋์ฐ)์ด๋ Octave(๋ฆฌ๋ ์ค)๋ฅผ ์ฌ์ฉํ๋ ๋ฒ์ ์ค๋ช ํ๋ค.
์ด๋ฏธ ์ค์น ๊ณผ์ ์ ๋ง์ณค๋ค๊ณ ๊ฐ์ ํ๋ค.
Start the Gazebo simulation
๋ฐ์คํฌํ ์์ด์ฝ haptixStart๋ฅผ ๋๋ธํด๋ฆญํ๋ค.
Run your controller in Matlab
Matlab์ ์ด๊ธฐ ์ ์ ํ๊ฒฝ๋ณ์ 'IGN_IP'๊ฐ ์
ํ
๋์ด์๋์ง ํ์ธํด๋ผ. ์์ธํ ์ค๋ช
์ ์ค์น ๊ณผ์ ์ผ๋ก ๊ฐ์ Network Configration ์ฅ์ ํ์ธํด๋ผ.
Matlab์ ์ด๊ณ Browse for folder ์์ด์ฝ์ ํด๋ฆญํ์ฌ๋ผ.
์๋ก์ด ํ์
์๋์ฐ๊ฐ ๋ํ๋ ๊ฒ์ด๋ค. HAPTIX ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ SDK์ ์์ถ์ ํผ ๋๋ ํ ๋ฆฌ์์ matlab\ ํด๋๋ฅผ ์ฐพ๋๋ค. HAPTIX ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ SDK์๋ Matlab ์ฝ์ ๋๋ .m ํ์ผ์์ hx_connect(), hx_robot_info(), hx_update(), hx_read_sensors() ๋ฐ hx_close() ํจ์๋ฅผ ํธ์ถ ํ ์์๋ mex ํ์ผ์ด ์๋ค. MATLAB์์ hx_matlab_controller.m ํ์ผ์ ์ด๊ณ Matlab ๋ช
๋ น ์ฐฝ์ ๋ค์์ ์
๋ ฅํ๋ค:
hx_matlab_controller
์๋ controller visualization ๋น๋์ค์ ๊ฐ์ ํ์ ์์ง์์ ๋ณผ ์ ์๋ค.
Run your controller in Octave
๋ง์ฝ ์ค๋น๊ฐ ๋์ด์์ง ์๋ค๋ฉด ๋จผ์ Octave๋ฅผ ์ค์นํ๋ค.
sudo apt-get install octave liboctave-dev
๊ทธ๋ฆฌ๊ณ ์ค์น๋ haptix-comm์ ํ์ ๋๋ ํ ๋ฆฌ์ธ octave ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ๋ค. ์ด ๋๋ ํ ๋ฆฌ์๋ ๋ช๊ฐ์ .m ํ์ผ์ด ์๋ค.
cd /usr/lib/x86_64-linux-gnu/haptix-comm/octave
๋ง์ฝ์ ์ ๋๋ ํ ๋ฆฌ๊ฐ ์๋ค๋ฉด, ์๋ ๋ช ๋ น์ ์๋ํด ๋ณด์๋ผ:
cd /usr/lib/haptix-comm/octave
Octave๋ฅผ ์์ํ๋ค.
octave
Octave์์ hx_connect(), hx_robot_info(), hx_update(), hx_read_sensors() ๋ฐ hx_close()๋ฅผ ํธ์ถ ํ ์ ์์ด์ผํ๋ค(๊ดํธ๋ ์ ํ ์ฌํญ์).
์๋ฎฌ๋ ์ดํธ๋ ํ(arm)์ ๋ํ ์ปจํธ๋กค๋ฌ๋ฅผ ์คํํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์
๋ ฅํ๋ผ:
hx_matlab_controller
์๋ controller visualization ๋น๋์ค์ ๊ฐ์ ํ์ ์์ง์์ ๋ณผ ์ ์๋ค.
Controller visualization
์ปจ๋๋กค๋ฌ๊ฐ ์คํ๋๋ ๋์ ๊ฐ์ ๋ณด ์์ ์๊ฐ๋ฝ์ ๋ถ๋๋ฌ์ด ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ผ ์์ง์ธ๋ค.

The code explained
counter = 0;
hx_connect();
deviceInfo = hx_robot_info();
% Uncomment this block to start logging.
% hxs_start_logging('/tmp/log/')
while counter < 250
cmdSent = tic;
% Initialize the command scalar structure.
cmd.ref_pos = [];
cmd.ref_vel = [];
cmd.ref_vel_max = [];
cmd.gain_pos = [];
cmd.gain_vel = [];
% Indicate that the positions we set should be used.
cmd.ref_pos_enabled = 1;
% We're not setting it, so indicate that ref_vel should be ignored.
cmd.ref_vel_enabled = 0;
% We're not setting it, so indicate that ref_vel_max should be ignored.
cmd.ref_vel_max_enabled = 0;
% We're not setting it, so indicate that gain_pos should be ignored.
cmd.gain_pos_enabled = 0;
% We're not setting it, so indicate that gain_vel should be ignored.
cmd.gain_vel_enabled = 0;
% Create a new command based on a sinusoidal wave.
for n = 0:deviceInfo.motor_count
cmd.ref_pos(end + 1) = 350 * 0.5 * sin(0.05 * 2.0 * pi * counter * 0.08);
% We could set a desired maximum velocity
% cmd.ref_vel(end + 1) = 1.0;
% cmd.ref_vel_max(end + 1) = 1.0;
% We could set a desired controller position gain
% cmd.gain_pos(end + 1) = 1.0;
% We could set a desired controller velocity gain
% cmd.gain_vel(end + 1) = 1.0;
end
% Send the new joint command and receive the state update.
state = hx_update(cmd);
counter = counter + 1;
% Busy wait. pause() is not accurate enough on Windows.
elapsedCmd = toc(cmdSent);
while elapsedCmd < 0.02
elapsedCmd = toc(cmdSent);
end
end
% Uncomment this block to stop logging.
% hxs_stop_logging()
hx_close();
HAPTIX Matlab/Octave API๋ hx_connect(), hx_robot_info(), hx_update(), hx_read_sensors() ๋ฐ hx_close()์ ๋ค์ฏ ๊ฐ์ง ํจ์๋ก ๊ตฌ์ฑ๋๋ค. hx_connect()์ hx_close()๋ Gazebo ์๋ฎฌ๋ ์ดํฐ์์๋ ์ ํ ์ฌํญ์ด์ง๋ง MuJoCo์์ ํธํ์ฑ์ ์ํด ํฌํจ๋์ด ์๋ค.
hx_robot_info()๋ ์ฃผ์ด์ง ์ฅ์น๋ก๋ถํฐ ์ ๋ณด๋ฅผ ์์ฒญํ๋ค. ์ด ํํ ๋ฆฌ์ผ์์ ์ฅ์น๋ Gazebo์์ ์๋ฎฌ๋ ์ด์
๋ ์์ด๋ค. ์ด ํธ์ถ์ ์๋ต์ด ์์ ๋ ๋๊น์ง ์ฐจ๋จ๋๋ค.
hx_robot_info()์ ๊ฒฐ๊ณผ ๊ฐ์ ์์ฒญ๋ ์ฅ์น์ ๋ํ ๋ชจํฐ, ์กฐ์ธํธ, ์ ์ด ์ผ์, IMU ๋ฐ ์กฐ์ธํธ ์ ํ ์๋ฅผ ํฌํจํ๋ ๊ตฌ์กฐ์ฒด์ด๋ค. ๋ํ ์ฅ์น๊ฐ ์
๋ฐ์ดํธ๋๋ ๋น๋์ธ ์
๋ฐ์ดํธ ์๋๋ ํฌํจ๋ฉ๋๋ค.
์ฅ์น ์ ๋ณด๋ฅผ ํ์ธํ๋ฉด ์ ์ ์ด ๋ช
๋ น์ ๋ณด๋ผ ์ ์๋ค. hx_update() ํจ์๋ ์๋ก์ด ๋ช
๋ น์ ๋ณด๋ด๊ณ ํ์ฌ ์์ ์ํ๋ฅผ๋ฐ๋ ์ญํ ์ ๋ด๋นํ๋ค.
๊ฐ ์กฐ์ธํธ์ ์์น, ์๋ ๋ฐ ์ด๋์ ํฌํจํ๋ ๋ช ๋ น ๊ตฌ์กฐ์ฒด๋ฅผ ์ฑ์ธ ํ์๊ฐ ์์ต๋๋ค. ์ด ์์ ์์ ์ฌ์ฉํ๋ ํ๋์ ๋ํด ๋์ผํ ์ด๋ฆ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ค์ํ๋ค.
๋ช
๋ น์ ์ ์ฉํ ํ ๋ช
๋ น์ ์ผ์ ์ํ๋ฅผ ๋ํ๋ด๋ ๊ตฌ์กฐ์ฒด๋ฅผ ๋ฐํํ๋ hx_update() ํจ์๋ฅผ ํธ์ถํ๋ค.