Skip to content

Commit

Permalink
Added RPC method to reset static poses.
Browse files Browse the repository at this point in the history
This is because otherwise static poses cannot be overwritten
  • Loading branch information
S-Dafarra committed Oct 4, 2024
1 parent 2f18059 commit 51836d1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/devices/openxrheadset/OpenXrHeadset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,3 +1021,10 @@ bool yarp::dev::OpenXrHeadset::setCustomPoseRelativeOrientation(const std::strin
static_cast<float>(angle2),
static_cast<float>(angle3)});
}

void yarp::dev::OpenXrHeadset::resetTransforms()
{
std::lock_guard<std::mutex> lock(m_mutex);
m_tfPublisher->clear();
m_posesManager.reset();
}
8 changes: 8 additions & 0 deletions src/devices/openxrheadset/OpenXrHeadset.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ class yarp::dev::OpenXrHeadset : public yarp::dev::DeviceDriver,
*/
virtual bool setCustomPoseRelativeOrientation(const std::string& customFrameName, const double angle1, const double angle2, const double angle3) override;

/**
* Reset the transforms all the published tranforms.
* This will also delete all the transforms currently stored in the transform server,
* so also the static poses will be published again. This must be used with caution,
* as it will reset all the transforms, including the ones that are not published by this module.
*/
virtual void resetTransforms() override;

private:

struct GuiParam
Expand Down
9 changes: 9 additions & 0 deletions src/devices/openxrheadset/PosePublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,12 @@ void PosePublisher::publish()
yCWarning(OPENXRHEADSET) << "Failed to publish" << m_label << "frame.";
}
}

void PosePublisher::reset()
{
m_publishedOnce = false;
m_data = OpenXrInterface::NamedPoseVelocity();
m_previouslyPublishedData = OpenXrInterface::NamedPoseVelocity();
m_localPose.eye();
deactivate();
}
2 changes: 2 additions & 0 deletions src/devices/openxrheadset/PosePublisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class PosePublisher

void publish();

void reset();

};

#endif // YARP_DEV_POSEPUBLISHER_H
15 changes: 15 additions & 0 deletions src/devices/openxrheadset/PosesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,18 @@ bool PosesManager::setCustomPoseRelativeOrientation(const std::string &customFra
m_customPoses[customFrameIt->second].setRelativeOrientation(relativeOrientationEulerAngles);
return true;
}

void PosesManager::reset()
{
m_rootFramePublisher.reset();

for (auto& poseIt : m_poses)
{
poseIt.second.reset();
}

for (auto& customPose : m_customPoses)
{
customPose.reset();
}
}
2 changes: 2 additions & 0 deletions src/devices/openxrheadset/PosesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class PosesManager

bool setCustomPoseRelativeOrientation(const std::string& customFrameName, const Eigen::Vector3f& relativeOrientationEulerAngles);

void reset();

};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,12 @@ service OpenXrHeadsetCommands
* @return True if successfull, false if the pose is not found
*/
bool setCustomPoseRelativeOrientation(1:string customFrameName, 2:double angle1, 3:double angle2, 4:double angle3);

/**
* Reset the transforms all the published tranforms.
* This will also delete all the transforms currently stored in the transform server,
* so also the static poses will be published again. This must be used with caution,
* as it will reset all the transforms, including the ones that are not published by this module.
*/
void resetTransforms();
}

0 comments on commit 51836d1

Please sign in to comment.