Commit c08b0432 authored by Patric Schmitz's avatar Patric Schmitz

final experiment version of GearVRApp

parent 938d200c
......@@ -73,6 +73,7 @@ void DataCaptureManager::appendKinematic(UserKinematic& kinematic, std::string&
to.append(fieldSeparator);
to.append(getMatlabString(kinematic.getVirtualHeadTransform()));
to.append(fieldSeparator);
}
void DataCaptureManager::LogTrackingFrameSkip(int numFrames) {
......@@ -112,8 +113,6 @@ void DataCaptureManager::LogReset(UserKinematic &kinematic) {
string result = LineTypes::reset + fieldSeparator +
to_string(currentTimestamp()) + fieldSeparator;
result.append(to_string(kinematic.getRotationGain()));
result.append(fieldSeparator);
appendKinematic(kinematic, result);
result.append(lineSeparator);
......@@ -123,6 +122,20 @@ void DataCaptureManager::LogReset(UserKinematic &kinematic) {
}
}
void DataCaptureManager::LogUserReset(float gain) {
if (!capturing) return;
string result = LineTypes::user_reset + fieldSeparator +
to_string(currentTimestamp()) + fieldSeparator;
result.append(to_string(gain));
result.append(lineSeparator);
fputs(result.c_str(), saveDataFile);
if (flushStreamAfterEachEntry) {
fflush(saveDataFile);
}
}
void DataCaptureManager::AddUserKinematicData(
unsigned long frameNumber,
UserKinematic &data, glm::mat4 const (&torsos)[2],
......@@ -213,9 +226,8 @@ double DataCaptureManager::currentTimestamp() {
return std::chrono::duration<double>(delta).count();
}
const char* DataCaptureManager::LineTypes::kinematic = "KINEMATIC";
const char* DataCaptureManager::LineTypes::reset = "USER_RESET";
const char* DataCaptureManager::LineTypes::reset = "RESET";
const char* DataCaptureManager::LineTypes::user_reset = "USER_RESET";
const char* DataCaptureManager::LineTypes::tracking_loss = "TRACKING_LOSS";
const char* DataCaptureManager::LineTypes::target = "TARGET_COLLECTED";
\ No newline at end of file
......@@ -34,6 +34,7 @@ public:
UserKinematic &kinematicData, glm::mat4 const (&torsos)[2],
float realRotation, float virtualRotation, float distance);
void LogReset(UserKinematic &kinematic);
void LogUserReset(float gain);
void LogTrackingFrameSkip(int numFrames);
void LogTrialStarted(UserKinematic &kinematic);
void LogTargetCollected(UserKinematic &kinematic, glm::vec2 targetPos);
......@@ -48,6 +49,7 @@ private:
struct LineTypes {
static const char* kinematic;
static const char* reset;
static const char* user_reset;
static const char* tracking_loss;
static const char* target;
};
......
......@@ -25,7 +25,7 @@ namespace {
const glm::vec3 startPosition =
(targetAreaStart + targetAreaEnd) / 2.f;
const float targetRadius = .8f;
const float targetRadius = 0.8f;
const float targetActiveRadius = 0.15f;
const float targetPercentActiveMin = 0.9f;
......@@ -40,10 +40,12 @@ namespace {
}
AcousticThresholdExperiment::AcousticThresholdExperiment(
UserKinematic & kinematic) :
UserKinematic & kinematic,
DataCaptureManager& dataCapture) :
trialRunning(false),
kinematic(kinematic),
toAcousticSender("herzog", 4200),
dataCapture(dataCapture),
// toAcousticSender("coudenhove", 4200),
controlReceiver(4201)
{
const float targetGridOffset = 6.f / (targetGridSize);
......@@ -75,19 +77,24 @@ void AcousticThresholdExperiment::Load(ModelRenderer *modelRenderer) {
targetStart->setPosition(startPosition);
targetStart->setVisible(true);
targetStart->setPercent(1.f);
targetStartActive = false;
}
void AcousticThresholdExperiment::frame() {
glm::vec3 headOnGround = kinematic.getVirtualHeadPosition();
headOnGround.y = 0;
if(!trialRunning) {
if(glm::distance(headOnGround, startPosition) < targetActiveRadius) {
startTrial();
if(targetStartActive)
{
if(!trialRunning) {
if(glm::distance(headOnGround, startPosition) < targetActiveRadius) {
startTrial();
}
}
else {
frameTrial();
}
}
else {
frameTrial();
}
}
......@@ -99,8 +106,10 @@ void AcousticThresholdExperiment::reset() {
targetStart->setVisible(true);
kinematic.setRotationGain(defaultRotationGain);
gainIncrement = (gainIncreasing ? -1.f : 1.f) *
gainIncrement = (gainIncreasing ? 1.f : -1.f) *
gainIncrementMagnitude;
LogError("-------- RESET --------------------------");
LogError("gain: " + to_string(kinematic.getRotationGain()));
LogError("gainIncrement: " + to_string(gainIncrement));
sendAcousticTransform();
......@@ -124,7 +133,7 @@ void AcousticThresholdExperiment::frameTrial() {
if(glm::distance(headOnGround,
targets[0]->getPosition()) < targetActiveRadius) {
if (dataCapture) dataCapture->LogTargetCollected(kinematic, targets[0]->getPosition());
dataCapture.LogTargetCollected(kinematic, targets[0]->getPosition());
placeTargets();
......@@ -224,12 +233,12 @@ void AcousticThresholdExperiment::randomizeTargets() {
void AcousticThresholdExperiment::sendAcousticTransform() {
// send gain
float gain = kinematic.getRotationGain();
write(toAcousticSender.fd, &gain, sizeof(float));
// write(toAcousticSender.fd, &gain, sizeof(float));
// send virtual head transform
write(toAcousticSender.fd,
glm::value_ptr(kinematic.getVirtualHeadTransform()),
16*sizeof(float));
// // send virtual head transform
// write(toAcousticSender.fd,
// glm::value_ptr(kinematic.getVirtualHeadTransform()),
// 16*sizeof(float));
}
static bool stop_control_server = false;
......@@ -242,28 +251,41 @@ void AcousticThresholdExperiment::setupControlServer() {
for (;;) {
std::fill(begin(buffer), end(buffer), char(0));
auto bytes_received = read(socket, buffer.data(), sizeof(buffer) - 1);
if (bytes_received >= 2) {
bool gain_up = (buffer[0] == '1');
bool radio_shown = (buffer[1] == '1');
float gain = float(strtod(buffer.data() + 3, nullptr));
if (gain != 0.f)
if (bytes_received >= 2) {
if(buffer[0] == 'r')
{
defaultRotationGain = gain;
float gain = float(strtod(buffer.data() + 2, nullptr));
dataCapture.LogUserReset(gain);
LogError("User reset: " + to_string(gain));
}
else if(buffer[0] == 's')
{
targetStartActive = true;
} else
{
bool gain_up = (buffer[0] == '1');
bool radio_shown = (buffer[1] == '1');
float gain = float(strtod(buffer.data() + 3, nullptr));
if (gain != 0.f)
{
defaultRotationGain = gain;
}
gainIncreasing = gain_up;
gainIncrement = (gainIncreasing ? 1.f : -1.f) *
gainIncrementMagnitude;
if (radioModel) radioModel->setVisible(radio_shown);
LogError("AcousticThresholdExperiment: received update");
LogError("gainIncrement: " + to_string(gainIncrement));
LogError("radio visible: " + to_string(radio_shown));
}
Log("AcousticThresholdExperiment: received update");
gainIncreasing = gain_up;
gainIncrement = (gainIncreasing ? -1.f : 1.f) *
gainIncrementMagnitude;
if (radioModel) radioModel->setVisible(radio_shown);
} else {
close(socket);
//close(socket);
break;
}
}
}
}).detach();
}
......@@ -22,7 +22,8 @@ class UserKinematic;
class AcousticThresholdExperiment {
public:
AcousticThresholdExperiment(UserKinematic & kinematic);
AcousticThresholdExperiment(UserKinematic & kinematic,
DataCaptureManager& dataCapture);
void Load(ModelRenderer *modelRenderer);
......@@ -54,14 +55,16 @@ private:
UserKinematic & kinematic;
RDWTargetStrategy::TargetSet targetSet;
TcpSender toAcousticSender;
bool targetStartActive = false;
// TcpSender toAcousticSender;
TcpReceiver controlReceiver;
bool gainIncreasing = false;
float defaultRotationGain = 1.f;
Model* radioModel = nullptr;
DataCaptureManager* dataCapture = nullptr;
DataCaptureManager& dataCapture;
};
#endif //GEARVRAPP_ACOUSTICTHRESHOLDEXPERIMENT_H
......@@ -29,12 +29,31 @@ void RDWDonutTargetStrategy::step() {
RDWAgent agentSim(agent);
agentSim.setVerbose(false);
agentSim.setErrorRadius(0);
agentSim.turnTo(targets.targets[target]);
agentSim.turnTo(targets.targets[target], RDWAgent::shortTurn);
agentSim.walkTo(targets.targets[target]);
RDWAgent agentSimLong(agent);
agentSimLong.turnTo(targets.targets[target], RDWAgent::longTurn);
agentSimLong.walkTo(targets.targets[target]);
auto plateauUtilFunc = [&](glm::vec2 pos, float rad) {
return fmax(glm::length(pos) - rad, 0);
};
float utilDonut = plateauUtilFunc(agentSim.getRealPosition(), radius);
float utilDonutLong = plateauUtilFunc(agentSimLong.getRealPosition(), radius);
float utilDonutEffective = fmax(utilDonut, utilDonutLong);
float utilVirtCenter =
plateauUtilFunc(agentSim.getVirtualPosition(), 2.f);
float utilVirtDistance =
glm::clamp(
1.f - glm::length(agent.getVirtualPosition() -
agentSim.getVirtualPosition()),
0.0f, 1.0f);
float util =
fabs(glm::length(agentSim.getRealPosition()) - radius); //-
// targets.targets[target].getDistanceFrom(agentSim.getRealPosition());
utilDonutEffective + 0.4 * utilVirtCenter + 1.5f * utilVirtDistance;
if(util < utilMin) {
utilMin = util;
indexMin = target;
......
......@@ -24,3 +24,8 @@ TcpReceiver::TcpReceiver(uint16_t port) {
listen(mSocket, 1);
}
TcpReceiver::~TcpReceiver()
{
close(mSocket);
}
......@@ -8,7 +8,7 @@
class TcpReceiver {
public:
TcpReceiver(uint16_t port);
~TcpReceiver();
int mSocket;
sockaddr_in mAddress = {};
};
......@@ -58,3 +58,8 @@ void
UserKinematic::setAngularVelocityHead(glm::vec3 velocity) {
angularVelocityHead = velocity;
}
glm::mat4
UserKinematic::getRealTorsoTransform(int i) {
return realTorsoTransform[i];
}
\ No newline at end of file
......@@ -26,6 +26,8 @@ public:
glm::vec3 getAngularVelocityHead();
void setAngularVelocityHead(glm::vec3 velocity);
glm::mat4 getRealTorsoTransform(int i);
private:
float translationGain = 1.f;
float rotationGain = 1.f;
......@@ -34,7 +36,7 @@ private:
glm::vec3 angularVelocityHead;
glm::mat4 realHeadTransform;
glm::mat4 realTorsoTransform;
glm::mat4 realTorsoTransform[2];
glm::mat4 virtualHeadTransform;
};
......
......@@ -51,7 +51,7 @@ namespace {
}
TestScene::TestScene() :
experiment(userKinematic)
experiment(userKinematic, dataCapture)
// splatRenderer("output.vr")
{
}
......@@ -74,8 +74,8 @@ void TestScene::Load()
loadModels();
viewerToBlender.Connect("herzog", 1337);
viewerToOpenAL.Connect("moneta", 1337);
// viewerToBlender.Connect("coudenhove", 1338);
viewerToOpenAL.Connect("coudenhove", 1338);
}
void TestScene::loadModels()
......@@ -175,7 +175,7 @@ void TestScene::loadModels()
* glm::rotate(-1.8f, glm::vec3{0,1,0}));
experiment.setRadioModel(radio);
dataCaptureManager.Start(App);
dataCapture.Start(App);
}
void TestScene::Update(double frameTime)
......@@ -189,7 +189,7 @@ void TestScene::Update(double frameTime)
totalRealRotation = 0.f;
totalVirtualRotation = 0.f;
totalWalkedDistance = 0.f;
dataCaptureManager.LogReset(userKinematic);
dataCapture.LogReset(userKinematic);
resetToGlobalTrackerPosition(vrapiRenderInterface);
......@@ -212,14 +212,14 @@ void TestScene::Update(double frameTime)
// testTransform[3][1] = currentTrackingPosition[1];
// testTransform[3][2] = currentTrackingPosition[2];
// glm::mat4 rotX90 = glm::axisAngleMatrix(glm::vec3(1, 0, 0),
// glm::radians(90.0f));
// viewerToBlender.UpdateViewer(
// rotX90 * testTransform,
// frameTime);
// viewerToOpenAL.UpdateViewer(
// testTransform,
// frameTime);
glm::mat4 rotX90 = glm::axisAngleMatrix(glm::vec3(1, 0, 0),
glm::radians(90.0f));
// viewerToBlender.UpdateViewer(
// rotX90 * userKinematic.getVirtualHeadTransform(),
// frameTime);
viewerToOpenAL.UpdateViewer(
userKinematic.getVirtualHeadTransform(),
frameTime);
Scene::Update(frameTime);
......@@ -347,9 +347,9 @@ void TestScene::Draw(double frameTime, GraphicsContext *context, int eyeIndex)
// Use real movement for the boundary view matrix.
auto realPos = userKinematic.getRealHeadPosition();
boundaryRenderer.Render(realPos, glm::vec3(1, 1, 0),
realViewMatrix, camera.ProjectionMatrix,
2.1f, -5.6f, 3.9f, 3.5f);
// boundaryRenderer.Render(realPos, glm::vec3(1, 1, 0),
// realViewMatrix, camera.ProjectionMatrix,
// 2.1f, -5.6f, 3.9f, 3.5f);
#if VRAPI
currentFrame++;
......@@ -391,7 +391,7 @@ void TestScene::ReceivePackage(JNIEnv *env, void *buffer, int length)
body.loc[0] / 1000.0f - sceneOffsetOrigin.x;
// correct for 43mm tracking 0 offset
currentTrackingPosition.y =
(body.loc[1] - 43) / 1000.0f - sceneOffsetOrigin.y;
(body.loc[1] + 43) / 1000.0f - sceneOffsetOrigin.y;
currentTrackingPosition.z =
body.loc[2] / 1000.0f - sceneOffsetOrigin.z;
......@@ -417,11 +417,11 @@ void TestScene::ReceivePackage(JNIEnv *env, void *buffer, int length)
}
}
dataCaptureManager.AddUserKinematicData(frameNr, userKinematic, torsoTransforms,
dataCapture.AddUserKinematicData(frameNr, userKinematic, torsoTransforms,
totalRealRotation, totalVirtualRotation, totalWalkedDistance);
if (lastFrameNr + 1 != frameNr)
{
dataCaptureManager.LogTrackingFrameSkip(frameNr - lastFrameNr - 1);
dataCapture.LogTrackingFrameSkip(frameNr - lastFrameNr - 1);
}
#if SEND_MISSED_FRAMES
......
......@@ -83,12 +83,11 @@ private:
UserKinematic userKinematic;
DataCaptureManager dataCapture;
AcousticThresholdExperiment experiment;
ViewerUDPStreamer viewerToBlender;
// ViewerUDPStreamer viewerToBlender;
ViewerUDPStreamer viewerToOpenAL;
DataCaptureManager dataCaptureManager;
};
#endif //GEARVRAPP_TESTSCENE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment