Skip to content

Commit

Permalink
Update code refactoring and documentation/changelo
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoAbbo committed Apr 4, 2024
1 parent 88e4f23 commit 8011e44
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 50 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
# Change Log
All notable changes to this project will be documented in this file.

### [1.3.0] -

### Added
* WeArtAnalogSensorRawDataObject new class that provides analog raw data from thimble's sensors

### Changed
* WeArtRawSensorDataTrackingObject to WeArtTrackingRawDataObject
* SensorData to TrackingRawData


### [1.2.0] - 2024-02-16
* Add raw sensors data tracking object
* Add middleware status messages and event
Expand Down
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The Weart Low-Level C# SDK allows to connect to the Weart middleware and perfor
* Start and Stop the middleware operations
* Calibrate the device
* Receive tracking data from the devices
* Receive raw data from the thimble's motion sensors
* Receive analog raw data from the thimble's senosrs
* Send haptic effects to the devices

## Installation
Expand All @@ -16,19 +18,7 @@ On Visual Studio:
* Select all the sdk source files and click "Add"

## Documentation
For the documentation, go [here](https://weart.it/docs/sdkcsharp/)

## Changelog

### Version 1.1.1 (latest)
* Fix connection issue to middleware while offline

### Version 1.1
* Add calibration procedure start/stop and listener
* Add new default tracking message and values for closure
* Add basic effect class for haptic feedback
* Remove unused velocity parameters from texture

For the documentation, go [here](https://weart.it/developer-guide/)

## Copyright

Expand Down
17 changes: 11 additions & 6 deletions WeArtAnalogSensorRawDataObject.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/**
* WEART - Analog sensor raw data
* https://www.weart.it/
*/

using WeArt.Core;
using WeArt.Messages;

namespace WeArt.Components
{
internal class WeArtAnalogSensorRawDataObject

/// <summary>
/// This component receives and exposes anlog raw sensors data from the thimbles
/// </summary>
public class WeArtAnalogSensorRawDataObject
{
public delegate void dAnalogSensorRawDataEvent(AnalogSensorRawData analogRawData);

Expand Down
2 changes: 1 addition & 1 deletion WeArtCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public struct TimeOfFlight
public int Distance { get; set; }
}

public class SensorData
public class TrackingRawData
{
[JsonIgnore]
public DateTime Timestamp { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions WeArtMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ public class RawDataOffMessage : WeArtJsonMessage { }
public class RawDataMessage : WeArtJsonMessage
{
public HandSide HandSide { get; set; }
public SensorData Index { get; set; }
public SensorData Thumb { get; set; }
public SensorData Middle { get; set; }
public SensorData Palm { get; set; }
public TrackingRawData Index { get; set; }
public TrackingRawData Thumb { get; set; }
public TrackingRawData Middle { get; set; }
public TrackingRawData Palm { get; set; }
}

[WeArtMiddlewareMessageID("RAW_SENSOR_ON_MASK")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace WeArt.Components
/// <summary>
/// This component receives and exposes raw sensors data from the hardware
/// </summary>
public class WeArtRawSensorsDataTrackingObject
public class WeArtTrackingRawDataObject
{
public delegate void dRawSensorDataEvent(SensorData sensorsData);
public delegate void dRawSensorDataEvent(TrackingRawData sensorsData);

public event dRawSensorDataEvent DataReceived;

Expand All @@ -40,9 +40,9 @@ public ActuationPoint ActuationPoint
set => _actuationPoint = value;
}

public SensorData LastSample { get; private set; }
public TrackingRawData LastSample { get; private set; }

public WeArtRawSensorsDataTrackingObject(WeArtClient client, HandSide handSide = HandSide.Right, ActuationPoint actuationPoint = ActuationPoint.Index)
public WeArtTrackingRawDataObject(WeArtClient client, HandSide handSide = HandSide.Right, ActuationPoint actuationPoint = ActuationPoint.Index)
{
_client = client;
_client.OnConnectionStatusChanged -= OnConnectionChanged;
Expand All @@ -51,12 +51,12 @@ public WeArtRawSensorsDataTrackingObject(WeArtClient client, HandSide handSide =
_client.OnMessage += OnMessageReceived;
HandSide = handSide;
ActuationPoint = actuationPoint;
LastSample = new SensorData { };
LastSample = new TrackingRawData { };
}

internal void OnConnectionChanged(bool connected)
{
LastSample = new SensorData { };
LastSample = new TrackingRawData { };
}

private void OnMessageReceived(WeArtClient.MessageType type, IWeArtMessage message)
Expand All @@ -69,7 +69,7 @@ private void OnMessageReceived(WeArtClient.MessageType type, IWeArtMessage messa
if (rawDataMessage.HandSide != _handSide)
return;

SensorData newSample;
TrackingRawData newSample;
switch (ActuationPoint)
{
case ActuationPoint.Thumb: newSample = rawDataMessage.Thumb; break;
Expand Down
58 changes: 44 additions & 14 deletions docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void AddEffectSample1_Click(object sender, RoutedEventArgs e)
}
~~~~~~~~~~~~~

### Raw Sensors Data tracking
### Tracking raw data

![Raw Sensors Data Panel](./example_app/ExampleApp_RawData.png)

Expand All @@ -206,27 +206,57 @@ In particular, it's possible to choose the hand and actuation point from which t

To start receiving raw data, click on the "Start Raw Data" button, and to stop click on the "Stop Raw Data" button.

When it's loaded, the application creates a WeArt.Components.WeArtRawSensorsDataTrackingObject for each pair of (HandSide, ActuationPoint).
When it's loaded, the application creates a WeArt.Components.WeArtTrackingRawDataObject for each pair of (HandSide, ActuationPoint).
When one of the combo boxes values changes, the application adds a callback to the corresponding tracking object.
The callback is responsible for displaying the received sample:

~~~~~~~~~~~~~{.cs}
private void RenderRawDataAsync(SensorData data)
private void RenderRawDataAsync(TrackingRawData data)
{
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
Acc_X.Text = data.Accelerometer.X.ToString();
Acc_Y.Text = data.Accelerometer.Y.ToString();
Acc_Y.Text = data.Accelerometer.Z.ToString();
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
Acc_X.Text = data.Accelerometer.X.ToString();
Acc_Y.Text = data.Accelerometer.Y.ToString();
Acc_Y.Text = data.Accelerometer.Z.ToString();
Gyro_X.Text = data.Gyroscope.X.ToString();
Gyro_Y.Text = data.Gyroscope.Y.ToString();
Gyro_Y.Text = data.Gyroscope.Z.ToString();
Gyro_X.Text = data.Gyroscope.X.ToString();
Gyro_Y.Text = data.Gyroscope.Y.ToString();
Gyro_Y.Text = data.Gyroscope.Z.ToString();
TimeOfFlight.Text = data.TimeOfFlight.Distance.ToString();
TimeOfFlight.Text = data.TimeOfFlight.Distance.ToString();
LastSampleTime.Text = data.Timestamp.ToString("yyyy/MM/dd HH:mm:ss.fff");
});
LastSampleTime.Text = data.Timestamp.ToString("yyyy/MM/dd HH:mm:ss.fff");
});
}
~~~~~~~~~~~~~

### Analog Raw Sensors Data

![Analog Sensors Data Panel](./example_app/ExampleApp_AnalogSensorData.png)

In the right section of the window, the application displays the anlog raw data of the different sensors aboard the TouchDIVER.
In particular, it's possible to choose the hand and actuation point from which to visualize:
* Timestamp of the last sample received
* NTC - Negative Temperature Coefficient (raw data and converted degree)
* FSR - force sensing resistor (raw adata and converted newton)

To start receiving analog sensor data, active this function on the Middleware and click on the "Start Raw Data" button, and to stop click on the "Stop Raw Data" button. In this modality the other tracking data will not received by the SDK.

When it's loaded, the application creates a WeArt.Components.WeArtAnalogSensorRawDataObject for each pair of (HandSide, ActuationPoint).
Using a timer, the application polls the chosen sensor and displays its data:

~~~~~~~~~~~~~{.cpp}
private void RenderAanlogSensorRawDataAsync(AnalogSensorRawData data)
{
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
ntcTempRawValue.Text = data.NtcTemperatureRaw.ToString();
ntcTempRawConvertedValue.Text = data.NtcTemperatureConverted.ToString();
forceSensingRawValue.Text = data.ForceSensingRaw.ToString();
forceSensingConvertedValue.Text = data.ForceSensingConverted.ToString();
LastSampleTime.Text = data.Timestamp.ToString("yyyy/MM/dd HH:mm:ss.fff");
});
}
~~~~~~~~~~~~~

Expand Down
37 changes: 32 additions & 5 deletions docs/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ The abduction value ranges from 0 (finger near the hand's central axis) to 1 (fi

@note The **closure** value is available for all thimbles, while the **abduction** value is available only for the thumb (other thimbles will have a value of 0).

## Raw Sensors Data
## Tracking Raw Data

It's possible to receive the raw data from the sensors on each thimble (and the control unit), in addition to the tracking data.
Each sensor has:
* 3-axis accelerometer
* 3-axis gyroscope
* Time of Flight sensor

To read these values, create a WeArtRawSensorsDataTrackingObject object and add it to the client.
To read these values, create a WeArtTrackingRawDataObject and add it to the client.
~~~~~~~~~~~~~{.cs}
WeArtRawSensorsDataTrackingObject rawSensorData = new WeArtRawSensorsDataTrackingObject(weArtClient, HandSide.Right, ActuationPoint.Index);
WeArtTrackingRawDataObject rawSensorData = new WeArtTrackingRawDataObject(weArtClient, HandSide.Right, ActuationPoint.Index);
~~~~~~~~~~~~~

Once this object is added to the client, it will listen for raw data messages.
Expand All @@ -197,7 +197,7 @@ To stop receiving raw data, call the WeArtClient.StopRawData() method.
To get the sensors data, get the latest sample (SensorData) from the WeArtRawSensorsDataTrackingObject object.
The sample contains the accelerometer, gyroscope and time of flight data, in addition to the timestamp of its sampling (generated by the middleware and represented as a DateTime value).
~~~~~~~~~~~~~{.cs}
SensorData sample = rawSensorData.LastSample;
TrackingRawData sample = rawSensorData.LastSample;
~~~~~~~~~~~~~

@note The Palm (control unit) doesn't contain a Time-Of-Flight sensor, so its value is always set to 0.
Expand All @@ -206,11 +206,38 @@ In addition to getting the latest sample by polling the tracking object, it's po
received from the TouchDIVER.

~~~~~~~~~~~~~{.cs}
rawSensorData.DataReceived += (SensorData data) => {
rawSensorData.DataReceived += (TrackingRawData data) => {
// process the sensor data sample
};
~~~~~~~~~~~~~

## Analog Raw Sensors Data

It's possible to receive the raw data from the sensors on each thimble (and the control unit), instead of the tracking data when this function is activated on the Middleware.
Each sensor has:
* NTC - Negative Temperature Coefficient (raw data and converted degree)
* FSR - force sensing resistor (raw adata and converted newton)

To read these values, create a WeArtAnalogSensorRawDataObject object and add it to the client.
~~~~~~~~~~~~~{.cs}
WeArtAnalogSensorRawDataObject anlogSensorData = new WeArtAnalogSensorRawDataObject(_weartClient, HandSide, ActuationPoint);
~~~~~~~~~~~~~

Once this object is added to the client, it will listen for raw data messages as soon the Middleware is on start.

To get the sensors data, get the latest sample (WeArtAnalogSensorData) from the AnalogSensorRawData object.
The sample contains the accelerometer, gyroscope and time of flight data, in addition to the timestamp of its sampling (generated by the middleware and represented as milliseconds in unix epoch time).
~~~~~~~~~~~~~{.cpp}
AnalogSensorRawData sample = anlogSensorData.LastSample;
sample.NtcTemperatureRaw;
sample.NtcTemperatureConverted;
sample.ForceSensingRaw;
sample.ForceSensingConverted;
sample.Timestamp.ToString("yyyy/MM/dd HH:mm:ss.fff");
~~~~~~~~~~~~~

@note The Palm (control unit) doesn't contain a analog sensor, so its value is always set to 0.

## Middleware and Devices status tracking

The SDK allows to track and receives updates about the middleware and the connected devices status.
Expand Down

0 comments on commit 8011e44

Please sign in to comment.