# 工作紀錄 / 楊鈞愷
###### tags: `工作紀錄`
## 前言
這裡只記錄了我到目前為止實作的歷程以及想法,還有遭遇的問題與解法,試圖在走過的路上留下足跡,以供日後參考。
關於想法與相關資訊可能未經查證,需特別注意。
## FRANKA EMIKA Panda: 從 Gazebo 到 Webots
- 在ROS框架下,多半使用URDF(Unified Robot Description Format)和XACRO這樣的XML文件來描述機器人的模型
- 而Gazebo就是ROS框架與URDF/XACRO主要支援的模擬器
- 使用[官方franka_ros github](https://github.com/frankaemika/franka_ros/tree/kinetic-devel/franka_description/robots)中提供的URDF/XACRO模型檔要如何在Gazebo上模擬可以參考此[網誌](https://erdalpekel.de/?p=55)
- 然而,Webots並不支援URDF/XACRO格式的文件
- Webots主要支援另一種描述3D模型的語言 - VRML(Virtual Reality Modeling Language),以及PROTO檔(*此部分不完整*)
注意:VRML必須是VRML97
- 因此,要移植到Webots我們有以下幾種可能的方法:
1. URDF to Webots(透過[Webots套件](https://github.com/cyberbotics/urdf2webots))
2. XACRO to Webots(透過ROS2套件)
3. 轉換[手臂官方之STEP檔](https://wiredworkers.io/download-franka-emika-panda-step-file/)(應該是一種CAD模型檔) to VRML97(.wrl檔)
4. 轉換其他CAD檔案 to VRML97
- 由於我只有踩進==3.== 這個坑,因此以下將著重在==3.== 之方法
## STEP to VRML97(.wrl)
透過[CAD Exchanger](https://cadexchanger.com/)將STEP檔轉成VRML97格式(wrl檔)
亦有文章或官方文件推薦使用SolidWorks, Blender, AutoCAD等CAD軟體
- 透過CAD Exchanger開啟並轉換STEP檔為VRML97格式

- Import VRML97 to Webots

- ==從第一張圖片中的STEP檔結構,我們就可以發現此模型檔包含8個主要部件(連接7個關節),以及數個名為PROTECTOR的小零件==
- 小零件如:

- looks so good, but...
## 遭遇的問題與困難
1. STEP檔中只有3D模型,缺少了關節資訊(joint)與各部件的物理參數
(或是在轉檔成VRML97時遺失)
2. 基於上述原因,我們必須學習Webots中裝配機器人的方法,自行調整各個部件之間的階層架構,使用Webots中的元件完成關節的組裝
3. 缺少或是不準確的物理參數(質量、摩擦係數等)可能導致模擬與實際手臂不相符,此狀況是否是可以被接受的?
若要準確模擬出實際手臂,則必須取得詳細物理參數(包含上述小零件之質量是否需要考慮等等)
[有關物理參數不準確 可參見廖軒裕7/9之工作紀錄](https://hackmd.io/WCklC078TveUMd_KGiMe6A?view#W2D4-0709)
## 7/10
Paper: [Differentiable Augmentation
for Data-Efficient GAN Training](https://arxiv.org/pdf/2006.10738.pdf)
- Abstract and Introduction
- Concepts of FID and IS
- [Learderboard for ImageNet 128x128](https://paperswithcode.com/sota/conditional-image-generation-on-imagenet)
[Notes](https://hackmd.io/gn8fkvX3QlWDHe_pa9OmpQ?view)
## 7/13
the same paper
- Introduction ~ Method
- [ML review(Coursera - Andrew Ng)](https://www.itread01.com/content/1545889984.html)
## 7/14
the same paper
- ~ Conclusion
## 7/15
trying to assemble panda arm in webots
## 7/20
applying ikpy to control the robot with inverse kinematics
- [ikpy](https://github.com/Phylliade/ikpy)
- [ikpy wiki](https://github.com/Phylliade/ikpy/wiki)
- [ikpy docs](https://ikpy.readthedocs.io/en/latest/)
[controller at github](https://github.com/CT-Lab/controller-testing)
[sample ikpy controller](http://codepad.org/4HCQis2I)
Issue: 範例機器手臂中,joint的anchor與同一層之solid的translation是相同的,而Chain的每一個URDFLink中的translation_vector即是使用此vector。然而在我們的手臂中,anchor與solid的translation並不盡相同,因此不確定要使用何者。
## 7/21
Issue: anchor和translation調整為相同之後,下一個問題是手臂之中存在轉動過的座標系,同樣的向量有可能指向不同地方,ikpy如何獲得這項資訊?
Meeting: [Dopamine (RL相關)](https://opensource.google/projects/dopamine)
## 7/22
Todo:
- [x] paper ppt增加IS FID敘述
- [x] 錄webots手臂控制[demo影片](https://drive.google.com/file/d/1cX0iKnKp70jeqhgJk-JGyW-8f6QYjOng/view?usp=sharing)
## 7/24
Meeting:
- Dopamine
- Franka + ROS
- x86?
## 7/27, 28
Dopamine:
- available on windows?
- [will this framework work in windows 10?](https://github.com/google/dopamine/issues/21)
- [Google Dopamine on Windows](https://discourse.aicrowd.com/t/google-dopamine-on-windows/536)
- [error running basic example on windows 10](https://github.com/google/dopamine/issues/97)
- 4 RL agents
TODO:
- [x] example colab: how to use Dopamine
## 7/29
Issue about the [Differentiable Augmentation
for Data-Efficient GAN Training](https://arxiv.org/pdf/2006.10738.pdf)
- dataset經過augment後,圖片並不會變多
- 10% dataset經過augment後仍然是10%的資料量
- 有關應用於NAS上的疑慮:
- 實驗結果顯示,只使用10% data時,FID已經來到20~30,可以預見當資料更少時,生成的圖片將會變得不穩定,且與top performance相距甚遠
- 實驗結果也顯示,10% data時表現較好不代表100% data時表現也較好
[Notes](https://hackmd.io/gn8fkvX3QlWDHe_pa9OmpQ?view)
[Code of the paper](https://github.com/mit-han-lab/data-efficient-gans)
## Trace Code
[學長的code (Dopamine to Webots) in our github](https://github.com/CT-Lab/Dopamine_Webots/tree/master/controllers)
interacting programs
in Webots: endpoint, endpoint_env
outside: train, run_experiment
- **train**: 一次training的進入點
- `launch_experiment()` create a runner with specific Dopamine agent and then call `runner.run_experiment()`
- **run_experiment**: define training process (iteration, episode, etc)
- a `runner` will initialize an environment (nothing), tf.Session, and an agent
- `run_experiment()` to `_run_one_iteration()` in a for-loop
- `_run_one_iteration()` -> `_run_train(eval)_phase()` -> `_run_one_phase()` -> loop `_run_one_episode()` -> a full trajectory
- `_run_one_episode()`: keep interacting until reaching a terminal state
- `_run_one_step()` to do actions and get observation, state, reward, etc
- check if an episode should be terminated
- if not, pass reward... to agent to get action
- `_run_one_step()`:
- write action to pipe; **endpoint.py will catch this**
- read returning reward... from pipe; **written by endpoint.py**
- **endpoint2D**: robot controller
- `read_from_pipe()` to get action
- call `step(action)` to pass action to environment and get reward, state, info, etc returned after executing the action
- `write_to_pipe()` to send these data back to the agent
- **endpoint_env**: Webots environment
- define `step()` and state, reward, etc
- **pipe**: implemented with Linux pipe; not using Python's multiprocessing module Pipe
- [ref1](https://www.hwchiu.com/c-pipe.html) [ref2](https://www.cnblogs.com/littlehann/p/6906164.html) [ref3](https://www.eadan.net/blog/ipc-with-named-pipes/)
- IPC, based on file system
- communication between robot controller and RL agent
- endpoint+endpoint_env <=> run_experiment
- **Notes**: channel pipe is for multi-Webots-simulation
1. 如何定義action
2. 需要環境的什麼資料(state)
3. 怎麼設計goal與reward
## Demo
https://drive.google.com/file/d/1LAMEbxVlHH6O-tiNLG9s0rohhGu1ZLZb/view?usp=sharing
## TODO
- [ ] review Q-learning and related tf functions
- [ ] trace code [(github)](https://github.com/CT-Lab/Dopamine_Webots/tree/master/controllers)