Skip to content

Commit

Permalink
reworked the way tracker information is stored to get rid of all the …
Browse files Browse the repository at this point in the history
…ignore tracker 0 jank in code
  • Loading branch information
ju1ce committed Aug 6, 2021
1 parent 6272843 commit 4f5c67b
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 167 deletions.
49 changes: 34 additions & 15 deletions AprilTagTrackers/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ void Connection::StartConnection()

void Connection::Connect()
{
//generate vector of tracker connection struct, connecting board ids to apropriate driver ids. In future, this should be done manualy in the gui
connectedTrackers.clear();

if (parameters->ignoreTracker0)
{
for (int i = 0; i < parameters->trackerNum - 1; i++)
{
TrackerConnection temp;
temp.TrackerId = i + 1;
temp.DriverId = i;
temp.Name = "ApriltagTracker" + std::to_string(i + 1);
connectedTrackers.push_back(temp);
}
connectedTrackers[0].Role = "TrackerRole_LeftFoot";
connectedTrackers[1].Role = "TrackerRole_RightFoot";
}
else
{
for (int i = 0; i < parameters->trackerNum; i++)
{
TrackerConnection temp;
temp.TrackerId = i;
temp.DriverId = i;
temp.Name = "ApriltagTracker" + std::to_string(i);
connectedTrackers.push_back(temp);
}
connectedTrackers[0].Role = "TrackerRole_Waist";
connectedTrackers[1].Role = "TrackerRole_LeftFoot";
connectedTrackers[2].Role = "TrackerRole_RightFoot";
}

//connect to steamvr as a client in order to get buttons.
vr::EVRInitError error;
openvr_handle = VR_Init(&error, vr::VRApplication_Overlay);
Expand All @@ -54,15 +85,6 @@ void Connection::Connect()

vr::VRInput()->GetActionSetHandle("/actions/demo", &m_actionsetDemo);

//function to create pipes for SteamVR connection
pipeNum = parameters->trackerNum;

double trackerNum = parameters->trackerNum;
if (parameters->ignoreTracker0)
{
trackerNum--;
}

std::istringstream ret;
std::string word;

Expand All @@ -78,9 +100,9 @@ void Connection::Connect()
}
int connected_trackers;
ret >> connected_trackers;
for (int i = connected_trackers; i < trackerNum; i++)
for (int i = connected_trackers; i < connectedTrackers.size(); i++)
{
ret = Send("addtracker");
ret = Send("addtracker " + connectedTrackers[i].Name + " " + connectedTrackers[i].Role);
ret >> word;
if (word != "added")
{
Expand All @@ -93,7 +115,7 @@ void Connection::Connect()
}
ret = Send("addstation");

ret = Send("settings " + std::to_string(parameters->smoothingFactor) + " 2");
ret = Send("settings 50 0.5"); //TODO: set the parameters correctly. I is lazy

//set that connection is established
status = CONNECTED;
Expand Down Expand Up @@ -138,9 +160,6 @@ std::istringstream Connection::Send(std::string lpszWrite)

std::istringstream Connection::SendTracker(int id, double a, double b, double c, double qw, double qx, double qy, double qz, double time, double smoothing)
{
if (parameters->ignoreTracker0) {
id--;
}

std::string s;
s = " updatepose " + std::to_string(id) +
Expand Down
8 changes: 8 additions & 0 deletions AprilTagTrackers/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#include <windows.h>
#include <openvr.h>

struct TrackerConnection {
int TrackerId;
int DriverId;
std::string Name;
std::string Role;
};

class Connection
{
public:
Expand All @@ -24,6 +31,7 @@ class Connection
int GetButtonStates();
int status = DISCONNECTED;
vr::IVRSystem* openvr_handle;
std::vector<TrackerConnection> connectedTrackers;
private:
void Connect();
HANDLE hpipe;
Expand Down
Loading

0 comments on commit 4f5c67b

Please sign in to comment.