Skip to content
Snippets Groups Projects
Commit a48241da authored by Sean Radigan's avatar Sean Radigan Committed by Ricardo Ortiz
Browse files

Added basic shell for VRPN phantom,

did not test if it compiles on anything.
Fix VRPN external build for linux.
parent 94f47fc3
No related branches found
No related tags found
No related merge requests found
......@@ -37,14 +37,19 @@ if(NOT DEFINED ${proj}_DIR)
)
endif()
# Set VRPN Windows only options
set(CMAKE_WIN_EXTERNAL_PROJECT_ARGS)
if(WIN32)
list(APPEND CMAKE_WIN_EXTERNAL_PROJECT_ARGS
-DVRPN_USE_HDAPI:BOOL=ON
)
set(CMAKE_GENERAL_EXTERNAL_PROJECT_ARGS)
if(SimMedTK_USE_PHANTOM_OMNI)
simmedtk_find_package(OpenHaptics QUIET)
if(OPENHAPTICS_FOUND)
list(APPEND CMAKE_GENERAL_EXTERNAL_PROJECT_ARGS
-DVRPN_USE_PHANTOM_SERVER:BOOL=ON
-DOpenHaptics_DIR:PATH=${OpenHaptics_DIR}
-DVRPN_GPL_SERVER:BOOL=ON
)
endif(OPENHAPTICS_FOUND)
endif()
message(STATUS "CMAKE_GENERAL_EXTERNAL_PROJECT_ARGS=${CMAKE_GENERAL_EXTERNAL_PROJECT_ARGS}")
# message(STATUS "Adding project:${proj}")
ExternalProject_Add(${proj}
SOURCE_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj}
......@@ -62,9 +67,15 @@ if(NOT DEFINED ${proj}_DIR)
-DBUILD_SHARED_LIBS:BOOL=${SimMedTK_BUILD_SHARED_LIBS}
-DCMAKE_INCLUDE_PATH:STRING=${SimMedTK_CMAKE_INCLUDE_PATH}
-DCMAKE_LIBRARY_PATH:STRING=${SimMedTK_CMAKE_LIBRARY_PATH}
-DVRPN_USE_PHANTOM_SERVER:BOOL=ON
${CMAKE_WIN_EXTERNAL_PROJECT_ARGS}
-DVRPN_SUBPROJECT_BUILD:BOOL=ON
-DVRPN_USE_HDAPI:BOOL=ON
-DVRPN_USE_HID:BOOL=ON
-DVRPN_INSTALL:BOOL=OFF
-DVRPN_BUILD_PYTHON:BOOL=OFF
-DVRPN_USE_GPM_MOUSE:BOOL=OFF
-DVRPN_USE_LIBNIFALCON:BOOL=OFF
${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
${CMAKE_GENERAL_EXTERNAL_PROJECT_ARGS}
${OUTPUT_DIRECTORIES}
DEPENDS
${${proj}_DEPENDENCIES}
......
......@@ -17,7 +17,7 @@
#
###########################################################################
set(SimMedTK_DEPENDENCIES VegaFEM Assimp SFML Eigen GLEW ThreadPool VTK)
set(SimMedTK_DEPENDENCIES VegaFEM Assimp SFML Eigen GLEW ThreadPool VTK VRPN)
if(BUILD_TESTING)
list(APPEND SimMedTK_DEPENDENCIES Bandit)
endif()
......
......@@ -87,6 +87,7 @@ set(SimMedTK_VERSION "${SimMedTK_VERSION_MAJOR}.${SimMedTK_VERSION_MINOR}.${SimM
# Testing
#
option(BUILD_TESTING "Test the project" ON)
include(SimMedTKTesting)
#-----------------------------------------------------------------------------
# Documentation options
......
......@@ -21,8 +21,8 @@
// Contact:
//---------------------------------------------------------------------------
#ifndef SMINTERFACE_H
#define SMINTERFACE_H
#ifndef SM_DEVICE_H
#define SM_DEVICE_H
// SimMedTK includes
#include "Core/Config.h"
......
#include "VRPNPhantomDevice.h"
#include <vrpn_Connection.h>
#include <vrpn_Button.h>
#include <vrpn_ForceDevice.h>
#include <vrpn_Tracker.h>
#include <server_src/vrpn_Phantom.h>
#include <chrono>
#include <thread>
#include <memory>
#include <algorithm>
VRPNPhantomDevice::VRPNPhantomDevice()
: terminate{false},
deviceURL("Phantom0@localhost"),
delay(std::chrono::milliseconds(100))
{
}
VRPNPhantomDevice::~VRPNPhantomDevice()
{
}
Device::Message VRPNPhantomDevice::open()
{
vrpnButton = std::make_shared<vrpn_Button_Remote>(this->deviceURL);
vrpnForce = std::make_shared<vrpn_ForceDevice_Remote>(this->deviceURL);
vrpnTracker = std::make_shared<vrpn_Tracker_Remote>(this->deviceURL);
//need try/catch incase the memory couldn't be allocated, the return
// Message::Failure;
vrpnButton->register_change_handler( this, ButtonChangeHandler );
vrpnForce->register_force_change_handler( this, ForceChangeHandler );
vrpnTracker->register_change_handler( this, TrackerChangeHandler );
return Device::Message::Success;
}
Device::Message VRPNPhantomDevice::close()
{
terminate = true;
return Device::Message::Success;
}
void VRPNPhantomDevice::exec()
{
while(!terminate)
{
processChanges();
std::this_thread::sleep_for(delay);
}
}
void VRPNPhantomDevice::setDeviceURL(const string s)
{
deviceURL = s;
}
const std::string VRPNPhantomDevice::getDeviceURL()
{
return deviceURL;
}
void VRPNPhantomDevice::setPollDelay(const std::chrono::duration d)
{
delay = d;
}
const std::chrono::duration VRPNPhantomDevice::getPollDelay()
{
return delay;
}
void VRPNPhantomDevice::processChanges()
{
vrpnButton->mainloop();
vrpnForce->mainloop();
vrpnTracker->mainloop();
}
void VRPN_CALLBACK
VRPNPhantomDevice::buttonChangeHandler(void *userData, const vrpn_BUTTONCB b)
{
VRPNPhantomDevice *handler = reinterpret_cast<VRPNPhantomDevice*>(userData);
if (b.button < handler->buttons.size())
{
buttons[b.button] = (1 == b.state);
//Should also handle time stamps
}//else the button isn't accounted for, as far as we know, it didn't exist
}
void VRPN_CALLBACK
VRPNPhantomDevice::forceChangeHandler(void *userData, const vrpn_FORCECB f)
{
VRPNPhantomDevice *handler = reinterpret_cast<VRPNPhantomDevice*>(userData);
std::copy(std::begin(f.force), std::end(f.force), std::begin(handler->force));
//Should also handle time stamps
}
void VRPN_CALLBACK
VRPNPhantomDevice::trackerChangeHandler(void *userData, const vrpn_TRACKERCB t)
{
VRPNPhantomDevice *handler = reinterpret_cast<VRPNPhantomDevice*>(userData);
std::copy(std::begin(t.pos), std::end(t.pos), std::begin(handler->pos));
std::copy(std::begin(t.quat), std::end(t.quat), std::begin(handler->quat));
//Should also handle time stamps
}
VRPNPhantomDeviceServer::VRPNPhantomDeviceServer()
: terminate{false},
deviceName("Phantom0"),
delay(std::chrono::milliseconds(100))
{
}
VRPNPhantomDeviceServer::~VRPNPhantomDeviceServer()
{
delete connection;
}
Device::Message VRPNPhantomDeviceServer::open()
{
connection = vrpn_create_server_connection();
phantom = std::make_shared<vrpn_Phantom>(deviceName, connection, 60.0f);
//need try/catch incase the memory couldn't be allocated, the return
// Message::Failure;
return Device::Message::Success;
}
Device::Message VRPNPhantomDeviceServer::close()
{
terminate = true;
return Device::Message::Success;
}
void VRPNPhantomDeviceServer::exec()
{
while(!terminate)
{
phantom->mainloop();
connection->mainloop();
std::this_thread::sleep_for(delay);
}
}
void VRPNPhantomDeviceServer::setDeviceName(const string s)
{
deviceName = s;
}
const std::string VRPNPhantomDeviceServer::getDeviceName()
{
return deviceName;
}
void VRPNPhantomDeviceServer::setPollDelay(const std::chrono::duration d)
{
delay = d;
}
const std::chrono::duration VRPNPhantomDeviceServer::getPollDelay()
{
return delay;
}
// This file is part of the SimMedTK project.
// Copyright (c) Center for Modeling, Simulation, and Imaging in Medicine,
// Rensselaer Polytechnic Institute
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//---------------------------------------------------------------------------
//
// Authors:
//
// Contact:
//---------------------------------------------------------------------------
#ifndef SM_VRPNPHANTOMDEVICE_H
#define SM_VRPNPHANTOMDEVICE_H
#include "Device.h"
#include <vrpn_Connection.h>
#include <vrpn_Button.h>
#include <vrpn_ForceDevice.h>
#include <vrpn_Tracker.h>
#include <server_src/vrpn_Phantom.h>
#include <string>
#include <memory>
#include <chrono>
#include <array>
class VRPNPhantomDevice : Device
{
public:
VRPNPhantomDevice();
virtual ~VRPNPhantomDevice();
Device::Message open() override;
Device::Message close() override;
void exec() override;
void setDeviceURL(const string s);
const std::string getDeviceURL();
void setPollDelay(const std::chrono::duration d);
const std::chrono::duration getPollDelay();
private:
bool terminate;
std::string deviceURL;
std::chrono::duration delay;
//Need getters and setters for these
std::array<bool, 2> buttons; //< Buttons: true = pressed/false = not pressed
std::array<vprn_float64, 3> force; //this should really be a vec3 or something
std::array<vprn_float64, 3> pos; //this should really be a vec3 or something
std::array<vprn_float64, 4> quat; //this should really be a quat or something
std::shared_ptr<vrpn_Button_Remote> vrpnButton;
std::shared_ptr<vrpn_ForceDevice_Remote> vrpnForce;
std::shared_ptr<vrpn_Tracker_Remote> vrpnTracker;
void processChanges();
void VRPN_CALLBACK buttonChangeHandler(void *userData, const vrpn_BUTTONCB b);
void VRPN_CALLBACK forceChangeHandler(void *userData, const vrpn_FORCECB f);
void VRPN_CALLBACK trackerChangeHandler(void *userData, const vrpn_TRACKERCB b);
};
class VRPNPhantomDeviceServer : Device
{
public:
VRPNPhantomDeviceServer();
virtual ~VRPNPhantomDeviceServer();
Device::Message open() override;
Device::Message close() override;
void exec() override;
void setDeviceName(const string s);
const std::string getDeviceName();
void setPollDelay(const std::chrono::duration d);
const std::chrono::duration getPollDelay();
private:
bool terminate;
std::string deviceName;
std::chrono::duration delay;
vrpn_Connection connection;
std::shared_ptr<vrpn_Phantom> phantom;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment