Skip to content

Commit

Permalink
Merge pull request #74 from senseshift/feature/advanced-fingers
Browse files Browse the repository at this point in the history
feat(OpenGloves): add advanced finger sensors
  • Loading branch information
leon0399 authored Aug 5, 2023
2 parents acbbc59 + 778c579 commit 7dc118f
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 123 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,34 @@ jobs:
matrix:
os: [ ubuntu-latest ]
target:
- lucidgloves-prototype3-esp32
- lucidgloves-prototype4-esp32
- lucidgloves-prototype3
- lucidgloves-prototype4
comm_flag:
- COMMUNICATION_PROTOCOL=COMMUNICATION_PROTOCOL_SERIAL
- COMMUNICATION_PROTOCOL=COMMUNICATION_PROTOCOL_BLE
coverage: [ false ]

include:
- os: ubuntu-latest
target: lucidgloves-prototype4-esp32
target: lucidgloves-prototype4
curl_calibration_flag: CALIBRATION_CURL="OH::MinMaxCalibrator<uint16_t, 0, ANALOG_MAX>"
coverage: true
- os: ubuntu-latest
target: lucidgloves-prototype4-esp32
target: lucidgloves-prototype4
curl_calibration_flag: CALIBRATION_CURL="OH::CenterPointDeviationCalibrator<uint16_t, 20, 270, 0, ANALOG_MAX>"
coverage: true
- os: ubuntu-latest
target: lucidgloves-prototype4-esp32
target: lucidgloves-prototype4
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
coverage: true

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- 'include'
- 'firmware'
- 'examples'
- 'test'
fail-fast: false
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ jobs:
strategy:
matrix:
target:
- lucidgloves-prototype3-esp32
- lucidgloves-prototype4-esp32
- lucidgloves-prototype3
- lucidgloves-prototype4
- indexer-c
- indexer-cs
comm_flag:
- OPENGLOVES_COMMUNCATION=OPENGLOVES_COMM_SERIAL
- OPENGLOVES_COMMUNCATION=OPENGLOVES_COMM_BTSERIAL
Expand Down
91 changes: 78 additions & 13 deletions firmware/mode_configs/opengloves/opengloves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,23 @@
#define FINGER_MIDDLE_ENABLED (defined(PIN_FINGER_MIDDLE) && (PIN_FINGER_MIDDLE != -1))
#define FINGER_RING_ENABLED (defined(PIN_FINGER_RING) && (PIN_FINGER_RING != -1))
#define FINGER_PINKY_ENABLED (defined(PIN_FINGER_PINKY) && (PIN_FINGER_PINKY != -1))
#define FINGER_CLASS(type, pin, invert, calib) \
FingerSensor(new OH::CalibratedSensor<uint16_t>(new OH::AnalogSensor<invert>(pin), new calib()), type)
#define FINGER_CLASS(type, curl_pin, curl_invert, curl_calib) \
FingerSensor( \
new OH::CalibratedSensor<uint16_t>(new OH::AnalogSensor<curl_invert>(curl_pin), new curl_calib()), \
type \
)
#define FINGER_THUMB_SPLAY (FINGER_THUMB_ENABLED && defined(PIN_FINGER_THUMB_SPLAY) && (PIN_FINGER_THUMB_SPLAY != -1))
#define FINGER_INDEX_SPLAY (FINGER_INDEX_ENABLED && defined(PIN_FINGER_INDEX_SPLAY) && (PIN_FINGER_INDEX_SPLAY != -1))
#define FINGER_MIDDLE_SPLAY \
(FINGER_MIDDLE_ENABLED && defined(PIN_FINGER_MIDDLE_SPLAY) && (PIN_FINGER_MIDDLE_SPLAY != -1))
#define FINGER_RING_SPLAY (FINGER_RING_ENABLED && defined(PIN_FINGER_RING_SPLAY) && (PIN_FINGER_RING_SPLAY != -1))
#define FINGER_PINKY_SPLAY (FINGER_PINKY_ENABLED && defined(PIN_FINGER_PINKY_SPLAY) && (PIN_FINGER_PINKY_SPLAY != -1))
#define FINGER_SPLAY_CLASS(type, curl_pin, curl_invert, curl_calib, splay_pin, splay_invert, splay_calib) \
FingerSensor( \
new OH::CalibratedSensor<uint16_t>(new OH::AnalogSensor<curl_invert>(curl_pin), new curl_calib()), \
new OH::CalibratedSensor<uint16_t>(new OH::AnalogSensor<splay_invert>(splay_pin), new splay_calib()), \
type \
)

