Razer Hydra - modulabs/gazebo-tutorial GitHub Wiki
Gazebo๋ Razer Hydra ์ปจํธ๋กค๋ฌ๋ฅผ ์ง์ํฉ๋๋ค. ์ด ๋ชจ์ ๋ฐ ๋ฐฉํฅ ๊ฐ์ง ์ปจํธ๋กค๋ฌ๋ฅผ ์ฌ์ฉํ์ฌ Gazebo์์ ๋ชจ๋ธ๊ณผ ์ํธ ์์ฉํ ์ ์์ต๋๋ค.
Razer hydra ์ปจํธ๋กค๋ฌ๋ 6์์ ๋ VR ์ปจํธ๋กค๋ฌ์ ๋๋ค. ํ์ง๋ง ๊ฑฐ์ ์ฌ์ฉํ์ง ์๋ ์ค๋๋ ์ปจํธ๋กค๋ฌ๋ผ ๋ค๋ฅธ ๊ธฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๊ธธ ์ถ์ฒํฉ๋๋ค.
ํฐ๋ฏธ๋ (CTRL-ALT-T)์ ์ด๊ณ ๋ค์ ๋ช ๋ น์ ์คํํ์ญ์์ค.
echo -e "ATTRS{idProduct}=="0300",ATTRS{idVendor}=="1532",ATTR{bInterfaceNumber}=="00",TAG="hydra-tracker"\nSUBSYSTEM=="hidraw",TAGS=="hydra-tracker", MODE="0666", SYMLINK+="hydra"" > 90-hydra.rules
๊ทธ๋ฌ๋ฉด 90-hydra.rules๋ผ๋ ํ์ผ์ด ์์ฑ๋ฉ๋๋ค.
๋ฃจํธ ์ก์ธ์ค์์ด ์ปจํธ๋กค๋ฌ์ ์ก์ธ์ค ํ ์ ์์ด์ผํฉ๋๋ค.
sudo cp 90-hydra.rules /etc/udev/rules.d/ sudo udevadm control --reload-rules
optional libusb dependecy๋ฅผ ์ค์นํด์ผํฉ๋๋ค.
sudo apt-get install libusb-1.0-0-dev
Hydra๊ฐ ๊ตฌ์ฑ๋๊ณ ์ถ๊ฐ ์ข ์์ฑ์ด ๋ง์กฑ๋๋ฉด Hydra ์ง์ ์์ค์์ Gazebo๋ฅผ ์ปดํ์ผ ํ ์ ์์ด์ผํฉ๋๋ค.
Gazebo๋ฅผ ์ปดํ์ผํ๋ ค๋ฉด์ด ์ง์ ์ฌํญ์ ๋ฐ๋ฅด์ญ์์ค. cmake ๋ช ๋ น์ ์คํํ๋ ๋์ SDK๊ฐ ๋ฐ๊ฒฌ๋์์์ ํ์ธํ๋ ๋ฉ์์ง๊ฐ ํ์๋ฉ๋๋ค.
-- Looking for libusb-1.0 - found. Razer Hydra support enabled.
๊ฐ์ ๋ณด์์ ํ๋๋ผ๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋ ๋จ๊ณ๊ฐ ํ์ํฉ๋๋ค. ์ฒซ ๋ฒ์งธ ๋จ๊ณ๋ ์๋ ํ์ผ์ Hydra ํ๋ฌ๊ทธ์ธ์๋ก๋ํ๋ ๊ฒ์ ๋๋ค
์ด ํ๋ฌ๊ทธ์ธ์ ์ฃผ์ ์ ๋ํ ๋ฉ์์ง๋ฅผ ์๋์ผ๋ก ๊ฒ์ํฉ๋๋ค. ~/hydra.
๋ ๋ฒ์งธ ๋จ๊ณ๋ hydra ์ฃผ์ ๋ฅผ ๊ตฌ๋ ํ๊ณ ํฅ๋ฏธ๋ก์ด ๊ฒ์ ๋ง๋๋ ํ๋ฌ๊ทธ์ธ์ ์์ฑํ๋ ๊ฒ์ ๋๋ค. ์ด ํํ ๋ฆฌ์ผ์์๋ Hydra์ ์ค๋ฅธ์ชฝ ์กฐ์ด์คํฑ์ ์ฌ์ฉํ์ฌ ๊ตฌ์ฒด๋ฅผ ์ด๋ํฉ๋๋ค. HydraDemoPlugin์ Gazebo์ plugins / ๋๋ ํ ๋ฆฌ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Plugin code:
#include <boost/bind.hpp> #include <gazebo/gazebo.hh> #include <gazebo/physics/physics.hh> #include "gazebo/transport/transport.hh" #include "HydraDemoPlugin.hh"
using namespace gazebo;
GZ_REGISTER_MODEL_PLUGIN(HydraDemoPlugin)
///////////////////////////////////////////////// HydraDemoPlugin::HydraDemoPlugin() { }
///////////////////////////////////////////////// HydraDemoPlugin::~HydraDemoPlugin() { }
///////////////////////////////////////////////// void HydraDemoPlugin::OnHydra(ConstHydraPtr &_msg) { boost::mutex::scoped_lock lock(this->msgMutex); this->hydraMsgPtr = _msg; }
///////////////////////////////////////////////// void HydraDemoPlugin::Load(physics::ModelPtr _parent, sdf::ElementPtr /_sdf/) { // Get the world name. this->model = _parent; this->world = this->model->GetWorld();
// Subscribe to Hydra updates by registering OnHydra() callback. this->node = transport::NodePtr(new transport::Node()); this->node->Init(this->world->GetName()); this->hydraSub = this->node->Subscribe("~/hydra", &HydraDemoPlugin::OnHydra, this);
// Listen to the update event. This event is broadcast every // simulation iteration. this->updateConnection = event::Events::ConnectWorldUpdateBegin( boost::bind(&HydraDemoPlugin::Update, this, _1)); }
///////////////////////////////////////////////// void HydraDemoPlugin::Update(const common::UpdateInfo & /_info/) { boost::mutex::scoped_lock lock(this->msgMutex);
// Return if we don't have messages yet if (!this->hydraMsgPtr) return;
// Read the value of the right joystick. double joyX = this->hydraMsgPtr->right().joy_x(); double joyY = this->hydraMsgPtr->right().joy_y();
// Move the sphere. this->model->SetLinearVel(math::Vector3(-joyX * 0.2, joyY * 0.2, 0));
// Remove the message that has been processed. this->hydraMsgPtr.reset(); }
Gazebo๋ฅผ ์์ํ๊ธฐ ์ ์ ๋ชจ๋ธ ํ๋ฌ๊ทธ์ธ์ ์๋ ํ์ผ์ ํฌํจ์์ผ์ผํฉ๋๋ค. ๋ค์์ ํํ ๋ฆฌ์ผ์ ์ ์ฒด ์ธ๊ณ ํ์ผ์ ๋๋ค (world / hydra_demo.world์์๋ ์ฌ์ฉ ๊ฐ๋ฅ).
<!-- A ground plane -->
<include>
<uri>model://ground_plane</uri>
</include>
<!-- A global light source -->
<include>
<uri>model://sun</uri>
</include>
<!-- Load the plugin for Razer Hydra -->
<plugin name="hydra" filename="libHydraPlugin.so">
<pivot>0.04 0 0</pivot>
<grab>0.12 0 0</grab>
</plugin>
<!-- A sphere controlled by Hydra-->
<model name="sphere">
<pose>0 0 0 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
</collision>
<visual name="visual">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
</visual>
</link>
<plugin name='sphere_ctroller' filename='libHydraDemoPlugin.so'></plugin>
</model>
๊ฐ์ ๋ณด๋ฅผ ์คํํ๊ณ ํ๋๋ผ์ ์ค๋ฅธ์ชฝ ์กฐ์ด์คํฑ์ ์ฌ์ฉํ์ฌ ๊ตฌ๋ฅผ ์์ง์ฌ์ผํฉ๋๋ค. ํ๋๋ผ ํ๋ฌ๊ทธ๋ฅผ ์์ง ๋ง๊ณ ๋ค์์ ์ํํ์ญ์์ค.
gazebo worlds/hydra_demo.world