NimbleScaffold.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// 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.
#ifndef SURGSIM_DEVICES_NIMBLE_NIMBLESCAFFOLD_H
#define SURGSIM_DEVICES_NIMBLE_NIMBLESCAFFOLD_H
#include <memory>
#include "SurgSim/DataStructures/DataGroup.h"
#include "SurgSim/Framework/BasicThread.h"
#include "SurgSim/Framework/Logger.h"
namespace SurgSim
{
namespace Devices
{
class NimbleDevice;
class NimbleThread;
class NimbleScaffold : public SurgSim::Framework::BasicThread
{
public:
~NimbleScaffold();
static std::shared_ptr<NimbleScaffold> getOrCreateSharedInstance();
protected:
bool doInitialize() override;
bool doStartUp() override;
bool doUpdate(double dt) override;
void doBeforeStop() override;
private:
struct StateData;
friend class NimbleDevice;
friend class NimbleThread;
NimbleScaffold();
bool registerDevice(NimbleDevice* device);
bool unregisterDevice(const NimbleDevice* device);
void updateDeviceData();
void resetDeviceData();
static SurgSim::DataStructures::DataGroup buildDeviceInputData();
std::shared_ptr<SurgSim::Framework::Logger> m_logger;
std::unique_ptr<StateData> m_state;
std::string m_serverIpAddress;
std::string m_serverPort;
bool m_serverSocketOpen;
static std::array<std::pair<std::string, int>, 15> m_jointPoseNames;
};
}; // namespace Devices
}; // namespace SurgSim
#endif // SURGSIM_DEVICES_NIMBLE_NIMBLESCAFFOLD_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Devices::NimbleScaffold::NimbleThread
friend class NimbleThread
Definition: NimbleScaffold.h:58
SurgSim::Devices::NimbleScaffold::NimbleScaffold
NimbleScaffold()
Constructor.
Definition: NimbleScaffold.cpp:279
DataGroup.h
SurgSim::Devices::NimbleScaffold
A class that manages Nimble devices.
Definition: NimbleScaffold.h:36
SurgSim::Devices::NimbleScaffold::m_state
std::unique_ptr< StateData > m_state
Internal scaffold state.
Definition: NimbleScaffold.h:86
SurgSim::Devices::NimbleScaffold::doBeforeStop
void doBeforeStop() override
Prepares the thread for its execution to be stopped.
Definition: NimbleScaffold.cpp:427
SurgSim::Devices::NimbleScaffold::doInitialize
bool doInitialize() override
Definition: NimbleScaffold.cpp:367
SurgSim::Devices::NimbleDevice
A class implementing the communication with the Nimble server.
Definition: NimbleDevice.h:57
SurgSim::Devices::NimbleScaffold::m_jointPoseNames
static std::array< std::pair< std::string, int >, 15 > m_jointPoseNames
The data group name for the joint poses, and the corresponding indices within the state data...
Definition: NimbleScaffold.h:96
SurgSim::Devices::NimbleScaffold::buildDeviceInputData
static SurgSim::DataStructures::DataGroup buildDeviceInputData()
Builds the data layout for the application input (i.e. device output).
Definition: NimbleScaffold.cpp:471
SurgSim::Devices::NimbleScaffold::resetDeviceData
void resetDeviceData()
Reset the device data.
Definition: NimbleScaffold.cpp:460
SurgSim::Devices::NimbleScaffold::m_serverIpAddress
std::string m_serverIpAddress
The IP address of the Nimble hand tracking server.
Definition: NimbleScaffold.h:89
SurgSim::Devices::NimbleScaffold::unregisterDevice
bool unregisterDevice(const NimbleDevice *device)
Unregisters the specified device object.
Definition: NimbleScaffold.cpp:337
SurgSim::Devices::NimbleScaffold::registerDevice
bool registerDevice(NimbleDevice *device)
Registers the specified device object.
Definition: NimbleScaffold.cpp:302
SurgSim::DataStructures::DataGroup
A collection of NamedData objects.
Definition: DataGroup.h:68
SurgSim::Devices::NimbleScaffold::updateDeviceData
void updateDeviceData()
Update the devices based on the data read from the Nimble server.
Definition: NimbleScaffold.cpp:442
SurgSim::Devices::NimbleScaffold::doUpdate
bool doUpdate(double dt) override
Implementation of actual work function for this thread, this has a default implementation to handle d...
Definition: NimbleScaffold.cpp:389
SurgSim::Framework::BasicThread
Basic thread implementation, tries to maintain a constant rate, supplies startup an initialization...
Definition: BasicThread.h:48
Logger.h
SurgSim::Devices::NimbleScaffold::doStartUp
bool doStartUp() override
Definition: NimbleScaffold.cpp:384
SurgSim::Devices::NimbleScaffold::m_serverPort
std::string m_serverPort
The port where the server is communicating.
Definition: NimbleScaffold.h:91
SurgSim::Devices::NimbleScaffold::~NimbleScaffold
~NimbleScaffold()
Destructor.
Definition: NimbleScaffold.cpp:288
SurgSim::Devices::NimbleScaffold::StateData
Definition: NimbleScaffold.cpp:253
BasicThread.h
SurgSim::Devices::NimbleScaffold::m_logger
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger used by the scaffold and all devices.
Definition: NimbleScaffold.h:84
SurgSim::Devices::NimbleScaffold::m_serverSocketOpen
bool m_serverSocketOpen
Flag to indicate that the socket is opened successfully.
Definition: NimbleScaffold.h:93
SurgSim::Devices::NimbleScaffold::getOrCreateSharedInstance
static std::shared_ptr< NimbleScaffold > getOrCreateSharedInstance()
Gets or creates the scaffold shared by all NimbleDevice instances.
Definition: NimbleScaffold.cpp:482