๋ณธ ํจํค์ง๋ ํด๋จธ๋ ธ์ด๋ ๋ก๋ด RoK-3์ ๊ต์ก์ฉ Gazebo Simulation ์ ๋๋ค. ์ด ๋ฌธ์๋ ํจํค์ง์ ์ค๋ช ๋ฌธ์์ด๋ฉฐ, ๊ตฌ์ฑ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
-
What to do before simulation
-
Simulation Manual
- Download and Setting RobotControl2022
- Libraries used in RobotControl2022 Package
- How to run RobotControl2022 package, Please read section 2 before proceeding.
- RoS-Kinetic install, link : https://wiki.ros.org/kinetic/Installation/Ubuntu
- Gazeobo-7 install, link : https://gazebosim.org/tutorials?cat=install&tut=install_ubuntu&ver=7.0
- Netbeans-IDE install, link : https://netbeans.apache.org/download/index.html
Java install before Netbeans install
- terminal
sudo apt update sudo apt install openjdk-8-jdk java -version
Netbeans-IDE install
- terminal
cd /usr/local/netbeans-x.x //๊ธฐ์กด netbeans์ uninstall.sh๊ฐ ์๋ ํด๋๋ก ์ด๋. (x.x๋ ํ์ฌ๋ฒ์ ) //๊ฒฝ๋ก๊ฐ ๋ค๋ฅผ ์ ์์ผ๋ ํ์ธํ ๊ฒ sudo sh uninstall.sh //uninstall ์คํ
-
NetBeans 13_linux install ๋งํฌ๋ก ์ ์ ํฉ๋๋ค.
-
HTTP ํ๋จ์ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ .sh ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์ต๋๋ค.
.sh ํ์ผ์ ๋ค์ด๋ก๋ ๊ฒฝ๋ก๋/home/user_name/Downloads
๋ก ์ค์ ํฉ๋๋ค.
(๋ง์ฝ ๋ค์ด๋ก๋๊ฐ ๋์ง ์๋๋ค๋ฉด, ๋งํฌ๋ฅผ ๋ณต์ฌํ์ฌ **wget -c** ๋ช ๋ น์ด๋ก ์ง์ ์คํ)
- terminal
---example--- wget -c https://dlcdn.apache.org/...linux-x64.sh
- ๋ค์ด๋ก๋๋ ํ์ผ์ ์คํ๊ถํ์ ๋ถ์ฌํ๊ณ , ์คํํฉ๋๋ค.
- terminal
chmod +x Apache-NetBeans-13-bin-linux-x64.sh ./Apache-NetBeans-13-bin-linux-x64.sh
-
์ค์น๋ applications ์์ Apache NetBeans IDE 13์ ์คํํฉ๋๋ค.
-
์๋จ Menu์ Tools ํญ๋ชฉ ์ค Plugins๋ฅผ ํด๋ฆญํฉ๋๋ค.
-
Plugins์ฐฝ์ด ๋จ๋ฉด, Settings ์นดํ ๊ณ ๋ฆฌ๋ก ๋ค์ด๊ฐ์, NetBeans 8.2 Plugin Portal ์ Active์ ์ฒดํฌํ ํ, Available Plugins ์นดํ ๊ณ ๋ฆฌ๋ก ๋ค์ด๊ฐ check for Newest ๋ฅผ ํด๋ฆญํ์ฌ ์ ๋ฐ์ดํธ๋ฅผ ์งํํด ์ค๋๋ค.
-
์ ๋ฐ์ดํธ๋ฅผ ์งํ ํ ๋ํ๋๋ c/c++ ์ install ์ ์ฒดํฌํ๊ณ ํ๋จ์ install ๋ฒํผ์ ํด๋ฆญํ์ฌ ์ค์น๋ฅผ ์งํํฉ๋๋ค.
-
์๋จ Menu์ File ํญ๋ชฉ์์ New Project๋ฅผ ์ ํํฉ๋๋ค.
-
Choose Project Step
categories : C/C++
Projects : C/C++ Project with Existing Sources
next
- Select Mode Step
specify the folder : /home/user_name/catkin_ws
(user_name ์ ๊ฒฝ์ฐ Ubuntu ์ค์น ์ ์ฌ์ฉ์๊ฐ ์ค์ ํ ์ด๋ฆ์ ์ ๋ ฅํฉ๋๋ค.)
Build Host : localhost
Tool Collection : Default(GNU(GNU))
Use Build Analyzer Check
Configuration Mode : Custom
next
- Pre-Build Action Step
Pre-Build Step is Required uncheck
next
- Build Actions Step
Working Directory : /home/user_name/catkin_ws
Clean Command : devel/env.sh catkin_make clean
Build Command : devel/env.sh catkin_make
Clean and Build after Finish check
next
- Source Files Step
Source FIle Folders : /home/user_name/catkin_ws
next
- Code Assistance Configuration Step
Automatic Configuration check
next
- Project Name and Location Step
Project Name : catkin_ws
Project Location : /home/user_name/NetBeansProjects
Project Folder : /home/user_name/NetBeansProjects/catkin_ws
Build Host : localhost
Tool Collection : Default(GNU(GNU))
ํ๋จ์ ๋นจ๊ฐ์ ๊ฒฝ๊ณ ๋ ์ด๋ฏธ ํด๋น ํด๋๊ฐ ์ด๋ฏธ ๋ง๋ค์ด์ ธ ์๋ค๋ ๊ฒฝ๊ณ ์ด๋ฏ๋ก, ์ฒ์ ์ธํ
ํ ๊ฒฝ์ฐ์๋ ๋ฑ์ฅํ์ง ์์ต๋๋ค.
finish
- GitHub์ ๋ฏธ๋ฆฌ ๊ฐ์
ํ ์ํ๋ฉด, ํด๋น ํจํค์ง๋ฅผ ๊ณต๋ ์์
ํ๋๋ฐ ์์ด ๋์์ด๋ฉ๋๋ค.
๋ฐ๋ผ์, ๊ฐ์ ์ ํฌ๋งํฉ๋๋ค. ๋ํ,Token password
๋ฅผ ๋ฐ๊ธ๋ฐ๊ธฐ ๋ฐ๋๋๋ค.
ํ ํฐ ๋ฐ๊ธ ๋ฐฉ๋ฒ ์ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.
ํ ํฐ์ ์์ฑ ์ดํ์ ๋ค์ ํ์ธํ ์ ์์ผ๋, ๋ฐ๋ก ์ ์ฅํด๋์ด์ผ ํฉ๋๋ค.
1.Download and Setting RobotControl2022
-
RobotControl2022 Repository์ ์ ์, link : https://github.com/swan0421/RobotControl2022
-
ํด๋น Repository์ ์ ์ ํ, ์ฐ์ธก ์๋จ์ Fork๋ฅผ ํด๋ฆญํ์ฌ, ๋ณธ์ธ์ Github Repository์ ๋ณต์ ๋์๋์ง ํ์ธํฉ๋๋ค.
(swan0421/Robotcontrol2022
->User_id/Robotcontrol2022
)
Fork๋?
๋ค๋ฅธ ์ฌ๋์ Github Repository ์์ ๋ด๊ฐ ์์ ํ๊ฑฐ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ณ ์ ํ ๋,
ํด๋น Repository๋ฅผ ๋ด Github Repository๋ก ๊ทธ๋๋ก ๋ณต์ ํ๋ ๊ธฐ๋ฅ์ด๋ค.
Forkํ Repository๋ ์๋ณธ Repository์ ์ฐ๊ฒฐ๋์ด ์์ด,
์๋ณธ Repository์ ๋ณํ๊ฐ ์๊ธฐ๋ฉด, Forkํ Repository์ ๋ฐ์ํ ์ ์๋ค.
-
๋ณต์ ๋ ๋ณธ์ธ์ Repository์ ์ ์ ํ์,
Code โผ
๋ผ๋ ์ด๋ก์ ๋ฒํผ์ด ์๋๋ฐ ํด๋ฆญํ์ฌ URL ์ฃผ์ (https:/~)์ ๋ณต์ฌํ๊ฑฐ๋,Download ZIP
์ ํตํด ํด๋น ํจํค์ง๋ฅผ ๋ค์ด ๋ฐ์ต๋๋ค. -
NetBeans์
Team
>Git
>clone
์ ๋๋ฅธํ,Repository URL
์ https://github.com/User_id/RobotControl2022.git ์ผ๋ก ์ค์ ํฉ๋๋ค.
(๋ณธ์ธ์ Repository ๊ฒฝ๋ก)
(๋ง์ฝ, NetBeans์์Team
>Git
>clone
๊ฒฝ๋ก๊ฐ ๋ณด์ด์ง ์๋ ๊ฒฝ์ฐ, NetBeans ํ๋ฉด ์ข์ธก์ ์๋ Projects ํจ๋์์ catkin_ws ๋ฅผ ํด๋ฆญํ๋ฉด ๋ณด์ด๋ฉฐ, ์์ ๊ฒฝ๋ก๋ git์ ์ฐ๋๋์์ ๋ ํ์ฑํ๋๋ ๊ฒฝ๋ก์ด๋ฏ๋ก ์ฒ์ ์ฐ๋ํ๋ ๊ฒ์ด๋ผ๋ฉด, Team > git > clone์ผ๋ก ํด๋ ๋จ)
User์๋ GitHUB์ user_name์ ์ฐ๊ณ , Password์๋ GitHUB์Token password
๋ฅผ ์ ๋ ฅํ ํ NEXT๋ฅผ ๋๋ฆ ๋๋ค. -
Select Remote Branches๋ฅผ
master*
๋ก ์ ํํ๊ณ Next๋ฅผ ๋๋ฆ ๋๋ค. -
Parent Directory๋ฅผ ์ฌ์ฉ์์
home/user_name/catkin_ws/src
๊ฒฝ๋ก๋ก ์ค์ ํ๊ณ , Clone name์ ์ฌ์ฉ์๊ฐ ์ํ๋ ์ด๋ฆ์ผ๋ก ์ค์ ํ๊ณ , (์ฐธ๊ณ : Clone Name์ ํจํค์ง์ ๊ด๋ จ๋ ์ด๋ฆ์ผ๋ก ์จ์ ๋ค๋ฅธ ํด๋๋ค๊ณผ ๊ตฌ๋ณ ์ง์ ๊ฒ) Checkout Branch๋master*
๋ก ์ค์ ํ๊ณ , Remote Name์ origin์ผ๋ก ์ค์ ํ ํ Finish๋ฅผ ๋๋ฆ ๋๋ค. -
์ฌ์ฉ์์ catkin_ws/src ์์น์ Step5์์ ์ค์ ํ Clone Name ์ ๊ฐ๋ ํด๋๊ฐ ์๋์ง ํ์ธํ๊ณ , ํด๋ ๋ด๋ถ์ ํจํค์ง ๊ตฌ์ฑ ํ์ผ๋ค(world ํด๋, src ํด๋, launch ํด๋ ๋ฑ)๊ณผ model ํด๋(=
rok3_model
)์ด ์๋์ง ํ์ธํฉ๋๋ค. -
rok3_model
ํด๋๋ฅผHOME/.gazebo/models/
ํด๋๋ก ๊ฐ์ ธ์์ ์๋ฎฌ๋ ์ด์ ์ ์ํ ํ์ผ ์ ํ ์ ๋ง๋ฌด๋ฆฌํฉ๋๋ค.
(.gazebo
ํด๋๊ฐ ๋ณด์ด์ง ์์ผ๋ฉด, Home ํด๋์์,Ctrl+H
๋ฅผ ๋๋ฌ์ ํด๋ ์จ๊น ํด์ ๋ฅผ ํ ๊ฒ)
(Gazebo๋ฅผ ์คํํ ์ ์ด ์๋ ๊ฒฝ์ฐ, ์จ๊นํด์ ๋ฅผ ํ์ฌ๋ ํด๋๊ฐ ๋ณด์ด์ง ์์ ์ ์์. Terminal ์์gazebo
๋ฅผ ์ ๋ ฅํ์ฌ ํ๋ฒ ์คํํด์ค ํ ๋ค์ ํ์ธํ ๊ฒ) -
ํจํค์ง๋ฅผ ์ปดํ์ผํ๊ธฐ ์ํด Netbeans์์ ํฐ๋ฏธ๋ ์ฐฝ์ ์ด๊ฑฐ๋ ๊ธฐ๋ณธ ํฐ๋ฏธ๋ ์ฐฝ์์
cd ~/catkin_ws && catkin_make
์ ์ ๋ ฅํ์ฌ ์ปดํ์ผ์ ์งํํฉ๋๋ค. (ํฐ๋ฏธ๋ ์ฐฝ์ด ์๋ณด์ธ๋ค๋ฉด, Netbeans์ ์๋จWinodow > IDE Tools > Termianl
์ ํด๋ฆญ) -
๋ง์ฝ,
catkin_make
๊ฐ ์๋ ๊ฒฝ์ฐ, section 2๋ฅผ ํด๋ณด์๊ธฐ ๋ฐ๋๋๋ค.
Library | Description |
---|---|
Eigen | Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms. |
RBDL | RBDL library contains highly efficient code for both forward and inverse dynamics for kinematic chains and branched models. |
Recommended to re-install RBDL
RBDL์ ์ฌ์ค์น๋ฅผ ๊ถ์ฅํฉ๋๋ค. ์ฌ์ฉ์๋ง๋ค root
๊ณ์ ํน์ user
๊ณ์ ์ผ๋ก ํ๊ธฐ ๋๋ฌธ์, Build ํ๋ ๊ณผ์ ์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. ๋ฐ๋ผ์, ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ค์น๋ฅผ ํด์ฃผ์๊ธฐ ๋ฐ๋๋๋ค. ๋ณธ ํจํค์ง๋ฅผ root
๊ณ์ ์์ ์ฌ์ฉํ ๊ฒฝ์ฐ, ์ฌ์ค์น๊ฐ ํ์์์ ์ ์์ต๋๋ค.
RBDL Build
RobotControl2022/src/RBDL/addons/urdfreader
ํด๋ ๋ด์ ์๋CMakeList.txt
ํ์ผ์include_directories
๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํด์ค๋๋ค.
- Before :
IF (DEFINED ENV{ROS_ROOT})
MESSAGE (STATUS "ROS found: $ENV{ROS_ROOT}")
find_package(catkin REQUIRED COMPONENTS urdf)
- After :
IF (DEFINED ENV{ROS_ROOT})
MESSAGE (STATUS "ROS found: $ENV{ROS_ROOT}")
find_package(catkin REQUIRED COMPONENTS urdf)
include_directories(include ${catkin_INCLUDE_DIRS})
- RBDL make & install (build ํด๋๊ฐ ์กด์ฌํ ๊ฒฝ์ฐ, ์ญ์ ) RBDL ํด๋์์ ํฐ๋ฏธ๋ ์ฐฝ์ ์ผ๊ณ ์๋์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํจ์ผ๋ก์จ, RBDL ์ฌ์ค์น๋ฅผ ๋๋ ๋๋ค.
RBDL ํด๋ -> ์ค๋ฅธ์ชฝ ๋ง์ฐ์ค ํด๋ฆญ -> Open in Terminal
๋๋
cd catkin_ws/src/RobotControl2022/src/RBDL
mkdir build
cd build/
cmake -D CMAKE_BUILD_TYPE=Release ../
cmake -D RBDL_BUILD_ADDON_URDFREADER=true ../
make
sudo make install
- ๊ทธ๋ฆฌ๊ณ ๋ค์ ํจํค์ง๋ฅผ ์ปดํ์ผํ๊ธฐ ์ํด Netbeans์์ ํฐ๋ฏธ๋ ์ฐฝ์ ์ด๊ฑฐ๋ ๊ธฐ๋ณธ ํฐ๋ฏธ๋ ์ฐฝ์์
cd ~/catkin_ws && catkin_make
์ ์ ๋ ฅํ์ฌ ์ปดํ์ผ์ ์งํํฉ๋๋ค.
HOME/.gazebo/models/rok3_model
ํด๋์ ์๋ model.sdf
๋ฅผ ์ฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ Fixed / Floating Dynamics์ ์ํด <fixed to world>
์ joint๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์
ํ
ํฉ๋๋ค.
Setting Floating Dynamics in model.sdf
<?xml version="1.0"?>
<sdf version='1.6'>
<model name='rok3_model'>
<!--joint name="fixed to world" type="fixed">
<parent>world</parent>
<child>base_link</child>
</joint-->
.
.
.
</model>
</sdf>
Setting Fixed Dynamics in model.sdf
<?xml version="1.0"?>
<sdf version='1.6'>
<model name='rok3_model'>
<joint name="fixed to world" type="fixed">
<parent>world</parent>
<child>base_link</child>
</joint>
.
.
.
</model>
</sdf>
๋ค์์ผ๋ก, catkin_ws/src/RobotControl2022/worlds
ํด๋์ ์๋ rok3.world
๋ฅผ ์ฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ Fixed / Floating Dynamics์ ์ํด ๋ชจ๋ธ์ <pose frame>
์ ๋ค์๊ณผ ๊ฐ์ด ์
ํ
ํฉ๋๋ค.
Setting Floating Dynamics in rok3.world
<?xml version="1.0" ?>
<sdf version="1.6">
<world name="rok3">
.
.
.
<include>
<uri>model:https://rok3_model</uri>
<pose frame=''>0 0 0.947 0 0 0</pose>
<plugin name="rok3_plugin" filename="librok3_pkgs.so"/>
</include>
</world>
</sdf>
Setting Fixed Dynamics in rok3.world
<?xml version="1.0" ?>
<sdf version="1.6">
<world name="rok3">
.
.
.
<include>
<uri>model:https://rok3_model</uri>
<pose frame=''>0 0 1.947 0 0 0</pose>
<plugin name="rok3_plugin" filename="librok3_pkgs.so"/>
</include>
</world>
</sdf>
-
rok3_plugin.cc
๋ Gazebo main code ์ด๋ฉฐ,/catkin_ws/src/RobotControl2022/src
์ ์์ต๋๋ค. -
๊ทธ๋ฆฌ๊ณ ,
rok3_plugin.cc
์์ ์ฌ์ฉ์๋ ๋ฐ๋์Load(physics::ModelPtr _model, sdf::ElementPtr /*_sdf*/)
ํจ์์์, ์๋ ์ฝ๋ ์์์ ๊ฐ์ดAddons::URDFReadFromFile()
ํจ์ ์์ ์ ์ฉ๋์ด ์๋rok3_model.urdf
์ ๊ฒฝ๋ก๋ฅผ ํ์ธํด์ฃผ์๊ณ , ํ๋ฆฐ๋ค๋ฉด ๋ฐ๋ก์ก์์ฃผ์๊ธฐ ๋ฐ๋๋๋ค. -
rok3_model.urdf
๋home/.gazebo/models/rok3_model/urdf
ํด๋์ ์์ผ๋ฉฐ, ํ์ผ ์์ฑ ํ์ธ์ ํตํด ์ ํํ ๊ฒฝ๋ก ํ์ธํ์๊ธฐ ๋ฐ๋๋๋ค.
rok3_model.sdf
ํ์ผ ์ค๋ฅธ์ชฝ ํด๋ฆญ ->Properties
->Location
ํ์ธ
In rok3_plugin.cc
void gazebo::rok3_plugin::Load(physics::ModelPtr _model, sdf::ElementPtr /*_sdf*/)
{
/*
* Loading model data and initializing the system before simulation
*/
//* model.sdf file based model data input to [physics::ModelPtr model] for gazebo simulation
model = _model;
//* [physics::ModelPtr model] based model update
GetJoints();
//* RBDL API Version Check
int version_test;
version_test = rbdl_get_api_version();
printf(C_GREEN "RBDL API version = %d\n" C_RESET, version_test);
//* model.urdf file based model data input to [Model* rok3_model] for using RBDL
Model* rok3_model = new Model();
Addons::URDFReadFromFile("/root/.gazebo/models/rok3_model/urdf/rok3_model.urdf", rok3_model, true, true);
//โโโ Check File Path โโโ
nDoF = rok3_model->dof_count - 6; // Get degrees of freedom, except position and orientation of the robot
joint = new ROBO_JOINT[nDoF]; // Generation joint variables struct
//* initialize and setting for robot control in gazebo simulation
SetJointPIDgain();
//* setting for getting dt
last_update_time = model->GetWorld()->GetSimTime();
update_connection = event::Events::ConnectWorldUpdateBegin(boost::bind(&rok3_plugin::UpdateAlgorithm, this));
}
๋ชจ๋ ์ค๋น ๊ณผ์ ์ด ๋๋๋ฉด, catkin_make
์ ์
๋ ฅํ์ฌ ์ปดํ์ผ์ ์งํํฉ๋๋ค.
cd ~/catkin_ws && catkin_make
์ต์ข ์ ์ผ๋ก, ๋ค์๊ณผ ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ํตํด ์๋ฎฌ๋ ์ด์ ์คํ
roslaunch rok3_study_pkgs rok3.launch
- void Practice() ํจ์ ๋ง๋ค๊ธฐ
void Practice()
- Practice() ํจ์์์ matrix ์์ฑ ๋ฐ ํฐ๋ฏธ๋์ฐฝ์ ์ธ์ํ๊ธฐ
- cout ์ฌ์ฉ
std::cout << "C_IE = " << C_IE << std::endl;
- Load ํจ์ ์ฒซ์ค์ Practice() ํจ์ ์ฌ์ฉ
- 3-link planar arm๋ฅผ ์ํ Homogeneous Transformation Matrix ๋ง๋ค๊ธฐ
- ๋ชจ๋ ๋งํฌ์ ๊ธธ์ด๋ 1m๋ก ๊ฐ์
MatrixXd getTransformI0()
MatrixXd jointToTransform01(VectorXd q)
MatrixXd jointToTransform12(VectorXd q)
MatrixXd jointToTransform23(VectorXd q)
MatrixXd getTransform3E()
- Forward Kinematics ๋ง๋ค๊ธฐ
VectorXd jointToPosition(VectorXd q)
MatrixXd jointToRotMat(VectorXd q)
VectorXd rotToEuler(MatrixXd rotMat) // EulerZYX
- Homogeneous Transformation Matrix ๋ง๋ค๊ธฐ
MatrixXd getTransformI0()
MatrixXd jointToTransform01(VectorXd q)
MatrixXd jointToTransform12(VectorXd q)
MatrixXd jointToTransform23(VectorXd q)
MatrixXd jointToTransform34(VectorXd q)
MatrixXd jointToTransform45(VectorXd q)
MatrixXd jointToTransform56(VectorXd q)
MatrixXd getTransform6E()
- Forward Kinematics ๋ง๋ค๊ธฐ
VectorXd jointToPosition(VectorXd q)
MatrixXd jointToRotMat(VectorXd q)
VectorXd rotToEuler(MatrixXd rotMat)
- q=[10;20;30;40;50;60] ์ผ๋, End-effector์ position๊ณผ Rotation Matrix ๊ตฌํ๊ธฐ
- ์ด๋, Euler Angle ๊ตฌํ๊ธฐ
- source ์ฝ๋
- ์ถ๋ ฅ๋ ๊ฒฐ๊ณผ๋ฌผ capture ํ์ผ
- jointToPosJac ํจ์ ๋ง๋ค๊ธฐ
MatrixXd jointToPosJac(VectorXd q)
{
// Input: vector of generalized coordinates (joint angles)
// Output: J_P, Jacobian of the end-effector translation which maps joint velocities to end-effector linear velocities in I frame.
MatrixXd J_P = MatrixXd::Zero(3,6);
MatrixXd T_I0(4,4), T_01(4,4), T_12(4,4), T_23(4,4), T_34(4,4), T_45(4,4), T_56(4,4), T_6E(4,4);
MatrixXd T_I1(4,4), T_I2(4,4), T_I3(4,4), T_I4(4,4), T_I5(4,4), T_I6(4,4);
MatrixXd R_I1(3,3), R_I2(3,3), R_I3(3,3), R_I4(3,3), R_I5(3,3), R_I6(3,3);
Vector3d r_I_I1(3), r_I_I2(3), r_I_I3(3), r_I_I4(3), r_I_I5(3), r_I_I6(3);
Vector3d n_1(3), n_2(3), n_3(3), n_4(3), n_5(3), n_6(3);
Vector3d n_I_1(3),n_I_2(3),n_I_3(3),n_I_4(3),n_I_5(3),n_I_6(3);
Vector3d r_I_IE(3);
//* Compute the relative homogeneous transformation matrices.
T_I0 =
T_01 =
T_12 =
T_23 =
T_34 =
T_45 =
T_56 =
T_6E =
//* Compute the homogeneous transformation matrices from frame k to the inertial frame I.
T_I1 =
T_I2 =
T_I3 =
T_I4 =
T_I5 =
T_I6 =
//* Extract the rotation matrices from each homogeneous transformation matrix. Use sub-matrix of EIGEN. https://eigen.tuxfamily.org/dox/group__QuickRefPage.html
R_I1 = T_I1.block(0,0,3,3);
R_I2 =
R_I3 =
R_I4 =
R_I5 =
R_I6 =
//* Extract the position vectors from each homogeneous transformation matrix. Use sub-matrix of EIGEN.
r_I_I1 =
r_I_I2 =
r_I_I3 =
r_I_I4 =
r_I_I5 =
r_I_I6 =
//* Define the unit vectors around which each link rotate in the precedent coordinate frame.
n_1 << 0,0,1;
n_2 <<
n_3 <<
n_4 <<
n_5 <<
n_6 <<
//* Compute the unit vectors for the inertial frame I.
n_I_1 = R_I1*n_1;
n_I_2 =
n_I_3 =
n_I_4 =
n_I_5 =
n_I_6 =
//* Compute the end-effector position vector.
r_I_IE =
//* Compute the translational Jacobian. Use cross of EIGEN.
J_P.col(0) << n_I_1.cross(r_I_IE-r_I_I1);
J_P.col(1) <<
J_P.col(2) <<
J_P.col(3) <<
J_P.col(4) <<
J_P.col(5) <<
//std::cout << "Test, JP:" << std::endl << J_P << std::endl;
return J_P;
}
- jointToRotJac ํจ์ ๋ง๋ค๊ธฐ
MatrixXd jointToRotJac(VectorXd q)
{
// Input: vector of generalized coordinates (joint angles)
// Output: J_R, Jacobian of the end-effector orientation which maps joint velocities to end-effector angular velocities in I frame.
MatrixXd J_R(3,6);
MatrixXd T_I0(4,4), T_01(4,4), T_12(4,4), T_23(4,4), T_34(4,4), T_45(4,4), T_56(4,4), T_6E(4,4);
MatrixXd T_I1(4,4), T_I2(4,4), T_I3(4,4), T_I4(4,4), T_I5(4,4), T_I6(4,4);
MatrixXd R_I1(3,3), R_I2(3,3), R_I3(3,3), R_I4(3,3), R_I5(3,3), R_I6(3,3);
Vector3d n_1(3), n_2(3), n_3(3), n_4(3), n_5(3), n_6(3);
//* Compute the relative homogeneous transformation matrices.
//* Compute the homogeneous transformation matrices from frame k to the inertial frame I.
//* Extract the rotation matrices from each homogeneous transformation matrix.
//* Define the unit vectors around which each link rotate in the precedent coordinate frame.
//* Compute the translational Jacobian.
//std::cout << "Test, J_R:" << std::endl << J_R << std::endl;
return J_R;
}
- q=[10;20;30;40;50;60] ์ผ๋, Geometric Jacobian ๊ตฌํ๊ธฐ
- source ์ฝ๋
- ์ถ๋ ฅ๋ ๊ฒฐ๊ณผ๋ฌผ capture ํ์ผ
- pseudoInverseMat ํจ์ ๋ง๋ค๊ธฐ
MatrixXd pseudoInverseMat(MatrixXd A, double lambda)
{
// Input: Any m-by-n matrix
// Output: An n-by-m pseudo-inverse of the input according to the Moore-Penrose formula
MatrixXd pinvA;
return pinvA;
}
- rotMatToRotVec ํจ์ ๋ง๋ค๊ธฐ : rotation matrix๋ฅผ ์ ๋ ฅ์ผ๋ก ๋ฐ์์ rotation vector๋ฅผ ๋ด๋ณด๋ด๋ ํจ์
VectorXd rotMatToRotVec(MatrixXd C)
{
// Input: a rotation matrix C
// Output: the rotational vector which describes the rotation C
Vector3d phi,n;
double th;
if(fabs(th)<0.001){
n << 0,0,0;
}
else{
}
phi = th*n;
return phi;
}
- q=[10;20;30;40;50;60] ์ผ๋, Jacobian์ pseudoInverse ๊ตฌํ๊ธฐ
pinvJ = pseudoInverseMat(J);
- q_des=[10;20;30;40;50;60], q_init=0.5q_des ์ผ๋, C_err(dph)=C_des*C_init.transpose() ๊ตฌํ๊ธฐ
- rotMatToRotVec ํจ์๋ก dph๊ตฌํ๊ธฐ
dph = rotMatToRotVec(C_err);
- source ์ฝ๋
- ์ถ๋ ฅ๋ ๊ฒฐ๊ณผ๋ฌผ capture ํ์ผ => dph = [0.00;1.14;-0.19]
- inverseKinematics ํจ์ ๋ง๋ค๊ธฐ
VectorXd inverseKinematics(Vector3d r_des, MatrixXd C_des, VectorXd q0, double tol)
{
// Input: desired end-effector position, desired end-effector orientation, initial guess for joint angles, threshold for the stopping-criterion
// Output: joint angles which match desired end-effector position and orientation
double num_it;
MatrixXd J_P(6,6), J_R(6,6), J(6,6), pinvJ(6,6), C_err(3,3), C_IE(3,3);
VectorXd q(6),dq(6),dXe(6);
Vector3d dr(3), dph(3);
double lambda;
//* Set maximum number of iterations
double max_it = 200;
//* Initialize the solution with the initial guess
q=q0;
C_IE = ...;
C_err = ...;
//* Damping factor
lambda = 0.001;
//* Initialize error
dr = ... ;
dph = ... ;
dXe << dr(0), dr(1), dr(2), dph(0), dph(1), dph(2);
////////////////////////////////////////////////
//** Iterative inverse kinematics
////////////////////////////////////////////////
//* Iterate until terminating condition
while (num_it<max_it && dXe.norm()>tol)
{
//Compute Inverse Jacobian
J_P = ...;
J_R = ...;
J.block(0,0,3,6) = J_P;
J.block(3,0,3,6) = J_R; // Geometric Jacobian
// Convert to Geometric Jacobian to Analytic Jacobian
dq = pseudoInverseMat(J,lambda)*dXe;
// Update law
q += 0.5*dq;
// Update error
C_IE = ...;
C_err = ...;
dr = ...;
dph = ...;
dXe << dr(0), dr(1), dr(2), dph(0), dph(1), dph(2);
num_it++;
}
std::cout << "iteration: " << num_it << ", value: " << q << std::endl;
return q;
}
- q=[10;20;30;40;50;60] ์ผ๋, ์ด ๊ด์ ๊ฐ๋์ ํด๋นํ๋ end-effoctor์ ๊ฐ์ r_des์ C_des๋ก ์ค์ ํ๊ณ ,
- r_des์ C_des์ ๋ํ joint angle ๊ตฌํ๊ธฐ
void Practice()
{
...
// q = [10;20;30;40;50;60]*pi/180;
r_des = jointToPostion(q);
C_des = jointToRotMat(q);
q_cal = inverseKinematics(r_des, C_des, q*0.5, 0.001);
}
- source ์ฝ๋
- ์ถ๋ ฅ๋ ๊ฒฐ๊ณผ๋ฌผ capture ํ์ผ
- Desired Pos = [0;0.105;-0.55] & Desired Orientation = Base
- Result = [0;0;-63.756;127.512;-63.756]
- 1-cos ํจ์๋ก trajectory ์์ฑํ๊ธฐ
double func_1_cos(double t, double, init, double final, double T)
{
double des;
...
return des;
}
- 5์ด๋์, ์ด๊ธฐ์์ธ์์ ์ค์ต5-2์ ์์ธ๋ก ์์ง์ด๊ธฐ in Joint Coordinates
- 5์ด๋์, z๋ฐฉํฅ์ผ๋ก 0.2m ์ด๋ํ๊ธฐ(๋ค๋ฆฌ๋ค๊ธฐ) in Cartesian Coordinates
- 5์ด๋์ 0.2m ๋ค๋ฆฌ๋ค๊ธฐ, 5์ด๋์ 0.2m ๋ค๋ฆฌ๋ด๋ฆฌ๊ธฐ in Cartesian Coordinates
- 5์ด๋์ 0.2m ๋ค๋ฆฌ๋ค๊ธฐ, 5์ด๋์, z์ถ์ผ๋ก 90๋ ํ์ ํ๊ธฐ in Cartesian Coordinates
- 5์ด๋์, Walk ready ์์ธ ๋ง๋ค๊ธฐ
- Right foot : Desired Pos = [0;0.105;-0.55] & Desired Orientation = Base) (Joint Coordinates)
- Left foot : Desried Pos = [0;-0.105;-0.55] & Desired Orientation = Base) (Joint Coordinates)
- ์ค๋ฅธ๋ฐ ์ง์งํ๋ฉฐ, ์ผ๋ฐ ๋ค๊ธฐ (Cartesian Coordinates)
- ๋๋ฐ ์ง์ง (Cartesian Coordinates)
- ์ผ๋ฐ ์ง์งํ๋ฉฐ, ์ค๋ฅธ๋ฐ ๋ค๊ธฐ (Cartesian Coordinates)
- ๋๋ฐ ์ง์ง (Cartesian Coordinates)
- ๋ ์์ ์ค์ต 7 ์ํํ๊ธฐ