#pragma endregion

Expand Down Expand Up @@ -110,23 +125,73 @@
using namespace OpenGloves;

HandSensors handSensors = {
#if FINGER_THUMB_ENABLED
#if FINGER_THUMB_SPLAY
.thumb = FINGER_SPLAY_CLASS(
IEncodedInput::Type::THUMB,
PIN_FINGER_THUMB,
FINGER_THUMB_INVERT,
CALIBRATION_CURL,
PIN_FINGER_THUMB_SPLAY,
FINGER_THUMB_SPLAY_INVERT,
CALIBRATION_SPLAY
),
#elif FINGER_THUMB_ENABLED
.thumb = FINGER_CLASS(IEncodedInput::Type::THUMB, PIN_FINGER_THUMB, FINGER_THUMB_INVERT, CALIBRATION_CURL),
#endif

#if FINGER_INDEX_ENABLED
#if FINGER_INDEX_SPLAY
.index = FINGER_SPLAY_CLASS(
IEncodedInput::Type::INDEX,
PIN_FINGER_INDEX,
FINGER_INDEX_INVERT,
CALIBRATION_CURL,
PIN_FINGER_INDEX_SPLAY,
FINGER_INDEX_SPLAY_INVERT,
CALIBRATION_SPLAY
),
#elif FINGER_INDEX_ENABLED
.index = FINGER_CLASS(IEncodedInput::Type::INDEX, PIN_FINGER_INDEX, FINGER_INDEX_INVERT, CALIBRATION_CURL),
#endif

#if FINGER_MIDDLE_ENABLED
#if FINGER_MIDDLE_SPLAY
.middle = FINGER_SPLAY_CLASS(
IEncodedInput::Type::MIDDLE,
PIN_FINGER_MIDDLE,
FINGER_MIDDLE_INVERT,
CALIBRATION_CURL,
PIN_FINGER_MIDDLE_SPLAY,
FINGER_MIDDLE_SPLAY_INVERT,
CALIBRATION_SPLAY
),
#elif FINGER_MIDDLE_ENABLED
.middle = FINGER_CLASS(IEncodedInput::Type::MIDDLE, PIN_FINGER_MIDDLE, FINGER_MIDDLE_INVERT, CALIBRATION_CURL),
#endif

#if FINGER_RING_ENABLED
#if FINGER_RING_SPLAY
.ring = FINGER_SPLAY_CLASS(
IEncodedInput::Type::RING,
PIN_FINGER_RING,
FINGER_RING_INVERT,
CALIBRATION_CURL,
PIN_FINGER_RING_SPLAY,
FINGER_RING_SPLAY_INVERT,
CALIBRATION_SPLAY
),
#elif FINGER_RING_ENABLED
.ring = FINGER_CLASS(IEncodedInput::Type::RING, PIN_FINGER_RING, FINGER_RING_INVERT, CALIBRATION_CURL),
#endif

#if FINGER_PINKY_ENABLED
#if FINGER_PINKY_SPLAY
.pinky = FINGER_SPLAY_CLASS(
IEncodedInput::Type::PINKY,
PIN_FINGER_PINKY,
FINGER_PINKY_INVERT,
CALIBRATION_CURL,
PIN_FINGER_PINKY_SPLAY,
FINGER_PINKY_SPLAY_INVERT,
CALIBRATION_SPLAY
),
#elif FINGER_PINKY_ENABLED
.pinky = FINGER_CLASS(IEncodedInput::Type::PINKY, PIN_FINGER_PINKY, FINGER_PINKY_INVERT, CALIBRATION_CURL),
#endif
};
Expand Down Expand Up @@ -161,7 +226,7 @@ std::vector<StringEncodedMemoizedSensor<bool>*> buttons = std::vector<StringEnco
#if GESTURE_TRIGGER_ENABLED && FINGER_INDEX_ENABLED
new GESTURE_CLASS(
IEncodedInput::Type::TRIGGER,
new TriggerGesture(&handSensors.index.value(), GESTURE_TRIGGER_THRESHOLD)
new TriggerGesture(handSensors.index.value(), GESTURE_TRIGGER_THRESHOLD)
),
#elif BUTTON_TRIGGER_ENABLED
new BUTTON_CLASS(IEncodedInput::Type::TRIGGER, PIN_BUTTON_TRIGGER, BUTTON_TRIGGER_INVERT),
Expand All @@ -171,10 +236,10 @@ std::vector<StringEncodedMemoizedSensor<bool>*> buttons = std::vector<StringEnco
new GESTURE_CLASS(
IEncodedInput::Type::GRAB,
new GrabGesture(
&handSensors.index.value(),
&handSensors.middle.value(),
&handSensors.ring.value(),
&handSensors.pinky.value(),
handSensors.index.value(),
handSensors.middle.value(),
handSensors.ring.value(),
handSensors.pinky.value(),
GESTURE_GRAB_THRESHOLD
)
),
Expand All @@ -185,7 +250,7 @@ std::vector<StringEncodedMemoizedSensor<bool>*> buttons = std::vector<StringEnco
#if GESTURE_PINCH_ENABLED && FINGER_THUMB_ENABLED && FINGER_INDEX_ENABLED
new GESTURE_CLASS(
IEncodedInput::Type::PINCH,
new PinchGesture(&handSensors.thumb.value(), &handSensors.index.value(), GESTURE_PINCH_THRESHOLD)
new PinchGesture(handSensors.thumb.value(), handSensors.index.value(), GESTURE_PINCH_THRESHOLD)
),
#elif BUTTON_PINCH_ENABLED
new BUTTON_CLASS(IEncodedInput::Type::PINCH, PIN_BUTTON_PINCH, BUTTON_PINCH_INVERT),
Expand Down
92 changes: 90 additions & 2 deletions ini/opengloves.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ build_flags = ${common.build_flags}
-D FINGER_RING_INVERT=false
-D FINGER_PINKY_INVERT=false

