Skip to content

Commit

Permalink
add GUI example with turtlesim and rqt. (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya.Fujita <Tomoya.Fujita@sony.com>
  • Loading branch information
fujitatomoya authored Aug 8, 2023
1 parent e30afcd commit be088ae
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 6 deletions.
47 changes: 41 additions & 6 deletions docs/ROS2_Deployment_Intermediate.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,57 @@ To control the capability such as `which node has display`, it will use node lab

**see deployment description [ROS 2 turtlesim and rqt](./../yaml/ros2-turtlesim.yaml)**

![ROS 2 Turtlesim and Rqt Example](./../images/ros2_turtlesim_sample.png)
![ROS 2 Turtlesim and Rqt Overview](./../images/ros2_turtlesim_overview.png)

- Disable xhost access control

```bash
tomoyafujita@~/DVT >xhost +local:root
non-network local connections being added to access control list
```

- Labeling the display capability.

In this example, `edgeserver` is the server runs GUI capability, but `edgedevice`.

```bash
xxx
root@tomoyafujita-HP-Compaq-Elite-8300-SFF:~# kubectl label nodes tomoyafujita-hp-compaq-elite-8300-sff nodetype=edgeserver
root@tomoyafujita-HP-Compaq-Elite-8300-SFF:~# kubectl label nodes ubuntu nodetype=edgedevice
root@tomoyafujita-HP-Compaq-Elite-8300-SFF:~# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
tomoyafujita-hp-compaq-elite-8300-sff Ready control-plane 63m v1.25.5 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=tomoyafujita-hp-compaq-elite-8300-sff,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=,nodetype=edgeserver
ubuntu Ready <none> 45m v1.25.5 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=ubuntu,kubernetes.io/os=linux,nodetype=edgedevice
```

- Start turtlesim and rqt on the node with display.
- Start turtlesim and rqt on `edgeserver`, and start bash process node in `edgedevice`.

```bash
xxx
root@tomoyafujita-HP-Compaq-Elite-8300-SFF:/ros_k8s/yaml# kubectl apply -f ros2-turtlesim.yaml
deployment.apps/ros2-turtlesim-gui created
deployment.apps/rqt created
deployment.apps/ros2-teleop-key created
```

- Use `turtle_teleop_key` to control the turtlesim.

process is already running in the cluster system on the host `edgedevice` labeled, so we can jump in the container `turtle_teleop_key` via kubernetes command as below.

```bash
xxx
```
root@tomoyafujita-HP-Compaq-Elite-8300-SFF:/ros_k8s/yaml# kubectl get pods
NAME READY STATUS RESTARTS AGE
ros2-teleop-key-75f7c5475c-s6hwj 1/1 Running 0 33s
ros2-turtlesim-gui-849df7c66b-gzmt9 1/1 Running 0 33s
rqt-5886589dfc-v8q92 1/1 Running 0 33s
root@tomoyafujita-HP-Compaq-Elite-8300-SFF:/ros_k8s/yaml# kubectl exec --stdin --tty ros2-teleop-key-75f7c5475c-s6hwj -- /bin/bash

root@ros2-teleop-key-75f7c5475c-s6hwj:/# source /opt/ros/rolling/setup.bash
root@ros2-teleop-key-75f7c5475c-s6hwj:/# ros2 run turtlesim turtle_teleop_key
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
Use G|B|V|C|D|E|R|T keys to rotate to absolute orientations. 'F' to cancel a rotation.
'Q' to quit.
...
```

<img src="./../images/ros2_turtlesim_output.png" width="800">
Binary file added images/ros2_turtlesim_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ros2_turtlesim_overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/system_overview.odp
Binary file not shown.
131 changes: 131 additions & 0 deletions yaml/ros2-turtlesim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ros2-turtlesim-gui
spec:
replicas: 1
selector:
matchLabels:
app: ros2-turtlesim-gui
template:
metadata:
labels:
app: ros2-turtlesim-gui
spec:
containers:
- image: tomoyafujita/ros:rolling
command: ["/bin/bash", "-c"]
args: ["source /opt/ros/$ROS_DISTRO/setup.bash && ros2 run turtlesim turtlesim_node"]
imagePullPolicy: IfNotPresent
tty: true
name: ros2-turtlesim-gui
### mounting host file to container
volumeMounts:
- mountPath: /tmp/.X11-unix
name: xserver
### bind host environment variable to container
env:
- name: DISPLAY
value: ":1" # can this be host variable instead?
### select the node with GUI for this deployment
nodeSelector:
nodetype: edgeserver
### bind the host xserver unix to the container
volumes:
- name: xserver
hostPath:
path: /tmp/.X11-unix
type: Directory # host should have this always
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
restartPolicy: Always

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: rqt
spec:
replicas: 1
selector:
matchLabels:
app: rqt
template:
metadata:
labels:
app: rqt
spec:
containers:
- image: tomoyafujita/ros:rolling
command: ["/bin/bash", "-c"]
args: ["source /opt/ros/$ROS_DISTRO/setup.bash && rqt"]
imagePullPolicy: IfNotPresent
tty: true
name: rqt
### mounting host file to container
volumeMounts:
- mountPath: /tmp/.X11-unix
name: xserver
### bind host environment variable to container
env:
- name: DISPLAY
value: ":1" # can this be host variable instead?
### select the node with GUI for this deployment
nodeSelector:
nodetype: edgeserver
### bind the host xserver unix to the container
volumes:
- name: xserver
hostPath:
path: /tmp/.X11-unix
type: Directory # host should have this always
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
restartPolicy: Always

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: ros2-teleop-key
spec:
replicas: 1
selector:
matchLabels:
app: ros2-teleop-key
template:
metadata:
labels:
app: ros2-teleop-key
spec:
containers:
- image: tomoyafujita/ros:rolling
command: ["/bin/bash", "-c"]
#args: ["source /opt/ros/$ROS_DISTRO/setup.bash && ros2 run turtlesim turtle_teleop_key"]
args: ["/bin/bash"]
imagePullPolicy: IfNotPresent
tty: true
name: ros2-teleop-key
### select the node w/o GUI for this deployment
nodeSelector:
nodetype: edgedevice
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
restartPolicy: Always

0 comments on commit be088ae

Please sign in to comment.