-
Notifications
You must be signed in to change notification settings - Fork 7
Manipulating Data
Manipulating data can be important as sensor data might not come the way you want to present it to the user. Therefore, the DataModification class was created with an adjustSensorData(Sensor sensor) method that returns a new Sensor containing modified data. To ensure that no data gets lost, the sensor object gets copied before manipulating it using the Sensor copy constructor.
Sensor adjusted = new Sensor(sensor);Modifying data can be really experiment specific, as shown by this example where the incoming temperature data needed to be devided by 10 in the MIRKA2-ICV experiment.
//MIRKA2-ICV: Thermocouple values are multiplied by 10 and saved as UINT
//to save bandwith
if (sensor.getSensorName().contains("Thermocouple")) {
for (Var var : adjusted.getVars()) {
//change datatype to new value
var.setDataType(DataType.FLOAT32);
for (Long key : var.getValues().keySet()) {
//devide the current value by 10 and replace the old one
var.getValues().replace(key, (double) (((int) var.getValues().get(key)) / 10));
}
}
}Other examples such as the conversion from quaternions to euler angles shown below can be used for multiple exeriments.
if (sensor.getSensorName().contains("IMU")) {
//for the IMU conversion it is necessary to generate new variables
adjusted.setVariables(new ArrayList<Var>());
//create yaw, pitch and roll variables
Var yaw = new Var();
Var pitch = new Var();
Var roll = new Var();
yaw.setDataName("Yaw");
yaw.setUnit("[deg]");
yaw.setDataType(DataType.FLOAT32);
pitch.setDataName("Pitch");
pitch.setUnit("[deg]");
pitch.setDataType(DataType.FLOAT32);
roll.setDataName("Roll");
roll.setUnit("[deg]");
roll.setDataType(DataType.FLOAT32);
//for every timestep create euler angles from quaternions
for (Long key : sensor.getVars().get(0).getValues().keySet()) {
//get w,x,y and z variables for the specified time step
double w = 0, x = 0, y = 0, z = 0;
for (Var var : sensor.getVars()) {
if (var.getDataName().contains("W")) {
w = new Double((int) var.getValues().get(key));
} else if (var.getDataName().contains("X")) {
x = new Double((int) var.getValues().get(key));
} else if (var.getDataName().contains("Y")) {
y = new Double((int) var.getValues().get(key));
} else if (var.getDataName().contains("Z")) {
z = new Double((int) var.getValues().get(key));
}
}
//normalize the values
double abs = Math.sqrt((Math.pow(x, 2)+Math.pow(y, 2)+Math.pow(z, 2)+Math.pow(w, 2)));
x = x/abs;
y = y/abs;
z = z/abs;
w = w/abs;
//compute and add values
yaw.addValue(key, (180/Math.PI)*Math.atan2((2 * x * y + 2 * z * w),
(Math.pow(w, 2) + Math.pow(x, 2) - Math.pow(y, 2) - Math.pow(z, 2))));
pitch.addValue(key, (180/Math.PI)*Math.asin((2 * y * w - 2 * z * x)));
roll.addValue(key, (180/Math.PI)*Math.atan2((2 * z * y + 2 * x * w),
(Math.pow(w, 2) - Math.pow(x, 2) - Math.pow(y, 2) + Math.pow(z, 2))));
}
//add variables to the adjusted sensor
adjusted.addVariable(yaw);
adjusted.addVariable(pitch);
adjusted.addVariable(roll);
}If a new sensor adjustment is to be implemented, the first thing to do is to define an if statement in the adjustSensorData method to ensure that only the specified sensor data is affected.
if (sensor.getSensorName().contains("IMU")) {Then the variables and other fields of the adjusted Sensor object can be manipulated.