Skip to content

Commit

Permalink
Added commands to get the expressions ports and the IPD
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed Oct 25, 2024
1 parent 0fa9ffb commit f7a4f1b
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/devices/openxrheadset/ExpressionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,29 @@ bool ExpressionsManager::configure(const std::string& prefix, bool eyeSupported,
m_eyeSupported = eyeSupported;
m_lipSupported = lipSupported;
m_gazeSupported = gazeSupported;
m_eyeExpressionsPortName = prefix + "/expressions/eye";
m_lipExpressionsPortName = prefix + "/expressions/lip";
m_gazePortName = prefix + "/expressions/gaze";

if (m_eyeSupported)
{
if (!m_eyeExpressionsPort.open(prefix + "/expressions/eye"))
if (!m_eyeExpressionsPort.open(m_eyeExpressionsPortName))
{
return false;
}
}

if (m_lipSupported)
{
if (!m_lipExpressionsPort.open(prefix + "/expressions/lip"))
if (!m_lipExpressionsPort.open(m_lipExpressionsPortName))
{
return false;
}
}

if (m_gazeSupported)
{
if (!m_gazePort.open(prefix + "/expressions/gaze"))
if (!m_gazePort.open(m_gazePortName))
{
return false;
}
Expand Down Expand Up @@ -89,3 +92,18 @@ void ExpressionsManager::close()
m_lipExpressionsPort.close();
m_gazePort.close();
}

std::string ExpressionsManager::getEyeExpressionsPortName() const
{
return m_eyeExpressionsPortName;
}

std::string ExpressionsManager::getLipExpressionsPortName() const
{
return m_lipExpressionsPortName;
}

std::string ExpressionsManager::getGazePortName() const
{
return m_gazePortName;
}
9 changes: 9 additions & 0 deletions src/devices/openxrheadset/ExpressionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class ExpressionsManager
bool m_eyeSupported{ false };
bool m_lipSupported{ false };
bool m_gazeSupported{ false };
std::string m_eyeExpressionsPortName;
std::string m_lipExpressionsPortName;
std::string m_gazePortName;

public:

Expand All @@ -34,6 +37,12 @@ class ExpressionsManager
void setGaze(const OpenXrInterface::Pose& headPose, const OpenXrInterface::Pose& gaze);

void close();

std::string getEyeExpressionsPortName() const;

std::string getLipExpressionsPortName() const;

std::string getGazePortName() const;
};


Expand Down
43 changes: 43 additions & 0 deletions src/devices/openxrheadset/OpenXrHeadset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,13 @@ bool yarp::dev::OpenXrHeadset::setInterCameraDistance(const double distance)
return m_eyesManager.setInterCameraDistance(distance);
}

double yarp::dev::OpenXrHeadset::getIPD()
{
std::lock_guard<std::mutex> lock(m_mutex);

return m_openXrInterface.ipd();
}

std::string yarp::dev::OpenXrHeadset::getLeftImageControlPortName()
{
std::lock_guard<std::mutex> lock(m_mutex);
Expand Down Expand Up @@ -1041,3 +1048,39 @@ bool yarp::dev::OpenXrHeadset::resetTransforms()
m_posesManager.reset();
return true;
}

bool yarp::dev::OpenXrHeadset::eyeExpressionsEnabled()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_openXrInterface.eyeExpressionsSupported();
}

std::string yarp::dev::OpenXrHeadset::getEyeExpressionsPortName()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_expressionsManager.getEyeExpressionsPortName();
}

bool yarp::dev::OpenXrHeadset::lipExpressionsEnabled()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_openXrInterface.lipExpressionsSupported();
}

std::string yarp::dev::OpenXrHeadset::getLipExpressionsPortName()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_expressionsManager.getLipExpressionsPortName();
}

bool yarp::dev::OpenXrHeadset::gazeEnabled()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_openXrInterface.gazeSupported();
}

std::string yarp::dev::OpenXrHeadset::getGazePortName()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_expressionsManager.getGazePortName();
}
44 changes: 43 additions & 1 deletion src/devices/openxrheadset/OpenXrHeadset.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver,

/**
* Get the current lateral distance between the visualization of the robot cameras.
* @return The IPD in meters.
* @return The distance in meters.
*/
virtual double getInterCameraDistance() override;

Expand All @@ -201,6 +201,12 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver,
*/
virtual bool setInterCameraDistance(const double distance) override;

/**
* Get the current IPD (Inter Pupillary Distance) of the VR eyes.
* @return The IPD in meters
*/
virtual double getIPD() override;

/**
* Get the name of the port trough which it is possible to control the left image.
* @return the name of the port to control the left image.
Expand Down Expand Up @@ -264,6 +270,42 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver,
*/
virtual bool resetTransforms() override;

