Skip to content
Snippets Groups Projects
Commit b7cd9c8e authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add context menu to switch between Ik methods

parent b6d21795
No related branches found
No related tags found
No related merge requests found
#include "IkDemo.h"
#include <SimoxUtility/algorithm/string.h>
#include <SimoxUtility/meta/EnumNames.hpp>
#include <SimoxUtility/math/pose/invert.h>
#include <VirtualRobot/Robot.h>
......@@ -29,6 +30,11 @@ namespace armar6::skills::components::armar6_ik_demo
SimpleDiffIk,
CompositeDiffIk,
};
const simox::meta::EnumNames<IkMethod> IkMethodNames =
{
{ IkMethod::SimpleDiffIk, "Simple Diff IK" },
{ IkMethod::CompositeDiffIk, "Composite Diff IK" },
};
struct Manipulator
{
......@@ -40,7 +46,7 @@ namespace armar6::skills::components::armar6_ik_demo
{
}
bool handle(viz::InteractionFeedback const& interaction, viz::StagedCommit* stage)
virtual bool handle(viz::InteractionFeedback const& interaction, viz::StagedCommit* stage)
{
bool updated = false;
if (interaction.layer() == gizmo.layer.data_.name)
......@@ -53,7 +59,6 @@ namespace armar6::skills::components::armar6_ik_demo
virtual void visualize(viz::Client& arviz) = 0;
virtual void runIk(IkDemo::Robot& robot) = 0;
viz::PoseGizmo gizmo;
};
......@@ -62,7 +67,15 @@ namespace armar6::skills::components::armar6_ik_demo
{
TcpManipulator()
{
gizmo.box.size({75, 100, 200});
std::vector<std::string> options;
for (IkMethod method : IkMethodNames.values())
{
options.push_back("Use " + IkMethodNames.to_name(method));
}
gizmo.box
.size({75, 100, 200})
.enable(viz::interaction().selection().transform().hideDuringTransform()
.contextMenu(options));
};
void visualize(viz::Client& arviz) override
......@@ -70,6 +83,38 @@ namespace armar6::skills::components::armar6_ik_demo
gizmo.setLayer(arviz.layer(tcp->getName()));
gizmo.update();
}
bool handle(viz::InteractionFeedback const& interaction, viz::StagedCommit* stage) override
{
bool updated = Manipulator::handle(interaction, stage);
if (interaction.layer() == gizmo.layer.data_.name)
{
switch (interaction.type())
{
case viz::InteractionFeedbackType::ContextMenuChosen:
{
int i = 0;
for (IkMethod method : IkMethodNames.values())
{
if (i == interaction.chosenContextMenuEntry())
{
this->method = method;
updated |= true;
ARMARX_IMPORTANT << "[" << tcp->getName() << "] Using " << IkMethodNames.to_name(method);
break;
}
++i;
}
} break;
default:
break;
}
}
return updated;
}
void runIk(IkDemo::Robot& robot) override
{
const Eigen::Matrix4f tcpPoseInRobotFrame =
......@@ -230,7 +275,7 @@ namespace armar6::skills::components::armar6_ik_demo
VirtualRobot::RobotNodeSetPtr nodeSet;
VirtualRobot::RobotNodePtr tcp;
IkMethod method = IkMethod::CompositeDiffIk;
IkMethod method = IkMethod::SimpleDiffIk;
};
......
......@@ -9,7 +9,7 @@ namespace armarx::viz
PoseGizmo::PoseGizmo()
{
box.enable(viz::interaction().selection().transform());
box.enable(viz::interaction().selection().transform().hideDuringTransform());
}
void PoseGizmo::setLayer(const Layer& layer_)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment