C++ SDK for MANUS Core 2.1
Loading...
Searching...
No Matches
SDKClient.hpp
Go to the documentation of this file.
1#ifndef _SDK_CLIENT_HPP_
2#define _SDK_CLIENT_HPP_
3
4// Set up a Doxygen group.
9#include <chrono> // Used for haptic commands.
10#include <cmath> // Used for rounding float values.
11#include <iomanip> // Used for printing glove data, and converting glove IDs to strings.
12#include <memory> // Used for smart pointers.
13#include <sstream>
14#include <functional>
15
16#include "spdlog/sinks/stdout_color_sinks.h"
17#include "spdlog/spdlog.h"
18
20#include "ManusSDK.h"
21
23constexpr unsigned int NUMBER_OF_HANDS_SUPPORTED = 2;
24
26constexpr unsigned long long int MINIMUM_MILLISECONDS_BETWEEN_HAPTICS_COMMANDS = 20;
27
29constexpr unsigned long long int MILLISECONDS_BETWEEN_TEMPORARY_SKELETONS_UPDATE = 1000;
30
32enum class ClientState : int
33{
41
43};
44
46enum class ClientReturnCode : int
47{
59
61};
62
67{
68 bool shouldHapticFinger[NUM_FINGERS_ON_HAND];
69};
70
73{
74public:
75 SkeletonInfo info;
76 std::vector<SkeletonNode> nodes;
77};
78
81{
82public:
83 std::vector<ClientSkeleton> skeletons;
84};
85
87{
88public:
89 SDKClient();
90 ~SDKClient();
91
95
96 //Callbacks
97 static void OnConnectedCallback(const ManusHost* const p_Host);
98 static void OnDisconnectedCallback(const ManusHost* const p_Host);
99 static void OnSkeletonStreamCallback(const SkeletonStreamInfo* const p_Skeleton);
100 static void OnLandscapeCallback(const Landscape* const p_Landscape);
101 static void OnSystemCallback(const SystemMessage* const p_SystemMessage);
102 static void OnErgonomicsCallback(const ErgonomicsStream* const p_Ergo);
103
104 float RoundFloatValue(float p_Value, int p_NumDecimalsToKeep);
105 void AdvanceConsolePosition(short int p_Y);
106
107protected:
111
117
119
126
128 virtual ClientReturnCode ReconnectingToCore(int32_t p_ReconnectionTime = 0, int32_t p_ReconnectionAttempts = 0);
129
130 void PrintHandErgoData(ErgonomicsData& p_ErgoData, bool p_Left);
131 void PrintErgonomicsData();
132 void PrintDongleData();
133 void PrintSystemMessage();
134 void PrintSkeletonData();
135
136 void PrintTrackerData();
139
141
142 void PrintSkeletonInfo();
145
147
152
153 static NodeSetup CreateNodeSetup(uint32_t p_Id, uint32_t p_ParentId, float p_PosX, float p_PosY, float p_PosZ, std::string p_Name);
154 bool SetupHandNodes(uint32_t p_SklIndex);
155 bool SetupHandChains(uint32_t p_SklIndex);
156
157 void LoadTestSkeleton();
158 void UnloadTestSkeleton();
159
160 void AllocateChains();
161
167
168 void TestTimestamp();
169
170 void RemoveIndexFromTemporarySkeletonList(uint32_t p_Idx);
171 static ManusVec3 CreateManusVec3(float p_X, float p_Y, float p_Z);
172
173protected:
175
176 bool m_RequestedExit = false;
177
178 //Console
180 const short int m_ConsoleWidth = 220;
181 const short int m_ConsoleHeight = 44;
182 const short int m_ConsoleScrollback = 500;
184
185 SessionType m_ClientType = SessionType::SessionType_CoreSDK;
186
187 ClientState m_State = ClientState::ClientState_PickingConnectionType;
189
190 std::function<ClientReturnCode()> m_CurrentInteraction = nullptr;
191
192 //Networking
195
196 uint32_t m_HostToConnectTo = 0;
199
203
204 std::unique_ptr<ManusHost[]> m_AvailableHosts = nullptr;
205 std::unique_ptr<ManusHost> m_Host;
206
207 //Data
208 uint32_t m_SessionId = 0;
209
211
212 std::vector<uint32_t> m_LoadedSkeletons;
213 std::vector<uint32_t> m_TemporarySkeletons;
214
215 std::mutex m_SkeletonMutex;
216
219
220
221 std::chrono::time_point<std::chrono::high_resolution_clock> m_TimeSinceLastDisconnect;
222 std::chrono::time_point<std::chrono::high_resolution_clock> m_LastTemporarySkeletonUpdate = std::chrono::high_resolution_clock::now();
223
225 std::string m_SystemMessage = "";
226 SystemMessageType m_SystemMessageCode = SystemMessageType::SystemMessageType_Unknown;
227 uint32_t m_ModifiedSkeletonIndex = UINT_MAX;
228
229 ManusTimestampInfo m_ErgoTimestampInfo;
230 ErgonomicsData m_LeftGloveErgoData;
231 ErgonomicsData m_RightGloveErgoData;
232
233 ChainType m_ChainType = ChainType::ChainType_Invalid;
234
235 bool m_TrackerTest = false;
237 float m_TrackerOffset = 0.0f;
238
240 Landscape* m_NewLandscape = nullptr;
241 Landscape* m_Landscape = nullptr;
242
243 uint32_t m_FirstLeftGloveID = 0;
245};
246
247// Close the Doxygen group.
249#endif
std::string m_SystemMessage
Definition: SDKClient.hpp:225
void PrintSystemMessage()
Prints the last received system messages received from Core.
Definition: SDKClient.cpp:1135
virtual ClientReturnCode NoHostsFound()
When no available hosts are found the user can either retry or exit.
Definition: SDKClient.cpp:605
bool m_RumblingWrist[NUMBER_OF_HANDS_SUPPORTED]
Definition: SDKClient.hpp:210
void ClearAllTemporarySkeletons()
This support function is used to clear all temporary skeletons associated to the current SDK session,...
Definition: SDKClient.cpp:2317
SessionType m_ClientType
Definition: SDKClient.hpp:185
ClientReturnCode ShutDown()
When you are done with the SDK, don't forget to nicely shut it down this will close all connections t...
Definition: SDKClient.cpp:152
virtual ClientReturnCode DisplayingDataTracker()
Definition: SDKClient.cpp:828
ClientReturnCode Run()
The main SDKClient loop. This is a simple state machine which switches between different substates.
Definition: SDKClient.cpp:62
virtual ClientReturnCode DisplayingLandscapeTimeData()
Definition: SDKClient.cpp:866
ManusTimestampInfo m_ErgoTimestampInfo
Definition: SDKClient.hpp:229
void PrintSkeletonInfo()
Prints the type of the first chain generated by the AllocateChain function, this is used for testing.
Definition: SDKClient.cpp:1280
virtual ClientReturnCode ReconnectingToCore(int32_t p_ReconnectionTime=0, int32_t p_ReconnectionAttempts=0)
It is called when the sdk is disconnected from Core and the user select one of the options to reconne...
Definition: SDKClient.cpp:954
void AdvanceConsolePosition(short int p_Y)
Set the position that the next log message will appear at. Using this allows us to have somewhat of a...
Definition: SDKClient.cpp:345
void PrintHandErgoData(ErgonomicsData &p_ErgoData, bool p_Left)
Prints the ergonomics data of a hand.
Definition: SDKClient.cpp:1014
ClientSkeletonCollection * m_NextSkeleton
Definition: SDKClient.hpp:217
ErgonomicsData m_RightGloveErgoData
Definition: SDKClient.hpp:231
bool m_TrackerDataDisplayPerUser
Definition: SDKClient.hpp:236
void ClearTemporarySkeleton()
This support function is used to clear a temporary skeleton from the temporary skeleton list,...
Definition: SDKClient.cpp:2297
uint32_t m_FirstRightGloveID
Definition: SDKClient.hpp:244
std::chrono::time_point< std::chrono::high_resolution_clock > m_TimeSinceLastDisconnect
Definition: SDKClient.hpp:221
const short int m_ConsoleWidth
Definition: SDKClient.hpp:180
ClientReturnCode Initialize()
Initialize the sample console and the SDK. This function attempts to resize the console window and th...
Definition: SDKClient.cpp:34
uint32_t m_SecondsToFindHosts
Definition: SDKClient.hpp:198
bool m_ShouldConnectLocally
Definition: SDKClient.hpp:193
virtual ClientReturnCode UpdateBeforeDisplayingData()
Some things happen before every display update, no matter what state. They happen here,...
Definition: SDKClient.cpp:717
virtual ClientReturnCode LookingForHosts()
Simple example of the SDK looking for manus core hosts on the network and display them on screen.
Definition: SDKClient.cpp:556
virtual ClientReturnCode InitializeSDK()
Initialize the sdk, register the callbacks and set the coordinate system. This needs to be done befor...
Definition: SDKClient.cpp:361
bool SetupHandChains(uint32_t p_SklIndex)
This function sets up some basic hand chains. Chains are required for a Skeleton to be able to be ani...
Definition: SDKClient.cpp:1811
static void OnSystemCallback(const SystemMessage *const p_SystemMessage)
This gets called when receiving a system message from Core.
Definition: SDKClient.cpp:273
virtual ClientReturnCode RegisterAllCallbacks()
Used to register the callbacks between sdk and core. Callbacks that are registered functions that get...
Definition: SDKClient.cpp:433
uint32_t m_ConsoleClearTickCount
Definition: SDKClient.hpp:179
static SDKClient * s_Instance
Definition: SDKClient.hpp:174
void PrintTrackerData()
Prints the tracker data Since our console cannot render this data visually in 3d (its not in the scop...
Definition: SDKClient.cpp:1161
void PrintDongleData()
Print the ergonomics data received from Core.
Definition: SDKClient.cpp:1103
virtual ClientReturnCode PickingConnectionType()
Overridable switch states of how the client flow is done. This is the first option screen in the clie...
Definition: SDKClient.cpp:500
void PrintSkeletonData()
Prints the finalized skeleton data received from Core. Since our console cannot render this data visu...
Definition: SDKClient.cpp:1146
std::chrono::time_point< std::chrono::high_resolution_clock > m_LastTemporarySkeletonUpdate
Definition: SDKClient.hpp:222
float m_TrackerOffset
Definition: SDKClient.hpp:237
virtual ClientReturnCode ConnectingToCore()
After a connection option was selected, the client will now try to connect to manus core via the SDK.
Definition: SDKClient.cpp:675
void LoadTestSkeleton()
This function sets up a very minimalistic hand skeleton. In order to have any 3d positional/rotationa...
Definition: SDKClient.cpp:1901
virtual ClientReturnCode DisplayingDataTemporarySkeleton()
Definition: SDKClient.cpp:845
std::unique_ptr< ManusHost[]> m_AvailableHosts
Definition: SDKClient.hpp:204
void PrintTrackerDataGlobal()
Prints the tracker data without taking users into account. This shows how one can get the tracker dat...
Definition: SDKClient.cpp:1182
virtual ClientReturnCode PickingHost()
Print the found hosts and give the user the option to select one.
Definition: SDKClient.cpp:627
float RoundFloatValue(float p_Value, int p_NumDecimalsToKeep)
Round the given float value so that it has no more than the given number of decimals.
Definition: SDKClient.cpp:331
virtual ClientReturnCode DisplayingData()
Once the connections are made we loop this function it calls all the input handlers for different asp...
Definition: SDKClient.cpp:766
bool m_TrackerTest
Definition: SDKClient.hpp:235
static void OnErgonomicsCallback(const ErgonomicsStream *const p_Ergo)
This gets called when receiving ergonomics data from Manus Core In our sample we only save the first ...
Definition: SDKClient.cpp:301
uint32_t m_SleepBetweenReconnectingAttemptsInMs
Definition: SDKClient.hpp:202
void HandleSkeletonCommands()
Handles the console commands for the skeletons.
Definition: SDKClient.cpp:1544
SystemMessageType m_SystemMessageCode
Definition: SDKClient.hpp:226
uint32_t m_ModifiedSkeletonIndex
Definition: SDKClient.hpp:227
static void OnConnectedCallback(const ManusHost *const p_Host)
Gets called when the client is connects to manus core Using this callback is optional....
Definition: SDKClient.cpp:172
uint32_t m_HostToConnectTo
Definition: SDKClient.hpp:196
void RemoveIndexFromTemporarySkeletonList(uint32_t p_Idx)
Definition: SDKClient.cpp:2532
std::mutex m_LandscapeMutex
Definition: SDKClient.hpp:239
std::mutex m_SkeletonMutex
Definition: SDKClient.hpp:215
static ManusVec3 CreateManusVec3(float p_X, float p_Y, float p_Z)
Definition: SDKClient.cpp:1719
int m_ConsoleCurrentOffset
Definition: SDKClient.hpp:183
std::vector< uint32_t > m_LoadedSkeletons
Definition: SDKClient.hpp:212
void HandleHapticCommands()
This showcases haptics support on gloves. Send haptics commands to connected gloves if specific keys ...
Definition: SDKClient.cpp:1436
uint32_t m_SessionId
Definition: SDKClient.hpp:208
bool SetupHandNodes(uint32_t p_SklIndex)
This support function sets up the nodes for the skeleton hand In order to have any 3d positional/rota...
Definition: SDKClient.cpp:1734
std::function< ClientReturnCode()> m_CurrentInteraction
Definition: SDKClient.hpp:190
virtual ClientReturnCode DisplayingDataSkeleton()
Definition: SDKClient.cpp:808
std::vector< uint32_t > m_TemporarySkeletons
Definition: SDKClient.hpp:213
void TestTimestamp()
Definition: SDKClient.cpp:2511
bool m_RequestedExit
Definition: SDKClient.hpp:176
void GetTemporarySkeletonFromFile()
Definition: SDKClient.cpp:2429
bool m_ShouldConnectGRPC
Definition: SDKClient.hpp:194
SkeletonInfo info
Definition: SDKClient.hpp:75
void AllocateChains()
This support function sets up an incomplete hand skeleton and then uses manus core to allocate chains...
Definition: SDKClient.cpp:1967
std::vector< SkeletonNode > nodes
Definition: SDKClient.hpp:76
void HandleTrackerCommands()
This support function is used to set a test tracker and add it to the landscape.
Definition: SDKClient.cpp:1648
void SaveTemporarySkeletonToFile()
Definition: SDKClient.cpp:2333
virtual ClientReturnCode RestartSDK()
Used to restart and initialize the SDK to make sure a new connection can be set up....
Definition: SDKClient.cpp:411
const short int m_ConsoleScrollback
Definition: SDKClient.hpp:182
void PrintLandscapeTimeData()
Definition: SDKClient.cpp:1267
virtual ClientReturnCode DisplayingDataGlove()
display the ergonomics data of the gloves, and handles haptic commands.
Definition: SDKClient.cpp:790
virtual ClientReturnCode DisconnectedFromCore()
When the SDK loses the connection with Core the user can either close the sdk or try to reconnect to ...
Definition: SDKClient.cpp:885
static void OnDisconnectedCallback(const ManusHost *const p_Host)
Gets called when the client disconnects from manus core. This callback is optional and in the sample ...
Definition: SDKClient.cpp:225
void UnloadTestSkeleton()
This support function is used to unload a skeleton from Core.
Definition: SDKClient.cpp:1947
int32_t m_SecondsToAttemptReconnecting
Definition: SDKClient.hpp:200
std::unique_ptr< ManusHost > m_Host
Definition: SDKClient.hpp:205
void PrintTrackerDataPerUser()
Prints the tracker data per user, this shows how to access this data for each user.
Definition: SDKClient.cpp:1205
void HandleTemporarySkeletonCommands()
Handles the console commands for the temporary skeletons.
Definition: SDKClient.cpp:1619
Landscape * m_Landscape
Definition: SDKClient.hpp:241
static void OnSkeletonStreamCallback(const SkeletonStreamInfo *const p_Skeleton)
This gets called when the client is connected to manus core.
Definition: SDKClient.cpp:236
std::mutex m_SystemMessageMutex
Definition: SDKClient.hpp:224
void GetTemporarySkeletonIfModified()
This support function checks if a temporary skeleton related to the current session has been modified...
Definition: SDKClient.cpp:1362
void BuildTemporarySkeleton()
This support function is used for the manual allocation of the skeleton chains with means of a tempor...
Definition: SDKClient.cpp:2071
void PrintErgonomicsData()
Print the ergonomics data received from Core.
Definition: SDKClient.cpp:1042
bool shouldHapticFinger[NUM_FINGERS_ON_HAND]
Definition: SDKClient.hpp:68
uint32_t m_NumberOfHostsFound
Definition: SDKClient.hpp:197
static void OnLandscapeCallback(const Landscape *const p_Landscape)
This gets called when receiving landscape information from core.
Definition: SDKClient.cpp:259
static NodeSetup CreateNodeSetup(uint32_t p_Id, uint32_t p_ParentId, float p_PosX, float p_PosY, float p_PosZ, std::string p_Name)
Skeletons are pretty extensive in their data setup so we have several support functions so we can cor...
Definition: SDKClient.cpp:1702
void PrintTemporarySkeletonInfo()
This support function gets the temporary skeletons for all sessions connected to Core and it prints t...
Definition: SDKClient.cpp:1403
Landscape * m_NewLandscape
Definition: SDKClient.hpp:240
void HandleSkeletonHapticCommands()
This showcases haptics support on the skeletons. Send haptics commands to the gloves connected to a s...
Definition: SDKClient.cpp:1559
ErgonomicsData m_LeftGloveErgoData
Definition: SDKClient.hpp:230
ChainType m_ChainType
Definition: SDKClient.hpp:233
ClientState m_PreviousState
Definition: SDKClient.hpp:188
std::vector< ClientSkeleton > skeletons
Definition: SDKClient.hpp:83
const short int m_ConsoleHeight
Definition: SDKClient.hpp:181
int32_t m_MaxReconnectionAttempts
Definition: SDKClient.hpp:201
ClientState m_State
Definition: SDKClient.hpp:187
uint32_t m_FirstLeftGloveID
Definition: SDKClient.hpp:243
ClientSkeletonCollection * m_Skeleton
Definition: SDKClient.hpp:218
Used to store the information about the final animated skeletons.
Definition: SDKClient.hpp:73
Used to store all the final animated skeletons received from Core.
Definition: SDKClient.hpp:81
constexpr unsigned long long int MINIMUM_MILLISECONDS_BETWEEN_HAPTICS_COMMANDS
Constant expression used to define the time between two possible haptics commands sent.
Definition: SDKClient.hpp:26
constexpr unsigned long long int MILLISECONDS_BETWEEN_TEMPORARY_SKELETONS_UPDATE
Constant expression used to define the time between two updates of the temporary skeleton count print...
Definition: SDKClient.hpp:29
ClientState
The current state of the client.
Definition: SDKClient.hpp:33
constexpr unsigned int NUMBER_OF_HANDS_SUPPORTED
Constant expression: number of hands supported by demo.
Definition: SDKClient.hpp:23
ClientReturnCode
Values that can be returned by this application.
Definition: SDKClient.hpp:47
@ ClientState_NoHostsFound
@ ClientState_ConnectingToCore
@ ClientState_LookingForHosts
@ ClientState_MAX_CLIENT_STATE_SIZE
@ ClientState_PickingConnectionType
@ ClientState_DisplayingData
@ ClientState_PickingHost
@ ClientState_Disconnected
@ ClientReturnCode_MAX_CLIENT_RETURN_CODE_SIZE
@ ClientReturnCode_FailedWrongTimeToGetData
@ ClientReturnCode_FailedPlatformSpecificInitialization
@ ClientReturnCode_FailedToConnect
@ ClientReturnCode_FailedToFindHosts
@ ClientReturnCode_FailedToRestart
@ ClientReturnCode_FailedToShutDownSDK
@ ClientReturnCode_UnrecognizedStateEncountered
@ ClientReturnCode_FailedToInitialize
@ ClientReturnCode_FailedToResizeWindow
@ ClientReturnCode_FailedPlatformSpecificShutdown
Haptic settings for a single glove.
Definition: SDKClient.hpp:67