Skip to content

Commit 2744667

Browse files
authored
Add ROS Launchpad
* Use PyPi yaml validation package * Use ROS Launchpad * Add ROS setup step to bash.bashrc * Remove obviated environment prep
1 parent d98a9d6 commit 2744667

File tree

9 files changed

+63
-240
lines changed

9 files changed

+63
-240
lines changed

Dockerfile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RUN python3 -m pip install "Cython<3.1"
3838

3939
# Install Python dependencies
4040
COPY deps/python3-requirements.txt ./
41-
RUN python3 -m pip install -r python3-requirements.txt
41+
RUN python3 -m pip install --ignore-installed -r python3-requirements.txt
4242

4343

4444
# Clone third-party dependencies from VCS
@@ -75,9 +75,8 @@ RUN apt update \
7575
&& rosdep install --default-yes --from-paths ./src --ignore-src \
7676
&& rm -rf /var/lib/apt/lists/*
7777

78-
# Copy the rest of the sources
78+
# Copy the rest of the source
7979
COPY ./src ./src
80-
COPY ./scripts ./scripts
8180

8281
# Build
8382
RUN bash -c "source devel/setup.bash \
@@ -91,7 +90,23 @@ RUN bash -c "source devel/setup.bash \
9190
rbr_maestro3_ctd \
9291
"
9392

94-
# Copy the launch tool
93+
# Clone the ROS Launchpad management server
94+
RUN mkdir -p /launchpad
95+
RUN curl -L http://github.com/WHOIGit/ros-launchpad/archive/v1.0.13.tar.gz | tar zxf - --strip-components=1 -C /launchpad
96+
RUN python3 -m pip install --ignore-installed -r /launchpad/requirements.txt
97+
98+
# Copy the launch tools and server files
9599
ENV DONT_SCREEN=1
96100
ENV NO_VIRTUALENV=1
97101
COPY ./phyto-arm ./phyto-arm
102+
103+
# Expose web interface port
104+
EXPOSE 8080
105+
106+
# Source ROS environment automatically for all bash sessions
107+
RUN echo "source /app/devel/setup.bash" >> /etc/bash.bashrc
108+
109+
ENTRYPOINT ["/bin/bash", "-c", "source /app/devel/setup.bash && exec \"$@\"", "--"]
110+
111+
# Default command runs the server with ROS environment sourced
112+
CMD ["/bin/bash", "-c", "cd /launchpad && python3 server.py --package phyto_arm --config /app/mounted_config.yaml /app/configs/example.yaml"]

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ These steps assume that ROS Noetic has been installed already.
120120
sudo systemctl start phyto-arm
121121

122122

123-
## Running
123+
## Running
124124

125-
The `phyto-arm` tool starts all of the ROS nodes and loads the provided configuration file.
125+
### Using ROS Launchpad (NEW)
126+
127+
ROS Launchpad is a simple web dashboard for managing ROS processes and config. The default Docker command will start it up, so simply starting the container is sufficient. `./scripts/docker_run.sh -d` will also run the dashboard.
128+
129+
### Using `phyto-arm`
130+
131+
The `phyto-arm` tool starts all of the ROS nodes and loads the provided configuration file. This is typically run within the container.
126132

127133
```
128134
phyto-arm start [-h] [--config_schema <schema file>] [--skip_validation] \
@@ -194,6 +200,14 @@ To launch all three simultaneously as separate panes in a tmux session, run the
194200

195201
### Running natively
196202

203+
*Not recommended*: Running as a Docker container is preferable in most scenarios.
204+
205+
Source any environments that are in use:
206+
```
207+
. venv/bin/activate # Python environment
208+
. devel/setup.bash # ROS environment
209+
```
210+
197211
The `phyto-arm` tool starts the main ROS nodes and loads the provided configuration file.
198212

199213
$ ./phyto-arm start main config/config.yaml
@@ -243,10 +257,8 @@ You can also provide your own schema by passing in the `--config_schema <file>`
243257
3. The datatype for every parameter present in both config and schema must match.
244258
4. Parameters in config but not schema are ignored.
245259

246-
The config validation script includes a separate set of unit tests that can be run with
247-
```bash
248-
python3 scripts/config_validation.test.py
249-
```
260+
For more information see https://github.com/WHOIGit/example-yaml-validator
261+
250262

251263
### Configuring host address
252264

deps/python3-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ git+https://github.com/WHOIGit/pyifcbclient.git#egg=pyifcbclient
1313
# Use an older version of grpcio that's available as a pre-built wheel.
1414
# TODO: Remove this when we move beyond Python 3.8 (Ubuntu 20.04).
1515
grpcio<1.71
16+
17+
yaml-validator==0.3.0

phyto-arm

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,7 @@ import urllib.request
1919

2020
import yaml
2121

22-
from scripts.config_validation import validate_config
23-
24-
# Load the virtual environment and Catkin workspace and return the resulting
25-
# environment
26-
def prep_environment():
27-
# Due to a long-standing bug in the setup.sh script, we must provide to the
28-
# devel/ directory in the _CATKIN_SETUP_DIR environment variable.
29-
#
30-
# This also needs to be an absolute path so that Python can locate packages.
31-
#
32-
# Ref: https://github.com/catkin/catkin_tools/issues/376
33-
parent_dir = os.path.dirname(__file__)
34-
setup_dir = os.path.abspath(os.path.join(parent_dir, 'devel'))
35-
env = {
36-
'_CATKIN_SETUP_DIR': setup_dir
37-
}
38-
39-
# Build command to load the catkin workspace (and optionally a virtual
40-
# environment) and dump the environment.
41-
command = f'. {shlex.quote(setup_dir)}/setup.sh && env'
42-
43-
if os.getenv('NO_VIRTUALENV') is None:
44-
command = f'. {shlex.quote(parent_dir)}/.venv/bin/activate && ' + \
45-
command
46-
47-
# Dump the environment and parse the output
48-
env_out = subprocess.check_output(command, shell=True, env=env)
49-
for line in env_out.rstrip().split(b'\n'):
50-
var, _, value = line.partition(b'=')
51-
env[var] = value
52-
53-
return env
22+
from yaml_validator import validate_config
5423

5524

5625
# Prepare a command and environment for roslaunch
@@ -112,7 +81,7 @@ def _start(args):
11281
config = yaml.safe_load(f)
11382

11483
# Prepare the environment
115-
env = prep_environment()
84+
env = dict(os.environ)
11685

11786
# Define an atexit handler that can be used to terminate subprocesses.
11887
# Recall that these handlers are invoked in reverse order, so since we start

phyto-arm.service

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ After=network.target
77
[Service]
88
Type=simple
99
Restart=on-failure
10+
RestartSec=10
1011
WorkingDirectory=/home/hablab/PhytO-ARM
11-
ExecStart=/bin/bash -c ". devel/setup.bash; roslaunch pa_base phyto_arm.launch"
12+
ExecStart=/bin/bash scripts/docker_run_daemon.sh
1213

1314
[Install]
1415
WantedBy=multi-user.target

scripts/__init__.py

Whitespace-only changes.

scripts/config_validation.py

Lines changed: 0 additions & 89 deletions
This file was deleted.

scripts/config_validation.test.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)