diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f1880f --- /dev/null +++ b/Dockerfile @@ -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"] + diff --git a/Readme.md b/README.md similarity index 72% rename from Readme.md rename to README.md index ca06ae6..e646a17 100644 --- a/Readme.md +++ b/README.md @@ -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` ``` @@ -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" ``` \ No newline at end of file diff --git a/door_adapter_template/door_adapter_template/DoorClientAPI.py b/door_adapter_template/door_adapter_template/DoorClientAPI.py index d77a813..4137fd0 100644 --- a/door_adapter_template/door_adapter_template/DoorClientAPI.py +++ b/door_adapter_template/door_adapter_template/DoorClientAPI.py @@ -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 diff --git a/door_adapter_template/door_adapter_template/door_adapter.py b/door_adapter_template/door_adapter_template/door_adapter.py index 959cf62..f39d473 100644 --- a/door_adapter_template/door_adapter_template/door_adapter.py +++ b/door_adapter_template/door_adapter_template/door_adapter.py @@ -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 @@ -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 @@ -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 diff --git a/door_adapter_template/package.xml b/door_adapter_template/package.xml index 1ab5fa5..07f690b 100644 --- a/door_adapter_template/package.xml +++ b/door_adapter_template/package.xml @@ -1,10 +1,10 @@ - door_adapter + door_adapter_template 0.0.0 A template for an RMF door adapter - + Apache License 2.0 rmf_door_msgs diff --git a/door_adapter_template/resource/door_adapter b/door_adapter_template/resource/door_adapter_template similarity index 100% rename from door_adapter_template/resource/door_adapter rename to door_adapter_template/resource/door_adapter_template diff --git a/door_adapter_template/setup.cfg b/door_adapter_template/setup.cfg index 0a5245f..cd89ae9 100644 --- a/door_adapter_template/setup.cfg +++ b/door_adapter_template/setup.cfg @@ -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 diff --git a/door_adapter_template/setup.py b/door_adapter_template/setup.py index f0e17be..a32d2b6 100644 --- a/door_adapter_template/setup.py +++ b/door_adapter_template/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -package_name = 'door_adapter' +package_name = 'door_adapter_template' setup( name=package_name, @@ -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' ], }, )