diff --git a/schunk_egu_egk_gripper_dummy/README.md b/schunk_egu_egk_gripper_dummy/README.md index 82e2346..ddaf6a1 100644 --- a/schunk_egu_egk_gripper_dummy/README.md +++ b/schunk_egu_egk_gripper_dummy/README.md @@ -1,19 +1,37 @@ # 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 +pip install --user fastapi uvicorn requests python-multipart ``` ## Getting started -1. Start the dummy standalone with - ```bash - ./start_dummy.sh - ``` +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 ```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 b/schunk_egu_egk_gripper_dummy/start_dummy new file mode 100755 index 0000000..8d78040 --- /dev/null +++ b/schunk_egu_egk_gripper_dummy/start_dummy @@ -0,0 +1,25 @@ +#!/usr/bin/sh + +# 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 diff --git a/schunk_egu_egk_gripper_dummy/start_dummy.sh b/schunk_egu_egk_gripper_dummy/start_dummy.sh deleted file mode 100755 index 1551d71..0000000 --- a/schunk_egu_egk_gripper_dummy/start_dummy.sh +++ /dev/null @@ -1 +0,0 @@ -uvicorn schunk_egu_egk_gripper_dummy.main:server --port 8000 --reload