27 #include <IceUtil/UUID.h>
28 #include <VirtualRobot/RobotNodeSet.h>
32 #include <RobotAPI/interface/observers/ObserverFilters.h>
34 #include "VisualServoGroupStatechartContext.generated.h"
37 using namespace VisualServoGroup;
41 TwoArmVisualServoTowardsTargetPose::GetName(),
57 if (in.isStartTimeRefSet())
59 ARMARX_INFO <<
"Using existing StartTime for Two Arm Visual Servo.";
60 local.setTimerCreated(
false);
64 ARMARX_INFO <<
"Creating new StartTime for Two Arm Visual Servo.";
65 in.setStartTimeRef(getContext<StatechartContext>()->systemObserverPrx->startTimer(
66 "TwoArmVisualServoTimer_" + IceUtil::generateUUID()));
67 local.setTimerCreated(
true);
70 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
71 if (context->getTCPControlUnit()->isRequested())
73 ARMARX_INFO <<
"TCPControlUnit is already requested.";
74 local.setTCPControlUnitRequested(
false);
79 context->getTCPControlUnit()->request();
80 local.setTCPControlUnitRequested(
true);
83 std::string leftTcpName = context->getRobot()
84 ->getRobotNodeSet(in.getLeftHandKinematicChainName())
87 local.setLeftTcpName(leftTcpName);
89 std::string rightTcpName = context->getRobot()
90 ->getRobotNodeSet(in.getRightHandKinematicChainName())
93 local.setRightTcpName(rightTcpName);
95 local.setLeftTargetReached(
false);
96 local.setRightTargetReached(
false);
98 memoryx::ChannelRefBaseSequence instancesLeft =
99 context->getObjectMemoryObserver()->getObjectInstances(in.getLeftHandMemoryChannel());
100 memoryx::ChannelRefBaseSequence instancesRight =
101 context->getObjectMemoryObserver()->getObjectInstances(in.getRightHandMemoryChannel());
105 if (instancesLeft.size() == 0)
108 << in.getLeftHandMemoryChannel()->get<std::string>(
"className");
109 auto list = context->getObjectMemoryObserver()->getObjectInstancesByClass(
110 in.getLeftHandMemoryChannel()->get<std::string>(
"className"));
112 for (
auto& entry :
list)
116 << ChannelRefPtr::dynamicCast(entry)->getDataField(
"className")->getString();
123 ChannelRefPtr::dynamicCast(instancesLeft.front())->getDataFieldIdentifier(
"position");
126 if (instancesRight.size() == 0)
129 << in.getRightHandMemoryChannel()->get<std::string>(
"className");
130 auto list = context->getObjectMemoryObserver()->getObjectInstancesByClass(
131 in.getRightHandMemoryChannel()->get<std::string>(
"className"));
133 for (
auto& entry :
list)
137 << ChannelRefPtr::dynamicCast(entry)->getDataField(
"className")->getString();
144 ChannelRefPtr::dynamicCast(instancesRight.front())->getDataFieldIdentifier(
"position");
150 local.setPoseUpdateTimerChannelRef(ChannelRefPtr::dynamicCast(
151 context->systemObserverPrx->startTimer(
"objectPoseUpdatedTimer")));
152 auto elapsed = local.getPoseUpdateTimerChannelRef()->getDataFieldIdentifier(
"elapsedMs");
153 if (in.getWatchObjectPoseUpdates())
155 Literal left(leftPosId, checks::updated);
156 Literal right(rightPosId, checks::updated);
157 Literal minDelay(elapsed, checks::larger, {100});
158 installConditionForObjectPoseUpdated((left || right) && minDelay);
161 if (in.isRightHandForceFieldRefSet() && in.isLeftHandForceFieldRefSet())
163 Literal rightForceLiteral(in.getRightHandForceFieldRef()->getDataFieldIdentifier(),
164 checks::magnitudelarger,
166 Literal leftForceLiteral(in.getLeftHandForceFieldRef()->getDataFieldIdentifier(),
167 checks::magnitudelarger,
170 installConditionForForceThresholdExceeded(rightForceLiteral || leftForceLiteral);
177 while (!isRunningTaskStopped())
179 if (in.isRightHandForceFieldRefSet() && in.isLeftHandForceFieldRefSet())
197 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
198 context->getTCPControlUnit()->release();
200 context->systemObserverPrx->removeTimer(local.getPoseUpdateTimerChannelRef());
202 if (local.getTimerCreated())
205 getContext<StatechartContext>()->systemObserverPrx->removeTimer(in.getStartTimeRef());
207 if (local.getTCPControlUnitRequested())
210 getContext<VisualServoGroupStatechartContext>()->getTCPControlUnit()->release();