Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Build/Runtime errors + Dockerized #5

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ros:humble-ros-base

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3-pip && \
pip3 install flask-socketio websockets websocket-client requests && \
rm -rf /var/lib/apt/lists/*

# Clone the repository
WORKDIR /door_adapter_template_ws/src
RUN git clone https://github.com/open-rmf/rmf_internal_msgs.git --branch main --single-branch --depth 1
COPY ./door_adapter_template door_adapter_template/

# Setup the workspace
WORKDIR /door_adapter_template_ws
RUN apt-get update && rosdep install --from-paths src --ignore-src --rosdistro=$ROS_DISTRO -y \
&& rm -rf /var/lib/apt/lists/*

# # Build the workspace
RUN . /opt/ros/$ROS_DISTRO/setup.sh \
&& colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release

# # Ensure the entrypoint script sources the ROS setup
RUN echo 'source /door_adapter_template_ws/install/setup.bash' >> /ros_entrypoint.sh

# # Ensure proper permissions for entrypoint
RUN chmod +x /ros_entrypoint.sh

ENTRYPOINT ["/ros_entrypoint.sh"]

30 changes: 26 additions & 4 deletions Readme.md β†’ README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# door_adapter_template
# **door_adapter_template**

The objective of this package is to serve as a reference or template for writing a python based RMF door adapter.

> Note: This package is only one such example that may be helpful for users to quickly integrate door control with RMF.

## Step 1: Fill up missing code
## **Step 1**: Fill up missing code
Simply fill up certain blocks of code which make `REST` API calls to IOT door.
These blocks are highlighted as seen below and are found in `DoorClientAPI.py`
```
Expand Down Expand Up @@ -46,16 +46,38 @@ Alternatively, if your door offers a websocket port for communication or allows

>Note: you could refer to the example mock door_adapter in the `door_adapter_template/example` folder

## Step 2: Update config.yaml
## **Step 2**: Update config.yaml
The `config.yaml` file contains important parameters for setting up the door adapter. There are three broad sections to this file:

1. **name** : the door name to display and called by RMF
2. **api_endpoint** : REST API endpoint to communicate to the door

## Step 3: Run the door adapter:
## **Step 3**: Run the door adapter:

Run the command below while passing the paths to the configuration file to operate on.

```bash
ros2 run door_adapter door_adapter -c CONFIG_FILE
```

### **Docker Build**

Run the command below to utilise the root `Dockerfile` to build `door_adapter_template` in docker:

```bash
docker build -t door_adapter_template:humble .
```

### **Docker Run**

Run the command below to utilise the root `Dockerfile` to run `door_adapter_template` in docker:

```bash
docker run -it --rm \
--name door_adapter_template_c \
--network host \
-v /dev/shm:/dev/shm \
-v ./door_adapter_template/config.yaml:/door_adapter_template_ws/src/door_adapter_template/config.yaml \
door_adapter_template:humble /bin/bash -c \
"source /ros_entrypoint.sh && ros2 run door_adapter_template door_adapter --config_file /door_adapter_template_ws/src/door_adapter_template/config.yaml"
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class DoorClientAPI:
def __init__(self, node, config):
self.name = 'rmf_door_adapter'
self.name = 'door_adapter_template'
self.timeout = 5 # seconds
self.debug = False
self.connected = False
Expand Down
8 changes: 4 additions & 4 deletions door_adapter_template/door_adapter_template/door_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import threading

import rclpy
from DoorClientAPI import DoorClientAPI
from door_adapter_template.DoorClientAPI import DoorClientAPI
from rclpy.node import Node
from rmf_door_msgs.msg import DoorRequest, DoorState, DoorMode

Expand All @@ -30,7 +30,7 @@ def __init__(self,

class DoorAdapter(Node):
def __init__(self,config_yaml):
super().__init__('door_adapter')
super().__init__('door_adapter_template_node')
self.get_logger().info('Starting door adapter...')

# Get value from config file
Expand Down Expand Up @@ -130,8 +130,8 @@ def door_request_cb(self, msg: DoorRequest):
# command to API. When the adapter receives a close request, it will
# stop sending the open command to API
self.get_logger().info(
f"[{msg.door_name}] Door mode [{msg.requested_mode.value}] '
f'requested by {msg.requester_id}"
f"[{msg.door_name}] Door mode [{msg.requested_mode.value}] "
f"requested by {msg.requester_id}"
)
if msg.requested_mode.value == DoorMode.MODE_OPEN:
# open door implementation
Expand Down
4 changes: 2 additions & 2 deletions door_adapter_template/package.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>door_adapter</name>
<name>door_adapter_template</name>
<version>0.0.0</version>
<description>A template for an RMF door adapter</description>
<maintainer email=""></maintainer>
<maintainer email="[email protected]"></maintainer>
<license>Apache License 2.0</license>

<exec_depend>rmf_door_msgs</exec_depend>
Expand Down
4 changes: 2 additions & 2 deletions door_adapter_template/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[develop]
script-dir=$base/lib/door_adapter
script-dir=$base/lib/door_adapter_template
[install]
install-scripts=$base/lib/door_adapter
install-scripts=$base/lib/door_adapter_template
4 changes: 2 additions & 2 deletions door_adapter_template/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

package_name = 'door_adapter'
package_name = 'door_adapter_template'

setup(
name=package_name,
Expand All @@ -20,7 +20,7 @@
tests_require=['pytest'],
entry_points={
'console_scripts': [
'door_adapter = door_adapter.door_adapter:main'
'door_adapter = door_adapter_template.door_adapter:main'
],
},
)