From 8d6127c590f7fb0ce1001b0aba099f4a81a045ac Mon Sep 17 00:00:00 2001 From: Stefan Scherzinger Date: Tue, 24 Sep 2024 13:42:22 +0200 Subject: [PATCH 1/3] Fix the dummy installation We can now start the dummy with the usual `ros2 run schunk_egu_egk_dummy start_dummy` call This is what ROS2 users would expect here. --- schunk_egu_egk_gripper_dummy/README.md | 16 ++++++++++++++-- schunk_egu_egk_gripper_dummy/config/__init__.py | 2 ++ schunk_egu_egk_gripper_dummy/setup.py | 5 +---- .../{start_dummy.sh => start_dummy} | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 schunk_egu_egk_gripper_dummy/config/__init__.py rename schunk_egu_egk_gripper_dummy/{start_dummy.sh => start_dummy} (83%) diff --git a/schunk_egu_egk_gripper_dummy/README.md b/schunk_egu_egk_gripper_dummy/README.md index 82e2346..8c5d04d 100644 --- a/schunk_egu_egk_gripper_dummy/README.md +++ b/schunk_egu_egk_gripper_dummy/README.md @@ -1,19 +1,31 @@ # Schunk EGU/EGK Dummy A minimalist protocol simulator for system tests. +Use this SCHUNK gripper dummy whenever you don't have access to real hardware +and still want to test your application. + ## Dependencies +We need additional Python dependencies. +Install them inside your favorite Python environment with ```bash pip install --user fastapi uvicorn ``` ## Getting started -1. Start the dummy standalone with +- **Option 1**: Although shipped inside a ROS2 package, the dummy itself doesn't need ROS2. + You can simply navigate into the dummy's package and start it with ```bash - ./start_dummy.sh + ./start_dummy ``` +- **Option 2**: When working in a sourced environment, you can start the dummy with + ```bash + ros2 run schunk_egu_egk_gripper_dummy start_dummy + ``` + ## Run tests locally +Inside the dummy's package ```bash pip install --user pytest httpx coverage diff --git a/schunk_egu_egk_gripper_dummy/config/__init__.py b/schunk_egu_egk_gripper_dummy/config/__init__.py new file mode 100644 index 0000000..fd5954f --- /dev/null +++ b/schunk_egu_egk_gripper_dummy/config/__init__.py @@ -0,0 +1,2 @@ +# This file's existence lets setup.py install the config folder to site-packages. +# We need this when starting this dummy with ros2 run. diff --git a/schunk_egu_egk_gripper_dummy/setup.py b/schunk_egu_egk_gripper_dummy/setup.py index 1614c37..775d78b 100644 --- a/schunk_egu_egk_gripper_dummy/setup.py +++ b/schunk_egu_egk_gripper_dummy/setup.py @@ -1,6 +1,5 @@ from setuptools import find_packages, setup import os -from glob import glob package_name = "schunk_egu_egk_gripper_dummy" @@ -11,9 +10,7 @@ data_files=[ ("share/ament_index/resource_index/packages", ["resource/" + package_name]), ("share/" + package_name, ["package.xml"]), - (os.path.join("share", package_name), [package_name + "/main.py"]), - (os.path.join("share", package_name, "src"), glob("src/*.py")), - (os.path.join("share", package_name, "config"), glob("config/*.json")), + (os.path.join("lib", package_name), ["start_dummy"]), ], install_requires=["setuptools"], zip_safe=True, diff --git a/schunk_egu_egk_gripper_dummy/start_dummy.sh b/schunk_egu_egk_gripper_dummy/start_dummy similarity index 83% rename from schunk_egu_egk_gripper_dummy/start_dummy.sh rename to schunk_egu_egk_gripper_dummy/start_dummy index 1551d71..21a9149 100755 --- a/schunk_egu_egk_gripper_dummy/start_dummy.sh +++ b/schunk_egu_egk_gripper_dummy/start_dummy @@ -1 +1,2 @@ +#!/usr/bin/sh uvicorn schunk_egu_egk_gripper_dummy.main:server --port 8000 --reload From dda34260bff7815f36c5ad0fc9370b4723af6917 Mon Sep 17 00:00:00 2001 From: Stefan Scherzinger Date: Tue, 24 Sep 2024 13:44:30 +0200 Subject: [PATCH 2/3] Add missing dependencies to the dummy's readme They seem to be required on a fresh system. --- schunk_egu_egk_gripper_dummy/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schunk_egu_egk_gripper_dummy/README.md b/schunk_egu_egk_gripper_dummy/README.md index 8c5d04d..e8c8c8d 100644 --- a/schunk_egu_egk_gripper_dummy/README.md +++ b/schunk_egu_egk_gripper_dummy/README.md @@ -9,7 +9,7 @@ We need additional Python dependencies. Install them inside your favorite Python environment with ```bash -pip install --user fastapi uvicorn +pip install --user fastapi uvicorn requests python-multipart ``` ## Getting started From eab0fd2f97782abe245e09d7090ee7ccdbf83cb9 Mon Sep 17 00:00:00 2001 From: Stefan Scherzinger Date: Tue, 24 Sep 2024 14:30:37 +0200 Subject: [PATCH 3/3] Make the dummy's port a start script argument This is helpful for users who need a specific port. --- schunk_egu_egk_gripper_dummy/README.md | 26 +++++++++++++++--------- schunk_egu_egk_gripper_dummy/start_dummy | 25 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/schunk_egu_egk_gripper_dummy/README.md b/schunk_egu_egk_gripper_dummy/README.md index e8c8c8d..ddaf6a1 100644 --- a/schunk_egu_egk_gripper_dummy/README.md +++ b/schunk_egu_egk_gripper_dummy/README.md @@ -13,16 +13,22 @@ pip install --user fastapi uvicorn requests python-multipart ``` ## Getting started -- **Option 1**: Although shipped inside a ROS2 package, the dummy itself doesn't need ROS2. - You can simply navigate into the dummy's package and start it with - ```bash - ./start_dummy - ``` - -- **Option 2**: When working in a sourced environment, you can start the dummy with - ```bash - ros2 run schunk_egu_egk_gripper_dummy start_dummy - ``` +There's a convenience script `start_dummy` for starting the dummy simulator. +It will start on localhost with port `8000` by default but you can specify another port via the `port:=` syntax. + +### Plain python + +Although shipped inside a ROS2 package, the dummy itself doesn't need ROS2. +You can simply navigate into the dummy's package and start it with +```bash +./start_dummy port:=8000 +``` + +### ROS2 +When working in a sourced ROS2 environment, you can start the dummy with +```bash +ros2 run schunk_egu_egk_gripper_dummy start_dummy --ros-args -p port:=8000 +``` ## Run tests locally Inside the dummy's package diff --git a/schunk_egu_egk_gripper_dummy/start_dummy b/schunk_egu_egk_gripper_dummy/start_dummy index 21a9149..8d78040 100755 --- a/schunk_egu_egk_gripper_dummy/start_dummy +++ b/schunk_egu_egk_gripper_dummy/start_dummy @@ -1,2 +1,25 @@ #!/usr/bin/sh -uvicorn schunk_egu_egk_gripper_dummy.main:server --port 8000 --reload + +# Default port +port=8000 + +# Parse arguments +while [ $# -gt 0 ]; do + case "$1" in + --ros-args) + shift + ;; + -p|--port) + shift + ;; + port:*) + port="${1#*:=}" + shift + ;; + *) + shift + ;; + esac +done + +uvicorn schunk_egu_egk_gripper_dummy.main:server --port $port --reload