/**
* Check if the eye expressions are enabled
* @return True if the eye expressions are enabled, false otherwise
*/
virtual bool eyeExpressionsEnabled() override;

/**
* Get the name of the port trough which it is possible to get the eye expressions.
* @return the name of the port to get the eye expressions.
*/
virtual std::string getEyeExpressionsPortName() override;

/**
* Check if the lip expressions are enabled
* @return True if the lip expressions are enabled, false otherwise
*/
virtual bool lipExpressionsEnabled() override;

/**
* Get the name of the port trough which it is possible to get the lip expressions.
* @return the name of the port to get the lip expressions.
*/
virtual std::string getLipExpressionsPortName() override;

/**
* Check if the gaze acquisition is enabled
* @return True if the gaze acquisition is enabled, false otherwise
*/
virtual bool gazeEnabled() override;

/**
* Get the name of the port trough which it is possible to get the gaze position.
* @return the name of the port to get the gaze position.
*/
virtual std::string getGazePortName() override;

private:

struct GuiParam
Expand Down
7 changes: 7 additions & 0 deletions src/devices/openxrheadset/OpenXrInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,8 @@ void OpenXrInterface::updateXrSpaces()
m_pimpl->mid_views_pose_inverted.orientation = toXr(toEigen(m_pimpl->mid_views_pose.orientation).inverse());
m_pimpl->mid_views_pose_inverted.position = toXr(toEigen(m_pimpl->mid_views_pose_inverted.orientation) * -toEigen(m_pimpl->mid_views_pose.position));

m_pimpl->ipd = (toEigen(m_pimpl->views[1].pose.position) - toEigen(m_pimpl->views[0].pose.position)).norm();

for (size_t i = 0; i < m_pimpl->views.size(); ++i)
{
#ifdef DEBUG_RENDERING_LOCATION
Expand Down Expand Up @@ -1794,6 +1796,11 @@ bool OpenXrInterface::isRunning() const
return m_pimpl->initialized && !m_pimpl->closing;
}

float OpenXrInterface::ipd() const
{
return m_pimpl->ipd;
}

OpenXrInterface::Pose OpenXrInterface::headPose() const
{
return XrSpaceLocationToPose(m_pimpl->view_space_location);
Expand Down
2 changes: 2 additions & 0 deletions src/devices/openxrheadset/OpenXrInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class OpenXrInterface

bool isRunning() const;

float ipd() const;

Pose headPose() const;

Velocity headVelocity() const;
Expand Down
2 changes: 2 additions & 0 deletions src/devices/openxrheadset/impl/OpenXrInterfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class OpenXrInterface::Implementation
// position of a frame in the middle of the eyes, oriented as the first eye
XrPosef mid_views_pose_inverted;

float ipd = 0.06f;

// List of top level paths to retrieve the state of each action
std::vector<TopLevelPath> top_level_paths;

Expand Down
44 changes: 43 additions & 1 deletion src/devices/openxrheadset/thrifts/OpenXrHeadsetCommands.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ service OpenXrHeadsetCommands

/**
* Get the current lateral distance between the visualization of the robot cameras.
* @return The IPD in meters.
* @return The distance in meters.
*/
double getInterCameraDistance();

Expand All @@ -125,6 +125,12 @@ service OpenXrHeadsetCommands
*/
bool setInterCameraDistance(1:double distance);

/**
* Get the current IPD (Inter Pupillary Distance) of the VR eyes.
* @return The IPD in meters
*/
double getIPD();

/**
* Get the name of the port trough which it is possible to control the left image.
* @return the name of the port to control the left image.
Expand Down Expand Up @@ -187,4 +193,40 @@ service OpenXrHeadsetCommands
* as it will reset all the transforms, including the ones that are not published by this module.
*/
bool resetTransforms();

/**
* Check if the eye expressions are enabled
* @return True if the eye expressions are enabled, false otherwise
*/
bool eyeExpressionsEnabled();

/**
* Get the name of the port trough which it is possible to get the eye expressions.
* @return the name of the port to get the eye expressions.
*/
string getEyeExpressionsPortName();

/**
* Check if the lip expressions are enabled
* @return True if the lip expressions are enabled, false otherwise
*/
bool lipExpressionsEnabled();

/**
* Get the name of the port trough which it is possible to get the lip expressions.
* @return the name of the port to get the lip expressions.
*/
string getLipExpressionsPortName();

/**
* Check if the gaze acquisition is enabled
* @return True if the gaze acquisition is enabled, false otherwise
*/
bool gazeEnabled();

/**
* Get the name of the port trough which it is possible to get the gaze position.
* @return the name of the port to get the gaze position.
*/
string getGazePortName();
}

0 comments on commit f7a4f1b

Please sign in to comment.