Data collection
The next step is to collect data to form a dataset. This entails:
- Using a board with an accelerometer running Infuse-IoT firmware.
- Build and Flash the tag with a suitable accelerometer firmware.
- During an experiment, log accelerometer values to the data logger or the GATT peripheral
- and utilise Python tools to annotate the raw data.
- Use Python tools to download the data logger data, or save the live GATT peripheral data
- Preprocess data (calculate the magnitudes, etc)
- Sample windows of data based on events for a balance dataset
- Save the dataset
Boards and devices
When selecting a board to use it must:
- Have an accelerometer (or other sensor to provide suitable data) and
- Have a way to log the sensor data either via
- The data logger subsystem, or
Using the data logger is preferred, however ensure the capacity is suitable for the sensor and experiment. For example 100Hz accelerometer data occupies at least 72kB per hour. Ensure a suitable size is available to prevent existing data being overwritten.
- A reliable ePacket interface
like Serial or Bluetooth to stream the data live.
Although a Serial link is more reliable, a cable may change the movement profile. Utilising the bluetooth is the most convenient method to stream the data wirelessly.
- The data logger subsystem, or
Suitable boards include the Thingy:52/53/91 and the nRF54L15 Tag.
For this demo, the nRF54L15 Tag
will be used as the sensor board.
The Zephyr board target is nrf54l15tag/nrf54l15/cpuapp.
Alternately, you can use a suitable Custom Tag Board instead.
Enter the board name/target of the custom board to update commands below
A second board will be required to be used as a gateway (unless using infuse native_bt).
This just requires a board with Bluetooth (e.g. nRF52840DK, nRF54L15DK, etc.)
For this demo, the nRF54L15DK
will be used as the gateway board. In Zephyr this target is referred to as nrf54l15dk/nrf54l15/cpuapp.
If using a custom board for the gateway device, enter the board name to update commands below
VDD:IO) to the VDD SWD0.Hardware Preparation
Ensure both devices have been provisioned by following the provisioning guide. This step can be skipped if both devices are already provisioned.
Build and Flash the Gateway
With your gateway device connected, follow the steps in Flashing a Gateway to program your gateway if it is not already running Gateway firmware.
Build and Flash the tag
Then build the task_runner: imu application sample for the tag:
west build -b nrf54l15tag/nrf54l15/cpuapp infuse-sdk/samples/task_runner/imu
west build -b nrf54l15tag/nrf54l15/cpuapp infuse-sdk/samples/task_runner/imu
And flash the tag with the following command.
west flash -d build/nrf54l15tag/nrf54l15/cpuapp/imu
west flash -d build/nrf54l15tag/nrf54l15/cpuapp/imu
Prepare your Gateway
Follow the guide to connect to your gateway using the Python Tools.
infuse native_bt See
Native Bluetooth
for more details.Prepare for an experiment
Before we can run the experiment there's a few steps to take to get ready beforehand.
About your Tag
To capture raw data and send annotate data to the tag we will need to be able to connect and run commands on the tag. To do this we will need to know the tag's Infuse ID. Follow these instructions to get the tag's Infuse ID.
You can also enter it below to substitute it into subsequent commands.
Data Collection
While running an experiment we need to save the raw sensor data during the experiment. This leaves us with two main options:
- Storing raw sensor data locally on the tag's local flash (preferably SD card or external flash).
- Streaming the raw sensor data live over Bluetooth (or serial).
Streaming the data may be more simple, but can be susceptible to data loss in the case of signal interference or range constraints. Conversely, storing the data on the tag is more reliable, however getting the data off the tag requires a bit more effort.
For this demonstration, we will use the streaming approach, especially since the nRF54L15 Tag does not have external flash loaded by default, limiting how much accelerometer data can be recorded.
We can also try this out ahead of the experiment:
With your gateway connected and running (ensuring the Python Gateway script is also running)
Choose a suitable location to save the logs:
And run the following command (in another terminal) to connect to the Tag, start streaming accelerometer data and saving it to your machine:
infuse bt_log --id 0x123456789ABCDEF --csv ~/csv_data --data
Once connected, there should be TDF messages appearing in the terminal, something similar to:
[11:44:12.950] Connected to 123456789ABCDEF (DATA)
Opening new ~/csv_data/123456789ABCDEF_ACC_4G.csv
1581889511.712 TDF: ACC_4G[10]
Opening new ~/csv_data/123456789ABCDEF_BATTERY_STATE.csv
1581889512.725 TDF: BATTERY_STATE
1581889511.895 TDF: ACC_4G[18]
1581889512.232 TDF: ACC_4G[32]
1581889512.837 TDF: ACC_4G[2]
1581889512.857 TDF: ACC_4G[29]
1581889513.395 TDF: ACC_4G[23]
This will create a new .csv file in ~/csv_data for each type of TDF.
This includes:
- Accelerometer Data (
0x123456789ABCDEF_ACC_XG.csv, where X is 2, 4, 8, or 16) - Annotations (
0x123456789ABCDEF_ANNOTATION.csv) - Battery Voltages (
0x123456789ABCDEF_BATTERY_STATE.csv) and more.This tool will continue to log new data until you close it with c.
Coming Soon
Annotation Labels
While recording the raw data, we will want to send annotations to indicate that this raw data is useful and what was occuring. This will become the labels in the labelled dataset.
This can be done via the annotation RPC (Command),
which logs a timestamped annotation TDF (Sensor data).
To simplify the process the infuse annotate_events tool can be used. It simplifies:
- Handling timing between the two systems when creating annotations to minimise delay.
- Maintaining a constant connection (to reduce down time connecting to the device).
- Pre-configurable or manually typed labels.
Time Configuration
Because many Infuse-IoT embedded devices are not networked, they do not always have a method to obtain the current time and even if they do, it will drift during operation. In this demo to keep things simple we will use the default behaviour which will prompt users to set the device time before an experiment. This is recommended since it improves the tool's reliability.
Only use
--skip-time if you know what you're doing.Loggers
When we send the annotation we need that to be saved somewhere ideally alongside our data. This could either be on the device (on either the onboard or removeable storage) or sent to a different device (over Bluetooth, UDP or Serial).
For the nRF54L15 Tag, we will be streaming the raw data over Bluetooth, so the easiest way to log this data will be over the Bluetooth interface by providing the --gatt argument.
However, if utilising the on device storage, --onboard or --external arguments can be used to store data to the corresponding onboard or removeable flash loggers.
For the nRF52L15 Tag, streaming the data will require annotations to be sent over the Bluetooth interface using --gatt.
Labels
Before we can send annotations to the device, we need a set of labels we want to classify. This can be whatever we want such as the behaviours we're aiming to classify such as:
- Swipe right
- Swipe left
- Double shake
- Double tap
- Rotation clockwise
- Rotation counter-clockwise
- Idle
- Unknown
However, the Nordic Edge-AI Lab requires datasets to be formatted in a particular way. Rather than having a window of time series data labelled as a specific event, Nordic Edge AI lab's datasets require:
- A label for each time series sample (not window).
- Option to provide an additional metadata field for the recording window.
This provides some interesting optimisations such as applying sliding windows during the recording window, which can help the training process to accomodate with the fact that windows of data at runtime are random (not perfectly aligned to the start and end of an event).
As a result marking the start and end of a series of gestures greately simplifies the process. Therefore each of the labels above will have a start and a stop label.
Running the tool will allow the user to type each label in, however this is slow, especially if it's the same labels each time.
Instead, we can supply a .json file containing the labels we want to use and supply this file instead.
[ "swipe_right start", "swipe_left start", "double_shake start", "double_tap start", "triple_tap start", "rotation_cw start", "rotation_ccw start", "idle start", "unknown start", "swipe_right end", "swipe_left end", "double_shake end", "double_tap end", "triple_tap end", "rotation_cw end", "rotation_ccw end", "idle end", "unknown end" ]
Create the labels.json label file with the same contents.
Simlarly, some behaviours might be more specific and require more fine tuned labelling. Usually, a label may be required on a per-event basis, making the tool much more valuable under those circumstances.
Test Run
Ensuring your gateway and gateway scripts are still running, start the infuse bt_log tool again
(if not currently running).
Now use the following command to try to send some annotations to the device:
labels.json in the present working directory, or update the path in the command.infuse annotate_events --id 0x123456789ABCDEF --preset-labels labels.json --gatt
infuse annotate_events --id 0x123456789ABCDEF --preset-labels labels.json --onboard
infuse annotate_events --id 0x123456789ABCDEF --preset-labels labels.json --external
Once ready, select the annotation you want to send using the arrow keys and hit ↵ to send it.
An ANNOTATION TDF should appear in the infuse bt_log console and the corresponding .csv.
Exit option or enter c to close the tool.You're now all set to run an experiment.
.csv files before starting an actual experiment.
Re-running the logging script will not overwrite existing data, instead appending to it.Running an Experiment
It's now time to run the experiment.
Start Logging
Repeat the process before starting to log data with:
infuse bt_log --id 0x123456789ABCDEF --data --csv ~/csv_data
Coming Soon
Start the annotation Tool
And then running the annotation tool to get ready:
infuse annotate_events --id 0x123456789ABCDEF --preset-labels labels.json --gatt
infuse annotate_events --id 0x123456789ABCDEF --preset-labels labels.json --onboard
infuse annotate_events --id 0x123456789ABCDEF --preset-labels labels.json --external
Start labelling
Select a behaviour to perform e.g. "Double Tap" and send the start annotation Perform the behaviour repeatedly for a given duration
Stop labelling
When finished, send the corresponding end annotation.
Repeat
Repeat the process for the remaining labels. For the "Unknown" class, perform random or other motions unlike the other gestures (like dropping, rolling, shaking, etc).
Especially under different conditions such as holding the tag with a different orientation or other people performing the actions.
With this the data collection process is complete. This process can be repeated to increase and diversify the raw data we use to create the training dataset.
The next step is to take the raw data collected and turn it into a training dataset.