-D FINGER_THUMB_SPLAY_INVERT=false
-D FINGER_INDEX_SPLAY_INVERT=false
-D FINGER_MIDDLE_SPLAY_INVERT=false
-D FINGER_RING_SPLAY_INVERT=false
-D FINGER_PINKY_SPLAY_INVERT=false

-D JOYSTICK_X_INVERT=false
-D JOYSTICK_Y_INVERT=false
-D JOYSTICK_DEADZONE=0.1
Expand Down Expand Up @@ -57,7 +63,7 @@ lib_deps = ${common.lib_deps}
; LucidGloves Prototype 3
; Wiring Diagram: https://github.com/LucidVR/lucidgloves/wiki/Prototype-3-Wiring-Diagram
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[env:lucidgloves-prototype3-esp32]
[env:lucidgloves-prototype3]
platform = ${opengloves.platform}
platform_packages = ${opengloves.platform_packages}
framework = ${opengloves.framework}
Expand Down Expand Up @@ -90,7 +96,7 @@ lib_deps = ${opengloves.lib_deps}
; LucidGloves Prototype 4
; Wiring Diagram: https://github.com/LucidVR/lucidgloves/wiki/Prototype-4-Wiring-Diagram
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[env:lucidgloves-prototype4-esp32]
[env:lucidgloves-prototype4]
platform = ${opengloves.platform}
platform_packages = ${opengloves.platform_packages}
framework = ${opengloves.framework}
Expand Down Expand Up @@ -125,3 +131,85 @@ build_unflags = ${opengloves.build_unflags}
build_src_filter = ${opengloves.build_src_filter}
+<mode_configs/opengloves/opengloves.cpp>
lib_deps = ${opengloves.lib_deps}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Indexer C
; Wiring Diagram: https://github.com/Valsvirtuals/Indexer/wiki/wiring-and-pinout
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[env:indexer-c]
platform = ${opengloves.platform}
platform_packages = ${opengloves.platform_packages}
framework = ${opengloves.framework}
board = wemos_d1_mini32
upload_speed = ${opengloves.upload_speed}
monitor_speed = ${opengloves.monitor_speed}

build_flags = ${opengloves.build_flags}
; Pins configuration
; Comment out to disable
-D PIN_FINGER_THUMB=25
-D PIN_FINGER_INDEX=14
-D PIN_FINGER_MIDDLE=33
-D PIN_FINGER_RING=39
-D PIN_FINGER_PINKY=36

-D PIN_JOYSTICK_X=12
-D PIN_JOYSTICK_Y=4
-D PIN_BUTTON_JOYSTICK=0

-D PIN_BUTTON_A=2
-D PIN_BUTTON_B=11
; -D PIN_BUTTON_MENU=5
-D PIN_BUTTON_CALIBRATE=27
; -D PIN_BUTTON_TRIGGER=19 ; unused if GESTURE_TRIGGER is true
; -D PIN_BUTTON_GRAB=18 ; unused if GESTURE_GRAB is true
; -D PIN_BUTTON_PINCH=23 ; unused if GESTURE_PINCH is true

