Skip to content

Commit 5c69c6c

Browse files
committed
Add pre-commit hooks & BSD 3-Clause license (#206)
* Add pre-commit hooks * Fix unknown module issue from msgs * Hardcode pylint version for consistency * Add ros2-devel to workflow branches * Remove pylint from workflow due to inconsistent errors between remote and local * Add license * Fix README numbering * Fix LICENSE numbering * Add license header to yaml files as well
1 parent a43947f commit 5c69c6c

File tree

161 files changed

+975
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+975
-380
lines changed

.codespell-ignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fof
2+
ans

.github/LICENSE_HEADER.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Copyright (c) 2024, Personal Robotics Laboratory
2+
License: BSD 3-Clause. See LICENSE.md file in root directory.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Description
22

3-
[TODO: describe, in-detail, what issue this PR addresses and how it addresses it. Link to relevant Github Issues.]
3+
\[TODO: describe, in-detail, what issue this PR addresses and how it addresses it. Link to relevant Github Issues.\]
44

55
# Testing procedure
66

7-
[TODO: describe, in-detail, how you tested this. The procedure must be detailed enough for the reviewer(s) to recreate it.]
7+
\[TODO: describe, in-detail, how you tested this. The procedure must be detailed enough for the reviewer(s) to recreate it.\]
88

99
# Before opening a pull request
10-
- [ ] Format your code using [black formatter](https://black.readthedocs.io/en/stable/) `python3 -m black .`
11-
- [ ] Run your code through [pylint](https://pylint.readthedocs.io/en/latest/) and address all warnings/errors. The only warnings that are acceptable to not address is TODOs that should be addressed in a future PR. From the top-level `ada_feeding` directory, run: `pylint --recursive=y --rcfile=.pylintrc .`.
10+
11+
- \[ \] `pre-commit run --all-files`
12+
- \[ \] Run your code through [pylint](https://pylint.readthedocs.io/en/latest/). `pylint --recursive=y --rcfile=.pylintrc .`. All warnings but `fixme` must be addressed.
1213

1314
# Before Merging
14-
- [ ] `Squash & Merge`
15+
16+
- \[ \] `Squash & Merge`

.github/workflows/pre-commit.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2024, Personal Robotics Laboratory
2+
# License: BSD 3-Clause. See LICENSE.md file in root directory.
3+
4+
name: pre-commit
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- master
11+
- ros2-devel
12+
pull_request:
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
17+
cancel-in-progress: true
18+
19+
env:
20+
PYTHON_VERSION: "3.10"
21+
22+
jobs:
23+
pre-commit:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ env.PYTHON_VERSION }}
30+
31+
## Run pre-commit and try to apply fixes
32+
- name: Run pre-commit
33+
uses: pre-commit/action@v3.0.1
34+
- name: Apply fixes from pre-commit
35+
uses: pre-commit-ci/lite-action@v1.0.2
36+
if: always()
37+
# - name: Install dependencies
38+
# run: |
39+
# python -m pip install --upgrade pip
40+
# pip install --force-reinstall pylint==3.1.0
41+
# pip install overrides
42+
# - name: Analysing the code with pylint
43+
# run: |
44+
# pylint --recursive=y --rcfile=.pylintrc . --disable fixme --disable import-error

.pre-commit-config.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.5.0
7+
hooks:
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-executables-have-shebangs
11+
- id: check-merge-conflict
12+
- id: check-shebang-scripts-are-executable
13+
- id: check-symlinks
14+
- id: check-xml
15+
- id: check-yaml
16+
- id: debug-statements
17+
- id: destroyed-symlinks
18+
- id: detect-private-key
19+
- id: end-of-file-fixer
20+
- id: mixed-line-ending
21+
- id: requirements-txt-fixer
22+
- id: trailing-whitespace
23+
24+
- repo: https://github.com/Lucas-C/pre-commit-hooks
25+
rev: v1.5.0
26+
hooks:
27+
- id: insert-license
28+
args:
29+
- --license-file
30+
- .github/LICENSE_HEADER.md
31+
- --use-current-year
32+
types_or: [python, yaml]
33+
34+
- repo: https://github.com/Lucas-C/pre-commit-hooks
35+
rev: v1.5.0
36+
hooks:
37+
- id: insert-license
38+
args:
39+
- --license-file
40+
- .github/LICENSE_HEADER.md
41+
- --use-current-year
42+
- --comment-style
43+
- "<!--| |-->"
44+
types_or: [xml]
45+
exclude: ".*package.xml$"
46+
47+
- repo: https://github.com/psf/black
48+
rev: 23.1.0
49+
hooks:
50+
- id: black
51+
52+
- repo: https://github.com/lovesegfault/beautysh
53+
rev: v6.2.1
54+
hooks:
55+
- id: beautysh
56+
57+
- repo: https://github.com/executablebooks/mdformat
58+
rev: 0.7.16
59+
hooks:
60+
- id: mdformat
61+
args:
62+
- --number
63+
64+
- repo: https://github.com/codespell-project/codespell
65+
rev: v2.2.4
66+
hooks:
67+
- id: codespell
68+
args:
69+
- --ignore-words=.codespell-ignore

.pylintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ clear-cache-post-run=no
2828
extension-pkg-allow-list=cv2,
2929
cv,
3030
lxml,
31-
tf2_py
31+
tf2_py,
32+
rclpy._rclpy_pybind11
3233

3334
# A comma-separated list of package or module names from where C extensions may
3435
# be loaded. Extensions are loading into the active Python interpreter and may
@@ -37,7 +38,8 @@ extension-pkg-allow-list=cv2,
3738
extension-pkg-whitelist=cv2,
3839
cv,
3940
lxml,
40-
tf2_py
41+
tf2_py,
42+
rclpy._rclpy_pybind11
4143

4244
# Return non-zero exit code if any of these messages/categories are detected,
4345
# even if score is above --fail-under value. Syntax same as enable. Messages

LICENSE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2024, Personal Robotics Laboratory
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,71 @@ This README is the definitive source for downloading, installing, and running th
77
### Setup (Robot Software)
88

99
1. [Install ROS2 Humble](https://docs.ros.org/en/humble/Installation.html) (binary packages are recommended over building from source), [configure your environment](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html), and [create a workspace](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html#).
10-
1. **NOTE**: In the remainder of the instructions, replace `~\colcon_ws` with the path to your workspace.
10+
11+
1. **NOTE**: In the remainder of the instructions, replace `~\colcon_ws` with the path to your workspace.
12+
1113
2. Configure [`pr-rosinstalls`](https://github.com/personalrobotics/pr-rosinstalls) in order to download all necessary repositories.
1214

13-
cd ~
14-
git clone https://github.com/personalrobotics/pr-rosinstalls.git
15+
```
16+
cd ~
17+
git clone https://github.com/personalrobotics/pr-rosinstalls.git
18+
```
1519

1620
3. Pull all the repositories, with the correct branch. Replace `<https/ssh>` with one of the options, depending on your authentication method.
1721

18-
sudo apt install python3-wstool # if not already installed
19-
cd ~/colcon_ws/src
20-
wstool init
21-
wstool merge ~/pr-rosinstalls/ada-feeding.<https/ssh>.rosinstall
22-
wstool up
22+
```
23+
sudo apt install python3-wstool # if not already installed
24+
cd ~/colcon_ws/src
25+
wstool init
26+
wstool merge ~/pr-rosinstalls/ada-feeding.<https/ssh>.rosinstall
27+
wstool up
28+
```
2329

2430
4. Configure [`rosdep`](https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html):
2531

26-
sudo apt install python3-rosdep # if not already installed
27-
sudo rosdep init # if this is the first time using rosdep
32+
```
33+
sudo apt install python3-rosdep # if not already installed
34+
sudo rosdep init # if this is the first time using rosdep
35+
```
2836

2937
5. (Only for users **with** sudo access) Install [`rosdep`](https://docs.ros.org/en/humble/Tutorials/Intermediate/Rosdep.html) dependencies:
3038

31-
rosdep update
32-
cd ~/colcon_ws
33-
rosdep install --from-paths src -y --ignore-src --as-root=pip:false
39+
```
40+
rosdep update
41+
cd ~/colcon_ws
42+
rosdep install --from-paths src -y --ignore-src --as-root=pip:false
43+
```
3444

3545
6. Install and fix pip/non-`rosdep` dependencies:
3646

37-
cd ~/colcon_ws/src/ada_feeding
38-
python3 -m pip install -r requirements.txt
39-
40-
- Upgrade `transforms3d`, since [the release on Ubuntu packages is outdated](https://github.com/matthew-brett/transforms3d/issues/65): `python3 -m pip install transforms3d -U`
41-
- Remove the duplicate matplotlib pip installation caused by installing scikit-spatial with pip (some accounts have required sudo access for this command, other have not. If you do not have sudo access and encounter this, contact a lab member who does):
42-
43-
```
44-
python3 -m pip uninstall matplotlib
45-
```
46-
47-
- [`pyrealsense2` is not released for ARM systems](https://github.com/IntelRealSense/librealsense/issues/6449#issuecomment-650784066), so ARM users will have to [build from source](https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/readme.md#building-from-source). You may have to add the `-DPYTHON_EXECUTABLE=/usr/bin/python3` flag to the `cmake` command. When running `sudo make install`, pay close attention to which path `pyrealsense2` is installed to and add *that path* to the `PYTHONPATH` -- it should be `/use/local/lib` but may be `/usr/local/OFF`.
48-
47+
```
48+
cd ~/colcon_ws/src/ada_feeding
49+
python3 -m pip install -r requirements.txt
50+
```
51+
52+
- Upgrade `transforms3d`, since [the release on Ubuntu packages is outdated](https://github.com/matthew-brett/transforms3d/issues/65): `python3 -m pip install transforms3d -U`
53+
54+
- Remove the duplicate matplotlib pip installation caused by installing scikit-spatial with pip (some accounts have required sudo access for this command, other have not. If you do not have sudo access and encounter this, contact a lab member who does):
55+
56+
```
57+
python3 -m pip uninstall matplotlib
58+
```
59+
60+
- [`pyrealsense2` is not released for ARM systems](https://github.com/IntelRealSense/librealsense/issues/6449#issuecomment-650784066), so ARM users will have to [build from source](https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/readme.md#building-from-source). You may have to add the `-DPYTHON_EXECUTABLE=/usr/bin/python3` flag to the `cmake` command. When running `sudo make install`, pay close attention to which path `pyrealsense2` is installed to and add *that path* to the `PYTHONPATH` -- it should be `/use/local/lib` but may be `/usr/local/OFF`.
61+
4962
7. Install the JACO SDK (real robot only). All SDKs are listed [here](https://www.kinovarobotics.com/resources?r=79301&s); PRL currently uses the [Gen2 SDK v1.5.1](https://drive.google.com/file/d/1UEQAow0XLcVcPCeQfHK9ERBihOCclkJ9/view). Note that although the latest version of that SDK is for Ubuntu 16.04, it still works on Ubuntu 22.04 (only for x86 systems, not ARM system).
63+
5064
8. (Optional): We recommend using CycloneDDS as your ROS2 midleware, with a custom configuration file that enables multicast on loopback and prioritizes loopback. Install it with `sudo apt install ros-humble-rmw-cyclonedds-cpp`. Then, add the following lines to your `~/bashrc`: `export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp; export CYCLONEDDS_URI=~/colcon_ws/src/ada_feeding/cyclonedds.xml`.
51-
- Note that you may have to change the name of the fallback interface that CycloneDDS uses if `lo` does not work for that transmission. To do so, run `ifconfig` and either use the name of your ethernet network or WiFi network, depending on how your computer is connected to the internet.
52-
- Note that you have to [rebuild your workspace from scratch after doing this](https://docs.ros.org/en/humble/How-To-Guides/Working-with-multiple-RMW-implementations.html#adding-rmw-implementations-to-your-workspace).
65+
66+
- Note that you may have to change the name of the fallback interface that CycloneDDS uses if `lo` does not work for that transmission. To do so, run `ifconfig` and either use the name of your ethernet network or WiFi network, depending on how your computer is connected to the internet.
67+
- Note that you have to [rebuild your workspace from scratch after doing this](https://docs.ros.org/en/humble/How-To-Guides/Working-with-multiple-RMW-implementations.html#adding-rmw-implementations-to-your-workspace).
68+
5369
9. Build your workspace:
5470
55-
cd ~/colcon_ws
56-
colcon build --symlink-install # if sim-only, add '--packages-skip ada_hardware'
71+
```
72+
cd ~/colcon_ws
73+
colcon build --symlink-install # if sim-only, add '--packages-skip ada_hardware'
74+
```
5775
5876
### Setup (System Configuration)
5977
@@ -68,31 +86,39 @@ If you change the e-stop button, the e-stop button's adapter(s), and/or the devi
6886
### Setup (Web App)
6987
7088
1. Install the Node Version Manager (nvm): https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script
89+
7190
2. Install and use NodeJS 21 (Note: if you have just installed nvm using the previous command, you will need to source your .bashrc or open a new terminal to run these commands):
7291
73-
nvm install 21
74-
nvm use 21
92+
```
93+
nvm install 21
94+
nvm use 21
95+
```
7596
7697
3. (Only for users **with** sudo access; this should already be configured on PRL computers) Make Node available to all users, including root:
7798
78-
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
79-
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
80-
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npx" "/usr/local/bin/npx"
99+
```
100+
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
101+
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
102+
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npx" "/usr/local/bin/npx"
103+
```
81104
82105
4. (Only for users **with** sudo access; this should already be configured on PRL computers) Install `serve` and `pm2` globally. Root access is necessary for `serve` so it can access port 80.
83106
84-
sudo npm install -g serve
85-
npm install -g pm2@latest
107+
```
108+
sudo npm install -g serve
109+
npm install -g pm2@latest
110+
```
86111
87112
5. Install the web app dependencies. (Note: there will be some vulnerabilities in dependencies. This is okay, since access to the web app is shielded behind our secure router.)
88113
89-
cd ~/colcon_ws/src/feeding_web_interface/feedingwebapp
90-
npm install --legacy-peer-deps
91-
npx playwright install
114+
```
115+
cd ~/colcon_ws/src/feeding_web_interface/feedingwebapp
116+
npm install --legacy-peer-deps
117+
npx playwright install
118+
```
92119
93120
6. (Optional; this should already be configured on PRL computers) To access the web app on a device other than the one hosting it, enable the desired port for HTTP access: https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands#allow-all-incoming-http-port-80
94121
95-
96122
## Running the Software
97123
98124
We use the convenience script `start.py` to launch the software. This script has several command-line arguments, which can be seen by passing the `-h` flag when running the script.
@@ -112,7 +138,6 @@ In a browser, access `127.0.0.1` (if on the same device serving the web app), or
112138
113139
To close, run `python3 src/ada_feeding/start.py -c`
114140
115-
116141
### Option B: Running Web App With the Mock Robot
117142
118143
This option starts the web app, runs dummy nodes for perception, runs the **real** robot motion code, but runs a mock robot in MoveIt. This is useful for testing robot motion code in simulation before moving onto the real robot. This will start the web app on port `3000` and does not require `sudo` access.
@@ -143,7 +168,6 @@ To close, run `python3 src/ada_feeding/start.py --sim dummy -c`
143168
144169
- **Something is not working, what do I do?**: All our code runs in `screen` sessions, so the first step is to attach to individual screen sessions to identify where the issue is. Run `screen -ls` to list all screens, run `screen -r <name>` to attach to a screen session, and `Ctrl-A d` to detach from the screen session. An introduction to `screen` can be found [here](https://astrobiomike.github.io/unix/screen-intro).
145170
- **The watchdog is not recognizing my initial e-stop click**: Verify the e-stop is plugged in, and that any other processes accessing the microphone (e.g., Sound Settings) are closed. Run `alsamixer` to see if your user account has access to it. If you do not see sound levels in the terminal, try `sudo alsamixer`. If that works, give your user account permission to access sound: `sudo setfacl -m u:$USER:rw /dev/snd/*`
146-
- **The watchdog is failing due to the F/T sensor**: First, check whether the force-torque sensor is publishing: `ros2 topic echo /wireless_ft/ftSensor3`. If not, the issue is in the `ft` screen (one potential issue is that the alias `ft-sensor` does not point to the right IP address for the force-torque sensor, in which case you should pass the IP address in using the `host` parameter). If so, check the timestamp of the published F/T messages compared to the current time. If it is off, the problem is that NTP got disabled on the force-torque sensor. You have to use `minicom` to re-enable NTP (see [here](https://github.com/personalrobotics/pr_docs/wiki/ADA) for PRL-specific instructions).
171+
- **The watchdog is failing due to the F/T sensor**: First, check whether the force-torque sensor is publishing: `ros2 topic echo /wireless_ft/ftSensor3`. If not, the issue is in the `ft` screen (one potential issue is that the alias `ft-sensor` does not point to the right IP address for the force-torque sensor, in which case you should pass the IP address in using the `host` parameter). If so, check the timestamp of the published F/T messages compared to the current time. If it is off, the problem is that NTP got disabled on the force-torque sensor. You have to use `minicom` to re-enable NTP (see [here](https://github.com/personalrobotics/pr_docs/wiki/ADA) for PRL-specific instructions).
147172
- **I get the error `cannot use destroyable because destruction was requested`**: Upgrade to the latest version of`rclpy`.
148-
- **I get the error `rosbags is not installed, or a wrong version is installed (needs 0.9.19). Type Checking against rosbag types will not work. Error: No module named 'rosbags'`**: Upgrade or downgrade to `rosbags` version 0.9.19.
149173
- **I get the error `bad option: --env-file=.env` when launching the WebRTC Signalling Server**: You are using an old version of Node; upgrade it to 21.

0 commit comments

Comments
 (0)