Skip to content

Commit 597844b

Browse files
committed
Merge remote-tracking branch 'origin/main' into 277-load-cell-validity-check
2 parents 3b53a25 + b850ff6 commit 597844b

File tree

13 files changed

+709
-273
lines changed

13 files changed

+709
-273
lines changed

.github/actions/setup-poetry-env/action.yml

+30-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,41 @@ runs:
2929
run: poetry config virtualenvs.in-project true
3030
shell: bash
3131

32+
# Re-enable caching with improved key and restore logic
3233
- name: Load cached venv
3334
id: cached-poetry-dependencies
3435
uses: actions/cache@v4
3536
with:
3637
path: .venv
37-
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}
38+
# Include poetry.toml in the cache key to catch configuration changes
39+
key: venv-${{ runner.os }}-py${{ inputs.python-version }}-${{ hashFiles('poetry.lock', 'poetry.toml') }}-v2
3840

3941
- name: Install dependencies
40-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
41-
run: poetry install --no-interaction
42+
run: |
43+
if [ "${{ steps.cached-poetry-dependencies.outputs.cache-hit }}" == 'true' ]; then
44+
echo "Using cached virtual environment"
45+
46+
# Validate the cached environment contains expected tools
47+
if ! poetry run pre-commit --version &>/dev/null || \
48+
! poetry run pytest --version &>/dev/null || \
49+
! poetry run mypy --version &>/dev/null; then
50+
echo "Cached environment is missing required tools. Reinstalling..."
51+
rm -rf .venv
52+
poetry install --no-interaction --with dev
53+
fi
54+
else
55+
echo "Installing dependencies"
56+
rm -rf .venv || true
57+
poetry install --no-interaction --with dev
58+
fi
59+
shell: bash
60+
61+
- name: Verify development tools installation
62+
run: |
63+
echo "Verifying pre-commit installation..."
64+
poetry run pre-commit --version
65+
echo "Verifying pytest installation..."
66+
poetry run pytest --version
67+
echo "Verifying mypy installation..."
68+
poetry run mypy --version
4269
shell: bash

.github/workflows/main.yml

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ jobs:
2222
- name: Set up the environment
2323
uses: ./.github/actions/setup-poetry-env
2424

25+
- name: Verify tools before running checks
26+
run: |
27+
poetry run which pre-commit
28+
poetry run which mypy
29+
poetry run which pytest
30+
2531
- name: Run checks
2632
run: make check
2733

@@ -43,9 +49,15 @@ jobs:
4349
with:
4450
python-version: ${{ matrix.python-version }}
4551

52+
- name: Verify pytest before running tests
53+
run: poetry run which pytest
54+
4655
- name: Run tests
4756
run: poetry run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
4857

58+
- name: Verify mypy before type checking
59+
run: poetry run which mypy
60+
4961
- name: Check typing
5062
run: poetry run mypy
5163

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ The library is available on PyPI and can be installed using pip:
6363
pip install opensourceleg
6464
```
6565

66+
### Hardware-Specific Dependencies
67+
68+
To keep your installation lightweight, you can install only the dependencies needed for your specific hardware:
69+
70+
```bash
71+
# For Dephy actuators
72+
pip install opensourceleg[dephy]
73+
74+
# For Moteus actuators
75+
pip install opensourceleg[moteus]
76+
77+
# For I2C communication
78+
pip install opensourceleg[communication]
79+
```
80+
81+
| Extra | Dependencies |
82+
| --------------- | ------------------------------------ |
83+
| `dephy` | flexsea |
84+
| `moteus` | moteus, moteus-pi3hat |
85+
| `communication` | smbus2 |
86+
| `messaging` | grpcio, grpcio-tools, types-protobuf |
87+
6688
For more details on the installation process, please refer to the [installation guide](https://neurobionics.github.io/opensourceleg/installation).
6789

6890
## 📚 Usage

docs/examples/assets/FSM_Diagram.svg

+1-1
Loading

docs/index.md

+22
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ The library is available on PyPI and can be installed using pip:
6363
pip install opensourceleg
6464
```
6565

