Updated documentation

This commit is contained in:
Luca Warmenhoven
2024-06-04 14:42:30 +02:00
parent c084443799
commit 3f560d9f47
4 changed files with 134 additions and 112 deletions

View File

@@ -1,108 +1,60 @@
## Motion Tracking System
## Motion Tracking System -- Pepper
---
To capture the user's motion with the sensing devices, we'll need to use a tracking system that calculates the
path the user makes to be able to determine the user's position and orientation, and therefore whether the movement
that was made correlates to the provided path.
This is done by some calculations in the `MotionProcessor` class. To get started, create an instance of the `MotionProcessor` class and call the `processMotion` method with the `MotionData` object as a parameter. This will return a `MotionResult` object that contains the calculated path.
### Introduction
The robot motion tracking system is a system that allows the robot to track the user's motion and provide feedback
based on the user's motion. The system consists of a Web Server, which actively listens for incoming data from the
two ESP8266 modules. The ESP8266 modules are connected to the robot and are responsible for tracking the user's motion.
These sensors send rotation data to the Web Server, which can then be parsed and used to provide feedback to the user.
### System Architecture
The system consists of three main components: the Web Server, the ESP8266 modules, and the Pepper robot. The Web Server
is responsible for receiving data from the ESP8266 modules and processing it. The ESP8266 modules are responsible for
sending rotation data to the web server, which is then parsed.
### Parsing Data
To parse the data received by the web server, one must utilize the class `InputProcessor`. This class is responsible for
both starting the server and processing data received by the server. To start parsing data, one can do the following:
```java
// create the motion processor
MotionProcessor motionProcessor = new MotionProcessor();
InputProcessor processor = new InputProcessor();
processor.startListening(); // This starts the web server.
```
To start listening for input, one must call the following method:
To parse data received by the server, one can register an event listener with the `InputProcessor` class. This event listener
will be called whenever new data is received by the server. To register an event listener, one can do the following:
```java
// start listening for input
motionProcessor.startListening();
processor.setInputHandler(new IInputHandler() {
@Override
public void accept(Vector3f rotationVector, int sensorId) {
// Do something with the input.
}
});
```
Calling this function creates a WebSocket server, which the sensing devices can connect to.
The `MotionProcessor` class will then start listening for a set of messages that start with specified kind of keywords.
The messages always start with the keyword, separated by a space, and then the data is sent.
The default data separator is `;`.
An example of the message format is shown below:
### Providing Feedback
If one wants to provide feedback to the user, one must first provide an exercise to the `InputProcessor` object.
This can be done by calling the `setExercise(Exercise exercise)` method. This method takes an `Exercise` object as a parameter.
This object contains information about the exercise, such as the name of the exercise, the muscle group it targets, and the
video associated with the exercise. One can then check the status of the current exercise by calling one of the following
methods:
```java
// Sending data
"data accelerationX;accelerationY;accelerationZ;rotationX;rotationY;rotationZ" // all values are floats
processor.getCurrentProgress(); // Returns the current progress of the exercise as a scalar (0 - 1)
// Changing the sample rate
"sampleRate rate" // rate is an integer
processor.getError(int sensorId, float time); // Get the error offset for a given sensor at a given time
// Calibrating the zero point
"zero x;y;z" // x, y, z are floats
```
processor.getAverageError(int sensorId); // Get the average error for a given sensor
To add a custom message received handler, one can simply call the following method:
processor.secondsPassed(); // Get the number of seconds that have passed since the exercise started
```java
// Add a custom message handler
motionProcessor.setMotionDataEventHandler((Vector3 vector) -> { ... });
```
*Note: The message handler provides a vector as a parameter; this vector is already converted from relative acceleration and rotation.*
processor.hasFinished(); // Check if the exercise has finished
### Error checking
To check whether the made movements correlate with a given path, one must check for their differences.
This can be done by a few implemented methods:
***Get the error of a vector compared to a path***
```java
GesturePath path = new GesturePath.Builder()
.addVector(...)
.build();
Vector3 referencePoint = new Vector3(...);
double error = motionProcessor.getError(path, referencePoint);
```
***Get the average error of a computed path to a `GesturePath`***
```java
GesturePath path = new GesturePath.Builder()
.addVector(...)
.build();
double error = motionProcessor.getAverageError(path);
```
***Get a list of error values from a computed path to a `GesturePath`***
```java
GesturePath path = new GesturePath.Builder()
.addVector(...)
.build();
List<Double> errorList = motionProcessor.getErrors(path);
```
### Example
An example of how to use a motion tracking system is shown below:
```java
// create the motion processor
MotionProcessor motionProcessor = new MotionProcessor();
// Create a gesture path
GesturePath.Builder pathBuilder = new GesturePath.Builder();
for ( int i = 0; i < 100; i++ )
pathBuilder.addVector(new Vector3(i, i, i));
GesturePath path = pathBuilder.build();
// Set the path
for ( int i = 0; i < 100; i++ ) {
motionProcessor.addMotionData(new MotionData(i, i, i, i, i, i));
}
// Get error values
List<Double> errorList = motionProcessor.getErrors(path);
// Get average error
double averageError = motionProcessor.getAverageError(path);
// Now you can do whatever you want with these results.
```