Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Updated to v20 AME API
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 11, 2022
1 parent cba3ae1 commit 86c16f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
22 changes: 19 additions & 3 deletions external/vendor/Amethyst_API_Devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ inline std::wstring StringToWString(const std::string& str)
{
const int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), nullptr, 0);
std::wstring w_str(count, 0);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &w_str[0], count);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), w_str.data(), count);
return w_str;
}

Expand All @@ -40,14 +40,14 @@ inline std::string WStringToString(const std::wstring& w_str)
{
const int count = WideCharToMultiByte(CP_UTF8, 0, w_str.c_str(), w_str.length(), nullptr, 0, nullptr, nullptr);
std::string str(count, 0);
WideCharToMultiByte(CP_UTF8, 0, w_str.c_str(), -1, &str[0], count, nullptr, nullptr);
WideCharToMultiByte(CP_UTF8, 0, w_str.c_str(), -1, str.data(), count, nullptr, nullptr);
return str;
}

namespace ktvr
{
// Interface Version
static const char* IAME_API_Devices_Version = "IAME_API_Version_018";
static const char* IAME_API_Devices_Version = "IAME_API_Version_020";

// Return messaging types
enum K2InitErrorType
Expand Down Expand Up @@ -135,6 +135,9 @@ namespace ktvr
[[nodiscard]] Eigen::Vector3d getJointPosition() const { return jointPosition; }
[[nodiscard]] Eigen::Quaterniond getJointOrientation() const { return jointOrientation; }

[[nodiscard]] Eigen::Vector3d getPreviousJointPosition() const { return previousJointPosition; }
[[nodiscard]] Eigen::Quaterniond getPreviousJointOrientation() const { return previousJointOrientation; }

[[nodiscard]] Eigen::Vector3d getJointVelocity() const { return jointVelocity; }
[[nodiscard]] Eigen::Vector3d getJointAcceleration() const { return jointAcceleration; }

Expand All @@ -151,8 +154,12 @@ namespace ktvr
Eigen::Quaterniond orientation,
const ITrackedJointState state)
{
previousJointPosition = jointPosition;
previousJointOrientation = jointOrientation;

jointPosition = std::move(position);
jointOrientation = std::move(orientation);

trackingState = state;

// Update pose timestamp
Expand All @@ -169,6 +176,9 @@ namespace ktvr
Eigen::Vector3d angularAcceleration,
const ITrackedJointState state)
{
previousJointPosition = jointPosition;
previousJointOrientation = jointOrientation;

jointPosition = std::move(position);
jointOrientation = std::move(orientation);

Expand All @@ -187,6 +197,7 @@ namespace ktvr
// For servers!
void update_position(Eigen::Vector3d position)
{
previousJointPosition = jointPosition;
jointPosition = std::move(position);

// Update pose timestamp
Expand All @@ -197,6 +208,7 @@ namespace ktvr
// For servers!
void update_orientation(Eigen::Quaterniond orientation)
{
previousJointOrientation = jointOrientation;
jointOrientation = std::move(orientation);
}

Expand Down Expand Up @@ -235,13 +247,17 @@ namespace ktvr
Eigen::Vector3d jointPosition = Eigen::Vector3d(0., 0., 0.);
Eigen::Quaterniond jointOrientation = Eigen::Quaterniond(1., 0., 0., 0.);

Eigen::Vector3d previousJointPosition = Eigen::Vector3d(0., 0., 0.);
Eigen::Quaterniond previousJointOrientation = Eigen::Quaterniond(1., 0., 0., 0.);

Eigen::Vector3d jointVelocity = Eigen::Vector3d(0., 0., 0.);
Eigen::Vector3d jointAcceleration = Eigen::Vector3d(0., 0., 0.);

Eigen::Vector3d jointAngularVelocity = Eigen::Vector3d(0., 0., 0.);
Eigen::Vector3d jointAngularAcceleration = Eigen::Vector3d(0., 0., 0.);

ITrackedJointState trackingState = State_NotTracked;

long long poseTimestamp = 0;
long long previousPoseTimestamp = 0;
};
Expand Down
14 changes: 8 additions & 6 deletions external/vendor/Amethyst_API_Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ namespace ktvr
// Get file location in AppData
inline std::wstring GetK2AppDataFileDir(const std::wstring& relativeFilePath)
{
CreateDirectory(std::wstring(std::wstring(_wgetenv(L"APPDATA")) +
L"\\Amethyst\\").c_str(), nullptr);
return std::wstring(_wgetenv(L"APPDATA")) + L"\\Amethyst\\" + relativeFilePath;
std::filesystem::create_directories(
std::wstring(_wgetenv(L"APPDATA")) + L"\\Amethyst\\");

return std::wstring(_wgetenv(L"APPDATA")) +
L"\\Amethyst\\" + relativeFilePath;
}

// Get file location in AppData
inline std::wstring GetK2AppDataLogFileDir(
const std::wstring& relativeFolderName,
const std::wstring& relativeFilePath)
{
CreateDirectory(
std::wstring(std::wstring(_wgetenv(L"APPDATA")) +
L"\\Amethyst\\logs\\" + relativeFolderName + L"\\").c_str(), nullptr);
std::filesystem::create_directories(
std::wstring(_wgetenv(L"APPDATA")) +
L"\\Amethyst\\logs\\" + relativeFolderName + L"\\");

return std::wstring(_wgetenv(L"APPDATA")) +
L"\\Amethyst\\logs\\" + relativeFolderName + L"\\" + relativeFilePath;
Expand Down

0 comments on commit 86c16f9

Please sign in to comment.