26 #include "VisualServoGroupStatechartContext.generated.h"
29 #include <RobotAPI/interface/observers/ObserverFilters.h>
31 #include <IceUtil/UUID.h>
34 using namespace VisualServoGroup;
51 if (in.isStartTimeRefSet())
53 ARMARX_INFO <<
"Using existing StartTime for Two Arm Visual Servo.";
54 local.setTimerCreated(
false);
58 ARMARX_INFO <<
"Creating new StartTime for Two Arm Visual Servo.";
59 in.setStartTimeRef(getContext<StatechartContext>()->systemObserverPrx->startTimer(
"TwoArmVisualServoTimer_" + IceUtil::generateUUID()));
60 local.setTimerCreated(
true);
63 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
64 if (context->getTCPControlUnit()->isRequested())
66 ARMARX_INFO <<
"TCPControlUnit is already requested.";
67 local.setTCPControlUnitRequested(
false);
72 context->getTCPControlUnit()->request();
73 local.setTCPControlUnitRequested(
true);
76 std::string leftTcpName = context->getRobot()->getRobotNodeSet(in.getLeftHandKinematicChainName())->getTCP()->getName();
77 local.setLeftTcpName(leftTcpName);
79 std::string rightTcpName = context->getRobot()->getRobotNodeSet(in.getRightHandKinematicChainName())->getTCP()->getName();
80 local.setRightTcpName(rightTcpName);
82 local.setLeftTargetReached(
false);
83 local.setRightTargetReached(
false);
85 memoryx::ChannelRefBaseSequence instancesLeft = context->getObjectMemoryObserver()->getObjectInstances(in.getLeftHandMemoryChannel());
86 memoryx::ChannelRefBaseSequence instancesRight = context->getObjectMemoryObserver()->getObjectInstances(in.getRightHandMemoryChannel());
90 if (instancesLeft.size() == 0)
92 ARMARX_WARNING <<
"No instances of the hand in the memory: " << in.getLeftHandMemoryChannel()->get<std::string>(
"className");
93 auto list = context->getObjectMemoryObserver()->getObjectInstancesByClass(in.getLeftHandMemoryChannel()->get<std::string>(
"className"));
95 for (
auto& entry :
list)
97 ARMARX_INFO <<
"obj: " << ChannelRefPtr::dynamicCast(entry)->getDataField(
"className")->getString();
103 leftPosId = ChannelRefPtr::dynamicCast(instancesLeft.front())->getDataFieldIdentifier(
"position");
106 if (instancesRight.size() == 0)
108 ARMARX_WARNING <<
"No instances of the hand in the memory: " << in.getRightHandMemoryChannel()->get<std::string>(
"className");
109 auto list = context->getObjectMemoryObserver()->getObjectInstancesByClass(in.getRightHandMemoryChannel()->get<std::string>(
"className"));
111 for (
auto& entry :
list)
113 ARMARX_INFO <<
"obj: " << ChannelRefPtr::dynamicCast(entry)->getDataField(
"className")->getString();
119 rightPosId = ChannelRefPtr::dynamicCast(instancesRight.front())->getDataFieldIdentifier(
"position");
125 local.setPoseUpdateTimerChannelRef(ChannelRefPtr::dynamicCast(context->systemObserverPrx->startTimer(
"objectPoseUpdatedTimer")));
126 auto elapsed = local.getPoseUpdateTimerChannelRef()->getDataFieldIdentifier(
"elapsedMs");
127 if (in.getWatchObjectPoseUpdates())
129 Literal left(leftPosId, checks::updated);
130 Literal right(rightPosId, checks::updated);
131 Literal minDelay(elapsed, checks::larger, {100});
132 installConditionForObjectPoseUpdated((left || right) && minDelay);
135 if (in.isRightHandForceFieldRefSet() && in.isLeftHandForceFieldRefSet())
140 installConditionForForceThresholdExceeded(rightForceLiteral || leftForceLiteral);
146 while (!isRunningTaskStopped())
148 if (in.isRightHandForceFieldRefSet() && in.isLeftHandForceFieldRefSet())
165 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
166 context->getTCPControlUnit()->release();
168 context->systemObserverPrx->removeTimer(local.getPoseUpdateTimerChannelRef());
170 if (local.getTimerCreated())
173 getContext<StatechartContext>()->systemObserverPrx->removeTimer(in.getStartTimeRef());
175 if (local.getTCPControlUnitRequested())
178 getContext<VisualServoGroupStatechartContext>()->getTCPControlUnit()->release();