---
# System prepended metadata

title: TGIO1 BUILD UP
tags: [TGIO1]

---

---
tags: TGIO1
---

# TGIO1 BUILD UP

OS version: Ubuntu 20.04

UserAccount: tirc
Password: tirc

---
[TOC]
## 電腦部分設定

### 外接螢幕輸出
此單板電腦的原始影像輸出為eDP腳位，而不是HDMI或DSUB，這件事在重灌系統等方面會有影響。成功灌入UBUNTU系統後，ALT+CTRL+T開啟terminal使用xrandr指令，強行把eDP輸出關掉，詳細參考下列網頁說明。(reboot後會還原)

```bash=
xrandr --output eDP-1 --off
```
> 詳情見[此處](https://www.arthurtoday.com/2012/09/ubuntu-xrandr-switch-to-external-monitor-command.html)
---

### 進入BIOS更改comport介面

這個不要看

| Component | COM | Port | Interface |
| -------- | -------- | -------- |-|
| Battery     |COM1   |ttyS0    |RS485|
|PXV|COM2|ttyS1|RS485|
|Gremsy|ttyUSB0|ttyUSB0|UART|
|EPOS2(SkyTrackerMotor)|node|3|USB|
|EPOS2(CameraHanger)|node|1|USB|
|FLIR A50|LAN1|LAN1|RJ45|


---
### 若遇見應用商店打不開情況:
```bash=
sudo apt-get install --reinstall software-center
```
> [name=HarrisonHuang] Reference: [ubuntu的应用商店打不开，闪退](https://blog.csdn.net/zhangkzz/article/details/89712717)

## 環境建置

### 安裝必要套件
```bash=
sudo apt-get update
sudo apt install build-essential
```
---

### 無線網路卡開機無法自動識別連上網路(需要重新插入)解決辦法
#### 安裝對應Driver
```bash=
sudo apt-get install git linux-headers-generic build-essential dkms;
git clone https://github.com/Mange/rtl8192eu-linux-driver;
cd rtl8192eu-linux-driver;
sudo dkms add .;
sudo dkms install rtl8192eu/1.0;
echo "blacklist rtl8xxxu" | sudo tee /etc/modprobe.d/rtl8xxxu.conf;
echo -e "8192eu\n\nloop" | sudo tee /etc/modules;
echo "options 8192eu rtw_power_mgnt=0 rtw_enusbss=0" | sudo tee /etc/modprobe.d/8192eu.conf;
sudo update-grub; sudo update-initramfs -u;
systemctl reboot -i;
sudo lshw -c network; # Check that your kernel has loaded the right module:
```
> Reference: [參考](https://github.com/Mange/rtl8192eu-linux-driver)
---
### 遠端桌面設定(TeamViewer)
#### ID: 404548346
```bash=
# download from the official website
sudo dpkg -i teamviewer*.deb

# start application command
# make it turn on when the PC boot
/usr/bin/teamviewer
```
> Reference: [參考](http://mh-resource.blogspot.com/2013/04/linuxubuntuteamviewer.html)
---
### 使用Serial port需設定權限
```bash=
sudo adduser $USER dialout
```
---



### Install ROS, version: noetic
[Ubuntu install of ROS Noetic](http://wiki.ros.org/noetic/Installation/Ubuntu)
> [name=HarrisonHuang] **Please remember to setup environment** 
>> Include path in /opt/ros/... and ~/catkin_ws/devel/... 
>> (based on where you build you workspace)
---
## Source file import

### Create ROS workspace: catkin_ws
```bash=
cd ~
mkdir catkin_ws | cd catkin_ws
mkdir src
cd ..
catkin_make
```
---

### Import **pxvNode** package
```bash=
cd ~/catkin_make/src/
git clone https://bitbucket.org/tirctw/pxvnode.git
```
> [name=Harrison Huang]綠(T/R+) 黃(T/R-)
> 
> PXV有距離限制，第二個燈號亮綠燈代表有成功辨識，亮紅燈代表無法辨識(條碼可能過近/過遠/損毀/視野內條碼數過少)
---
### maxon_epos

#### Linux
##### Install EPOS Library(Ubuntu 20.04)
由[EPOS Linux Library](https://www.maxongroup.ch/maxon/view/product/control/Positionierung/530239)下載並安裝 (下載 -> 軟體/韌體 -> EPOS Linux Library)

```bash=
unzip EPOS_Linux_Library.zip -d . //一定要從此步驟解壓縮
sudo apt-get install unzip // If the unzip program is not available
cd EPOS_Linux_Library
sudo bash ./install.sh
```

```bash=
git clone https://bitbucket.org/tirctw/maxon_epos.git
```

---
#### Windows test
##### Install EPOS Studio(Windows 10)

[下載EPOS studio](https://www.maxongroup.ch/maxon/view/product/control/Positionierung/530239)
> [name=Harrison]EPOS Studio可用於初步設定、測試基本功能與確定node
---

##### 使用EPOS studio開始設定epos2(SkyTrackerMotor(OLD))
###### Step1-5: 
硬體接線 (power、motor control、encoder)
開啟EPOS Studio => 選擇EPOS2 Project
右鍵project -> wizard -> Startup Wizard
USB -> EC Motor -> Block(Hallsensor) -> Hallsensor

###### Step6: System data
| parameter                     | value    |
| --------                      | -------- |
| Max. Application Speed        | 8000 rpm |
| Nominal Current               | 5000mA     |
| Max. Output Current Limit     | Text     |
| Thermal Time Constant Winding | 18.5 s   |
| Number of Pole Pairs          | 8        |
###### Step7: Safty Parameter Position
| parameter                     | value    |
| --------                      | -------- |
| Max. following error          | 2048 qc  |

完成後可右鍵project -> regulation tuning -> auto

######  Other Parameters
| parameter                     | value    |
| --------                      | -------- |
| Max. profile velocity         | 4500 rpm  |
| Quickstop Deceleration        | 2000 rpm/s|

##### I/O settings
![](https://i.imgur.com/K4Dr0nN.png)

I/O configuration
![](https://i.imgur.com/qPJn22z.png)

##### 使用EPOS studio開始設定(hangerTrackRobot)
##### **EPOS4**
| parameter                     | value    |
| --------                      | -------- |
|**Motor**||
| Motor type        | maxon EC motor(BLDC) |
| Nominal Current               | 5000mA     |
| Torque constant     | (checked)Identifying during mechanical system identification  |
| Thermal Time Constant Winding | 18.5 s   |
| Max speed|6250 rpm|
| Number of Pole Pairs          | 8        |
|**Sensors**||
|Polarity|(O)maxon|
|**Communication**||
|Type|Block communication|
|Sensors|X4 Digital Hall sensors|
|**Limits**||
|Max output current|30000 mA|
|Max acceleration|3000 rpm|
|Max profile velocity|6000 rpm|
|Following error window|2000 inc|

| Digital Inputs | Functionality | Polarity |
| -------- | -------- | -------- |
| Digital input 1|Negative limit switch| High active     |
| Digital input 2  | Positive limit switch  |High active|
| Digital input 3  | Home switch     |High active|
| Digital input 4  | General purpose A (none)|High active|

| Digital Outputs | Functionality | Polarity |
| -------- | -------- | -------- |
| Digital output 1|General purpose A (brake)|High active |
| Digital output 2|General purpose B (none)| High active |

---

##### Import maxon_epos2 package (not used anymore)

```bash=
git clone https://bitbucket.org/tirctw/maxonepos2.git
```

> [name=Harrison]
> EPOS2使用方法為接USB，使用nodeID決定要控制哪個驅動板，Linux下對驅動板初始化記得要先對特定nodeID設定setEnableState()
> 此處之code沒有再更改參數(加速度、減速度…)，若有更改需求可以使用EPOS2 Studio進行更改(建議)或是使用Library
> 
> Reference: [來源](https://www.maxongroup.com.tw/medias/sys_master/8830511546398.pdf)

若要使用getErrorCode可看MRD1內[MotorController.cpp](https://bitbucket.org/tirctw/mrd1/src/master/Maxon%20Motor%20Test/Maxon%20Motor%20Test/MotorController.cpp)

---
### Import robotController package
```bash=
git clone https://bitbucket.org/tirctw/robotcontroller.git
```
---
### Install DFI IPC GPIO Control Library (not used now)

於\\192.168.158.21\tirc\PRJ_TGIO1下載[EAPI_Sample_v1.7.70_210903.zip] ，讀docs內文件Linux部分設定即可
```bash=
cd robotcontroller
sudo cp libEAPI_Library.so /usr/lib
```
> 控制GPIO需要切換到root
> 記得參照DFI BT253 user manual將COM3跳至DIO

#### DFI BT253 GPIO ID
```
|--|--|--|--|--|--|--|
3  2  1  0  7  6  5  4 
```

---
### Install USB-4750 DIO Extension Install Driver
```bash=
cd robotcontroller
sudo su
bash linux_driver_source_4.0.4.0_64bit.run
# choose driver USB-4750
```
> [name=Harrison]Windows下載後安裝Linux driver後挪入
> Reference: [下載](https://www.advantech.eu/support/details/driver?id=1-1YPCECD)
---
### Import gremsyGimbal package
```bash=
git clone https://bitbucket.org/tirctw/gremsygimbal.git
```
> 裡面有個testNode可以拉出來後執行，記得先roscore或是roslaunch
```bash=
rosrun testNode testNode
```
> 此testNode可以輸入命令type, 並輸入三軸角度進行控制雲台

---

### Import ultrasonicSensor package
```bash=
git clone https://bitbucket.org/tirctw/ultrasonicsensor.git
```

---

### Import batteryMonitor package
```bash=
git clone https://bitbucket.org/tirctw/batterymonitor.git
```

---
### JoyStick Controller

#### Install Joy ROS Package

[安裝與測試範例](https://www.cnblogs.com/21207-iHome/p/8031905.html)
[Note for Launch File Setting](https://www.itread01.com/content/1549038810.html)


#### 安裝Logi wireless controller F710 (現TGIO1使用)
依照上方安裝與測試範例進行測試沒問題即可直接使用

#### 安裝XBox One Wireless Adapter的對應Linux Driver

依照[說明](https://github.com/medusalix/xow)進行安裝driver (必須使用ubuntu 18.04以上版本)


1. 要安裝對應套件，否則make會出錯
2. 似乎重開才會生效
3. 手把連接方式: 按手把上的大圓按鈕->壓前方的連線鍵->按usb dongle的按鈕

---
### ROS mqtt_bridge to broker
```bash=
sudo apt install python3-pip
sudo apt install ros-noetic-rosbridge-library
sudo apt install mosquitto mosquitto-clients

cd mqtt_bridge

# 此處使用super user安裝，以後launch ROS是以super user執行
sudo su
pip3 install -r requirements.txt
```
> reference: [參考](https://github.com/groove-x/mqtt_bridge)

---
### Build up the environment inside Ubuntu ( Java <--> ROS )
> reference: [Environment setup](https://hackmd.io/Ma2T_iayS2a7g1ZzB1tPmw?view)
---

### 開機自動啟動launch file

#### tgioLaunch.bash
```bash=
echo password | sudo -S su
sudo su << HERE

# ROS package path
source /home/tirc/catkin_ws/devel/setup.bash

# tgio project workspace
source /home/tirc/catkin_ws/devel/setup.bash

# launch file
roslaunch robotController tgio.launch

HERE
```

---

#### 於 start application 新增設定
```bash=
gnome-terminal --working-directory=/home/tirc/ -e 'bash tgioLauncher.bash'
```
> Reference: [參考](https://qastack.cn/unix/70859/why-doesnt-sudo-su-in-a-shell-script-run-the-rest-of-the-script-as-root)


## Others

### 設定watchdog
[設定watchdog module](https://forum.up-community.org/discussion/4638/itco-watchdog-in-ubuntu)

### 測試watchdog
[強制讓Linux系統崩潰](https://blog.csdn.net/masterbee/article/details/101159135)
