Download

Home made VR controller big serial lagg just in Unreal Engine

Hi Guys,

yould you please help me out a bit with some advices. I have a “home made” VR controller, that communicates trough serial (USB CDC). I receive in Unreal Engine the coordinates and position, but from two slaves. (COM1 =orientation; COM2= pos).
I have the problem that there is a big lagg in communication I think. In other frameworks I have no problem, just in Unreal Engine. I use 4.9.2. I am going to build up from 0 in 4.12.5. After packaging is even worse.
You can see it the best when I move my finger. there is a really big delay.

To see what is it about: HURO6D - YouTube

Can it be because I read data just every thick? What should I post You here?

Thanks

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “GameFramework/Actor.h”
#include “MyActor_withserial.generated.h”

UCLASS()
class GLOVE_BASIC_V1_0_API AMyActor_withserial : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
AMyActor_withserial();

// Called when the game starts or when spawned
virtual void BeginPlay() override;

// Called every frame
virtual void Tick( float DeltaSeconds ) override;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
	float Serialphi = 0.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
	float Serialpsi = 0.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
	float Serialteta = 0.0f;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
	float mutatophi = 0.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
	float mutatopsi = 0.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
	float mutatoteta = 0.0f;

};


#include “Glove_Basic_V1_0.h”
#include “MyActor_withserial.h”
#include <stdio.h>
#include <tchar.h>
#include “SerialClass.h” // Library described above
#include <string>

Serial* SP;
//Serial* HuroBAT;

int dataLength = 32;
int readResult = 0;
int index;
char incomingData[33] = “”; // don’t forget to pre-allocate memory
bool FirstTime = true;
unsigned char readedbytes[80];
long d;
float Kesztyu_Nyito, phi, psi, teta, phi2, psi2, teta2, Kesztyu_Zaro, HuroBat_Kezdo, KezPosX_temp, KezPosY_temp, KezPosZ_temp, HuroBat_Zaro;
float xmin, xmax, ymin, ymax, zmin, zmax, xmin2, xmax2, ymin2, ymax2, zmin2, zmax2;

// Gyuri Szűrő--------------------
float m = 0.1;
double v, v_valos; //Sebesség
double e; //Szűrési hányados, 0-1 között kell legyen, minél kisebb annál erősebb a korrekció
float KezPosX0, KezPosY0, KezPosZ0; //Előző értékek tárolására alkalmas változók
float KezPosX0valos, KezPosY0valos, KezPosZ0valos; //Előző valos értékek tárolására alkalmas változók
//---------------------------------

// Sets default values
AMyActor_withserial::AMyActor_withserial()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AMyActor_withserial::BeginPlay()
{
Super::BeginPlay();

// application reads from the specified serial port and reports the collected data
int _tmain(int argc, _TCHAR* argv]);
{
	//printf("Welcome to the serial test app!

");

	SP = new Serial("\\\\.\\COM6");    // adjust as needed
	//		HuroBAT = new Serial("\\\\.\\COM4");	//HuroBAT Serial

}

}

// Called every frame
void AMyActor_withserial::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );

memset(incomingData, 0, dataLength);
memset(readedbytes, 0, dataLength);

if (SP-&gt;IsConnected()) {
	if (FirstTime){
		GEngine-&gt;AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("we are connected ")));
		FirstTime = false;
	}


	readResult = SP-&gt;ReadData(incomingData, 32);

	memcpy(readedbytes, incomingData, 32);

	index = 0;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	Kesztyu_Nyito = *(float *)&d;

	index = 4;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	phi = *(float *)&d;
	index = 8;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	teta = *(float *)&d;
	index = 12;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	psi = *(float *)&d;

	index = 16;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	phi2 = *(float *)&d;
	index = 20;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	teta2 = *(float *)&d;
	index = 24;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	psi2 = *(float *)&d;
	index = 28;
	d = (readedbytes[index + 3] &lt;&lt; 24) | (readedbytes[index + 2] &lt;&lt; 16) | (readedbytes[index + 1] &lt;&lt; 8) | (readedbytes[index]);
	Kesztyu_Zaro = *(float *)&d;

}
else
{
	GEngine-&gt;AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("NOT connected to Glove ")));
}

/*
KezPosX = 0;
KezPosY = 0;
KezPosZ = 0;
*/

if (Kesztyu_Nyito == 90 && Kesztyu_Zaro == 165){

	Serialphi = phi;
	Serialteta = teta;
	Serialpsi = psi;

	mutato2phi = phi2;
	mutato2teta = teta2;
	mutato2psi = psi2;
}


memset(incomingData, 0, 20);
memset(readedbytes, 0, 20);


SP-&gt;Serialflush();

}

openframeworks: https://www.youtube.com/watch?v=1wK1oi0gPrk

unreal engine: https://www.youtube.com/watch?v=jmzuaB0qAX4&feature=youtu.be