Skip to content

Commit

Permalink
Merge pull request #75 from senseshift/feature/og-ffb
Browse files Browse the repository at this point in the history
feat(OpenGloves): add force-feedback
  • Loading branch information
leon0399 authored Aug 6, 2023
2 parents 7dc118f + 9d926eb commit faddc24
Show file tree
Hide file tree
Showing 18 changed files with 780 additions and 120 deletions.
68 changes: 34 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ jobs:
run: |
./.github/scripts/get_firmware_name.sh ${{ matrix.target }} ${{ matrix.serial_plotter_flag }} ${{ matrix.battery_flag }} ${{ matrix.nimble_flag }}
- name: Enable coverage (non-macOS)
if: runner.os != 'macOS' && matrix.coverage
run: |
sed -i '/__OH_FIRMWARE__/p; s/-D __OH_FIRMWARE__/-lgcov --coverage/' platformio.ini
- name: Enable coverage (macOS)
if: runner.os == 'macOS' && matrix.coverage
run: |
sed -i '' '/__OH_FIRMWARE__/p; s/-D __OH_FIRMWARE__/-lgcov --coverage/' platformio.ini
- name: Update build flags (non-macOS)
if: runner.os != 'macOS'
run: |
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.battery_flag }}/' platformio.ini
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.serial_plotter_flag }}/' platformio.ini
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.nimble_flag }}/' platformio.ini
- name: Update build flags (macOS)
if: runner.os == 'macOS'
run: |
sed -i '' '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.battery_flag }}/' platformio.ini
sed -i '' '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.serial_plotter_flag }}/' platformio.ini
sed -i '' '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.nimble_flag }}/' platformio.ini
- name: Speedup package installation
if: matrix.coverage
uses: abbbi/github-actions-tune@v1
Expand All @@ -88,7 +110,7 @@ jobs:
path: |
~/.platformio/.cache
./.pio
key: ${{ runner.os }}-pio-${{ matrix.target }}-${{ hashFiles('platformio.ini') }}
key: ${{ runner.os }}-pio-${{ matrix.target }}-${{ hashFiles('**/*.ini') }}
restore-keys: |
${{ runner.os }}-pio-${{ matrix.target }}-
${{ runner.os }}-pio-
Expand All @@ -98,28 +120,6 @@ jobs:
with:
python-version: '3.9'

- name: Enable coverage (non-macOS)
if: runner.os != 'macOS' && matrix.coverage
run: |
sed -i '/__OH_FIRMWARE__/p; s/-D __OH_FIRMWARE__/-lgcov --coverage/' platformio.ini
- name: Enable coverage (macOS)
if: runner.os == 'macOS' && matrix.coverage
run: |
sed -i '' '/__OH_FIRMWARE__/p; s/-D __OH_FIRMWARE__/-lgcov --coverage/' platformio.ini
- name: Update build flags (non-macOS)
if: runner.os != 'macOS'
run: |
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.battery_flag }}/' platformio.ini
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.serial_plotter_flag }}/' platformio.ini
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.nimble_flag }}/' platformio.ini
- name: Update build flags (macOS)
if: runner.os == 'macOS'
run: |
sed -i '' '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.battery_flag }}/' platformio.ini
sed -i '' '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.serial_plotter_flag }}/' platformio.ini
sed -i '' '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.nimble_flag }}/' platformio.ini
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -165,31 +165,31 @@ jobs:
target:
- lucidgloves-prototype3
- lucidgloves-prototype4
- indexer-c
- indexer-cf
- indexer-cs
- indexer-csf
comm_flag:
- COMMUNICATION_PROTOCOL=COMMUNICATION_PROTOCOL_SERIAL
- COMMUNICATION_PROTOCOL=COMMUNICATION_PROTOCOL_BLE
- COMMUNICATION_PROTOCOL=OPENGLOVES_COMM_SERIAL
- COMMUNICATION_PROTOCOL=OPENGLOVES_COMM_BTSERIAL
coverage: [ false ]

include:
- os: ubuntu-latest
target: lucidgloves-prototype4
target: lucidgloves-prototype4-ffb
curl_calibration_flag: CALIBRATION_CURL="OH::MinMaxCalibrator<uint16_t, 0, ANALOG_MAX>"
coverage: true
- os: ubuntu-latest
target: lucidgloves-prototype4
target: lucidgloves-prototype4-ffb
curl_calibration_flag: CALIBRATION_CURL="OH::CenterPointDeviationCalibrator<uint16_t, 20, 270, 0, ANALOG_MAX>"
coverage: true
- os: ubuntu-latest
target: lucidgloves-prototype4
target: lucidgloves-prototype4-ffb
curl_calibration_flag: CALIBRATION_CURL="OH::FixedCenterPointDeviationCalibrator<uint16_t, 20, 270, 0, ANALOG_MAX>"
coverage: true
- os: ubuntu-latest
target: indexer-c
comm_flag: COMMUNICATION_PROTOCOL=COMMUNICATION_PROTOCOL_SERIAL
coverage: true
- os: ubuntu-latest
target: indexer-cs
comm_flag: COMMUNICATION_PROTOCOL=COMMUNICATION_PROTOCOL_SERIAL
target: indexer-csf
comm_flag: COMMUNICATION_PROTOCOL=OPENGLOVES_COMM_BTSERIAL
coverage: true

steps:
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ jobs:
target:
- lucidgloves-prototype3
- lucidgloves-prototype4
- lucidgloves-prototype4-ffb
- indexer-c
- indexer-cf
- indexer-cs
- indexer-csf
comm_flag:
- OPENGLOVES_COMMUNCATION=OPENGLOVES_COMM_SERIAL
- OPENGLOVES_COMMUNCATION=OPENGLOVES_COMM_BTSERIAL
Expand All @@ -137,6 +140,15 @@ jobs:
run: |
./.github/scripts/get_firmware_name.sh ${{ matrix.target }} ${{ matrix.comm_flag }}
- name: Update build command (non-Windows)
run: |
sed -i '/\[env\]/p; s/\[env\]/upload_protocol = custom/' platformio.ini
sed -i '/\[env\]/p; s/\[env\]/upload_command = \$PYTHONEXE .\/scripts\/ci\/create-archive.py \$FLASH_EXTRA_IMAGES \$ESP32_APP_OFFSET \$SOURCE/' platformio.ini
- name: Update build flags (non-macOS)
run: |
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.comm_flag }}/' platformio.ini
- name: Cache pip
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -168,15 +180,6 @@ jobs:
pio upgrade --dev
pio pkg update --global
- name: Update build command (non-Windows)
run: |
sed -i '/\[env\]/p; s/\[env\]/upload_protocol = custom/' platformio.ini
sed -i '/\[env\]/p; s/\[env\]/upload_command = \$PYTHONEXE .\/scripts\/ci\/create-archive.py \$FLASH_EXTRA_IMAGES \$ESP32_APP_OFFSET \$SOURCE/' platformio.ini
- name: Update build flags (non-macOS)
run: |
sed -i '/__OH_FIRMWARE__/p; s/__OH_FIRMWARE__/${{ matrix.comm_flag }}/' platformio.ini
- name: Build
run: |
mkdir build
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"xmemory": "cpp",
"xtree": "cpp",
"xhash": "cpp",
"xlocnum": "cpp"
"xlocnum": "cpp",
"ledc.h": "c"
},
"files.eol": "\n",
"files.insertFinalNewline": true,
Expand Down
55 changes: 53 additions & 2 deletions firmware/mode_configs/opengloves/opengloves.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <calibration.hpp>
#include <og_constants.hpp>
#include <og_serial_commmunications.hpp>
#include <og_serial_communication.hpp>
#include <opengloves_task.hpp>
#include <output_writers/servo.hpp>
#include <sensor.hpp>
#include <sensor/analog.hpp>
#include <sensor/digital.hpp>
Expand Down Expand Up @@ -122,6 +123,15 @@
#define UPDATE_RATE 90
#endif

#define FFB_THUMB_ENABLED (defined(PIN_FFB_THUMB) && (PIN_FFB_THUMB != -1))
#define FFB_INDEX_ENABLED (defined(PIN_FFB_INDEX) && (PIN_FFB_INDEX != -1))
#define FFB_MIDDLE_ENABLED (defined(PIN_FFB_MIDDLE) && (PIN_FFB_MIDDLE != -1))
#define FFB_RING_ENABLED (defined(PIN_FFB_RING) && (PIN_FFB_RING != -1))
#define FFB_PINKY_ENABLED (defined(PIN_FFB_PINKY) && (PIN_FFB_PINKY != -1))

#define FFB_ENABLED \
(FFB_THUMB_ENABLED || FFB_INDEX_ENABLED || FFB_MIDDLE_ENABLED || FFB_RING_ENABLED || FFB_PINKY_ENABLED)

using namespace OpenGloves;

HandSensors handSensors = {
Expand Down Expand Up @@ -268,9 +278,35 @@ std::vector<StringEncodedMemoizedSensor<uint16_t>*> joysticks = {

std::vector<IStringEncodedMemoizedSensor*> otherSensors = std::vector<IStringEncodedMemoizedSensor*>();

OpenGlovesConfig config = OpenGlovesConfig(UPDATE_RATE, CALIBRATION_DURATION, CALIBRATION_ALWAYS_CALIBRATE);
OpenGlovesTrackingTaskConfig config =
OpenGlovesTrackingTaskConfig(UPDATE_RATE, CALIBRATION_DURATION, CALIBRATION_ALWAYS_CALIBRATE);
OpenGlovesTrackingTask* trackingTask;

#if FFB_ENABLED
HandActuators handActuators = {
#if FFB_THUMB_ENABLED
.thumb = new OH::ServoActuator(PIN_FFB_THUMB),
#endif

#if FFB_INDEX_ENABLED
.index = new OH::ServoActuator(PIN_FFB_INDEX),
#endif

#if FFB_MIDDLE_ENABLED
.middle = new OH::ServoActuator(PIN_FFB_MIDDLE),
#endif

#if FFB_RING_ENABLED
.ring = new OH::ServoActuator(PIN_FFB_RING),
#endif

#if FFB_PINKY_ENABLED
.pinky = new OH::ServoActuator(PIN_FFB_PINKY),
#endif
};
OpenGlovesForceFeedbackTask* ffbTask;
#endif

void setupMode()
{
#if OPENGLOVES_COMMUNCATION == OPENGLOVES_COMM_SERIAL
Expand Down Expand Up @@ -302,6 +338,21 @@ void setupMode()
.priority = OPENGLOVES_FINGERS_TASK_PRIORITY,
}
);

#if FFB_ENABLED
ffbTask = new OpenGlovesForceFeedbackTask(
*communication,
handActuators,
UPDATE_RATE,
{
.name = "OpenGlovesForceFeedbackTask",
.stackDepth = 8192,
.priority = OPENGLOVES_FINGERS_TASK_PRIORITY,
}
);
ffbTask->begin();
#endif

trackingTask->begin();
}

Expand Down
Loading

1 comment on commit faddc24

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

39.53%

Please sign in to comment.