build_unflags = ${opengloves.build_unflags}
build_src_filter = ${opengloves.build_src_filter}
+<mode_configs/opengloves/opengloves.cpp>
lib_deps = ${opengloves.lib_deps}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Indexer CS
; Wiring Diagram: https://github.com/Valsvirtuals/Indexer/wiki/wiring-and-pinout
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[env:indexer-cs]
platform = ${opengloves.platform}
platform_packages = ${opengloves.platform_packages}
framework = ${opengloves.framework}
board = wemos_d1_mini32
upload_speed = ${opengloves.upload_speed}
monitor_speed = ${opengloves.monitor_speed}

build_flags = ${opengloves.build_flags}
; Pins configuration
; Comment out to disable
-D PIN_FINGER_THUMB=25
-D PIN_FINGER_INDEX=14
-D PIN_FINGER_MIDDLE=33
-D PIN_FINGER_RING=39
-D PIN_FINGER_PINKY=36

-D PIN_FINGER_THUMB_SPLAY=32
-D PIN_FINGER_INDEX_SPLAY=13
-D PIN_FINGER_MIDDLE_SPLAY=34
-D PIN_FINGER_RING_SPLAY=35
-D PIN_FINGER_PINKY_SPLAY=26

-D PIN_JOYSTICK_X=12
-D PIN_JOYSTICK_Y=4
-D PIN_BUTTON_JOYSTICK=0

-D PIN_BUTTON_A=2
-D PIN_BUTTON_B=11
; -D PIN_BUTTON_MENU=5
-D PIN_BUTTON_CALIBRATE=27
; -D PIN_BUTTON_TRIGGER=19 ; unused if GESTURE_TRIGGER is true
; -D PIN_BUTTON_GRAB=18 ; unused if GESTURE_GRAB is true
; -D PIN_BUTTON_PINCH=23 ; unused if GESTURE_PINCH is true

build_unflags = ${opengloves.build_unflags}
build_src_filter = ${opengloves.build_src_filter}
+<mode_configs/opengloves/opengloves.cpp>
lib_deps = ${opengloves.lib_deps}
2 changes: 1 addition & 1 deletion lib/arduino/battery/adc_naive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace OH {

BatteryState ADCNaiveBattery::getValue()
{
return { .level = simpleMap<uint16_t>(analogRead(this->pin), 4095, 255) };
return { .level = static_cast<uint8_t>(simpleMap<uint16_t>(analogRead(this->pin), 4095, 255)) };
}
} // namespace OH
12 changes: 6 additions & 6 deletions lib/calibration/calibration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace OH {
virtual void disableCalibration() = 0;
};

class Calibrated : public ICalibrated {
class Calibrated : public virtual ICalibrated {
protected:
bool calibrate = false;

Expand Down Expand Up @@ -79,7 +79,7 @@ namespace OH {
_Tp output = accurateMap<_Tp>(input, value_min, value_max, output_min, output_max);

// Lock the range to the output.
return constrain(output, output_min, output_max);
return std::clamp(output, output_min, output_max);
}

private:
Expand Down Expand Up @@ -118,8 +118,8 @@ namespace OH {
// Map the input to the sensor range of motion.
int output = accurateMap<_Tp>(input, output_min, output_max, 0, sensor_max);

// Find the deviation from the center and constrain it to the maximum that the driver supports.
output = constrain(output - center, -driver_max_deviation, driver_max_deviation);
// Find the deviation from the center and clamp it to the maximum that the driver supports.
output = std::clamp<int>(output - center, -driver_max_deviation, driver_max_deviation);

// Finally map the deviation from the center back to the output range.
return (_Tp) accurateMap<int>(output, -driver_max_deviation, driver_max_deviation, output_min, output_max);
Expand All @@ -144,8 +144,8 @@ namespace OH {
// Map the input to the sensor range of motion.
int output = accurateMap<_Tp>(input, output_min, output_max, 0, sensor_max);

// Find the deviation from the center and constrain it to the maximum that the driver supports.
output = constrain(output - center, -driver_max_deviation, driver_max_deviation);
// Find the deviation from the center and clamp it to the maximum that the driver supports.
output = std::clamp<int>(output - center, -driver_max_deviation, driver_max_deviation);

// Finally map the deviation from the center back to the output range.
return (_Tp) accurateMap<int>(output, -driver_max_deviation, driver_max_deviation, output_min, output_max);
Expand Down
4 changes: 0 additions & 4 deletions lib/core/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <iterator>
#include <logging.hpp>

#ifndef constrain
#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
#endif

namespace OH {
/**
* Checks if a container contains a value.
Expand Down
Loading

1 comment on commit 7dc118f

@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

42.47%

Please sign in to comment.