66+
### Hardware-Specific Dependencies
67+
68+
To keep your installation lightweight, you can install only the dependencies needed for your specific hardware:
69+
70+
```bash
71+
# For Dephy actuators
72+
pip install opensourceleg[dephy]
73+
74+
# For Moteus actuators
75+
pip install opensourceleg[moteus]
76+
77+
# For I2C communication
78+
pip install opensourceleg[communication]
79+
```
80+
81+
| Extra | Dependencies |
82+
|-------|-------------|
83+
| `dephy` | flexsea |
84+
| `moteus` | moteus, moteus-pi3hat |
85+
| `communication` | smbus2 |
86+
| `messaging` | grpcio, grpcio-tools, types-protobuf |
87+
6688
For more details on the installation process, please refer to the [installation guide](https://neurobionics.github.io/opensourceleg/installation).
6789

6890
## 📚 Usage

docs/installation.md

+33
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ source .venv/bin/activate
5151
# Step 3: Install opensourceleg
5252
pip install opensourceleg
5353
```
54+
#### Hardware-Specific Dependencies
55+
56+
The opensourceleg library supports a variety of actuators and sensors, each with its own dependencies. Rather than installing all possible dependencies (which can be extensive), we recommend installing only what you need for your specific hardware configuration.
57+
58+
### Installing Hardware-Specific Packages
59+
60+
You can easily install hardware-specific dependencies using pip's "extras" feature:
61+
62+
```bash
63+
# For Dephy actuators
64+
pip install opensourceleg[dephy]
65+
66+
# For Moteus actuators
67+
pip install opensourceleg[moteus]
68+
69+
# For I2C communication
70+
pip install opensourceleg[communication]
71+
72+
# For gRPC messaging functionality
73+
pip install opensourceleg[messaging]
74+
```
75+
76+
### Available Extras
77+
78+
| Extra | Dependencies |
79+
|-------|-------------|
80+
| `dephy` | flexsea |
81+
| `moteus` | moteus, moteus-pi3hat |
82+
| `communication` | smbus2 |
83+
| `messaging` | grpcio, grpcio-tools, types-protobuf |
84+
85+
This approach keeps your installation lightweight and focused on just the hardware you're working with.
86+
5487

5588
💡 **Why Use a Virtual Environment?**
5689
Keeps your projects isolated

docs/tutorials/sensors/reading_loadcell_data.md

+43-37
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,68 @@
11
# Using the Dephy Loadcell Amplifier
22

3-
This tutorial demonstrates how to use the Dephy Loadcell Amplifier with the Open Source Leg platform to measure forces and moments.
3+
This tutorial demonstrates how to use the Dephy Loadcell Amplifier with the Open Source Leg platform to measure forces and moments. It includes examples for both standard I2C communication and custom callbacks for advanced use cases, including using the Dephy Actpack to interface with the amplifier directly instead of the Raspberry Pi's I2C bus.
44

55
## Hardware Setup
66

7-
1. Connect the loadcell to the Dephy Loadcell Amplifier and the amplifier to the Raspberry Pi via I2C
8-
2. Verify proper power supply connections
9-
3. Ensure proper grounding
10-
4. Mount the loadcell securely
7+
1. Connect the loadcell to the Dephy Loadcell Amplifier and the amplifier to the Raspberry Pi via I2C. Alternatively, raw amplifier readings can be read from the `genvars` property of the `DephyActuator` class and fed into the amplifier update method as a custom callback (see example below).
8+
2. Verify proper power supply connections.
9+
3. Ensure proper grounding.
10+
4. Mount the loadcell securely.
1111

1212
This example shows how to:
1313

14-
- Initialize and configure a Dephy Loadcell Amplifier
15-
- Read forces and moments (6-axis measurements)
16-
- Log loadcell measurements
14+
- Initialize and configure a Dephy Loadcell Amplifier.
15+
- Read forces and moments (6-axis measurements).
16+
- Log loadcell measurements.
17+
- Use custom callbacks for advanced data handling.
18+
19+
---
1720

1821
## Code Structure
1922

20-
The [tutorial script](https://github.com/neurobionics/opensourceleg/blob/main/tutorials/sensors/reading_loadcell_data.py) is organized into several main sections:
23+
The [tutorial script](https://github.com/neurobionics/opensourceleg/blob/main/tutorials/sensors/reading_loadcell_data.py) for reading loadcell data has two main functions. The first shows the standard implementation where the I2C bus on a Raspberry Pi is used to communicate with the strain amplifier. The second shows an alternative use where raw ADC values are passed to the sensor in a custom data callback function. This second implementation is useful when the raw values are provided via a method other than I2C, such as reading them directly from a Dephy Actuator.
2124

2225
### 1. Initialization
2326

2427
```python
25-
--8<-- "tutorials/sensors/reading_loadcell_data.py:1:40"
28+
--8<-- "tutorials/sensors/reading_loadcell_data.py:1:25"
2629
```
2730

2831
This section:
2932

3033
- Sets up constants and configuration parameters
3134
- Defines the calibration matrix
32-
- Creates a data logger for recording measurements
33-
- Sets up a real-time loop for consistent timing
34-
- Initializes the DephyLoadcellAmplifier with specified parameters
3535

36-
### 2. Main Loop
36+
### 2. Standard Setup with I2C Communication
37+
38+
This section demonstrates how to use the loadcell with standard I2C communication. It includes:
39+
40+
- Initializing the loadcell with I2C parameters.
41+
- Calibrating the loadcell.
42+
- Reading and logging force/torque data.
3743

3844
```python
39-
--8<-- "tutorials/sensors/reading_loadcell_data.py:48:55"
45+
--8<-- "tutorials/sensors/reading_loadcell_data.py:28:53"
4046
```
4147

42-
The main loop:
48+
### 3. Custom Callback Communication
49+
This section demonstrates how to use a custom callback to provide raw data to the loadcell. It includes:
50+
51+
- Using a DephyActuator to retrieve raw amplifier readings.
52+
- Passing the raw data to the loadcell using a callback function.
53+
- Calibrating the loadcell with the custom callback.
54+
- Reading and logging force/torque data.
4355

44-
1. Updates the loadcell to get the latest reading
45-
2. Logs the time and current force/torque values
46-
3. Updates the logger
56+
```python
57+
--8<-- "tutorials/sensors/reading_loadcell_data.py:56:90"
58+
```
4759

48-
## Loadcell Parameters
60+
## Important Class Parameters
4961

50-
When initializing the DephyLoadcellAmplifier, several important parameters can be configured:
62+
When initializing the `DephyLoadcellAmplifier`, several important parameters can be configured:
5163

5264
```python
53-
--8<-- "tutorials/sensors/reading_loadcell_data.py:32:40"
65+
--8<-- "tutorials/sensors/reading_loadcell_data.py:29:36"
5466
```
5567

5668
### Parameter Details
@@ -86,7 +98,7 @@ When initializing the DephyLoadcellAmplifier, several important parameters can b
8698

8799
## Available Properties
88100

89-
The DephyLoadcellAmplifier provides six measurement properties:
101+
The `DephyLoadcellAmplifier` provides six measurement properties:
90102

91103
1. **Forces** (fx, fy, fz):
92104
- Linear forces in Newtons (N)
@@ -115,14 +127,20 @@ The DephyLoadcellAmplifier provides six measurement properties:
115127

116128
2. Run the script:
117129
```bash
118-
python loadcell.py
130+
python reading_loadcell_data.py
119131
```
120132

121133
3. Expected behavior:
122134
- Loadcell begins reading force/torque data continuously at 200Hz
123135
- Data is logged to `./logs/reading_loadcell_data.csv`
124136
- Force and moment values update as you apply loads to the sensor
125137

138+
4. To change between I2C and using custom data callbacks, swap the `if __name__ == "__main__"` between the two demo function calls:
139+
140+
```python
141+
--8<-- "tutorials/sensors/reading_loadcell_data.py:101:102"
142+
```
143+
126144
## Common Issues
127145

128146
- **I2C Communication Errors**: Verify connections with `i2cdetect -y 1`
@@ -141,18 +159,6 @@ LOADCELL_CALIBRATION_MATRIX = np.array([
141159
# ... additional rows ...
142160
])
143161
```
144-
Should be replaced with your specific loadcell's calibration values.
145-
146-
## Best Practices
147-
148-
1. **Before Each Use**
149-
150-
- Verify all connections
151-
152-
2. **Maintenance**
153-
154-
- Regular calibration checks
155-
- Clean connections
156-
- Monitor for drift
162+
should be replaced with your specific loadcell's calibration values.
157163

158164
If you have any questions or need further assistance, please post on the [Open Source Leg community forum](https://opensourceleg.org/community).

0 commit comments

Comments
 (0)