27 #include <RobotSkillTemplates/statecharts/ForceControlGroup/ForceControlGroupStatechartContext.generated.h>
31 #include <VirtualRobot/Robot.h>
32 #include <VirtualRobot/RobotNodeSet.h>
37 using namespace ForceControlGroup;
53 setTimeoutEvent(in.gettimeout(), createEventTimeout());
57 ForceControlGroupStatechartContext*
c = getContext<ForceControlGroupStatechartContext>();
60 if (in.istcpNameSet())
62 tcpName = in.gettcpName();
66 tcpName =
c->getRobot()->getRobotNodeSet(in.getrobotNodeSetName())->getTCP()->getName();
75 installConditionForSensorUpdate(
update && update_torque);
79 if (in.istimestampSet())
81 duration = now - in.gettimestamp()->toTime();
85 duration = IceUtil::Time::milliSecondsDouble(0);
89 std::string robotNodeSetName = in.getrobotNodeSetName();
99 float forceThreshold = in.getforceThreshold();
102 Eigen::Vector3f newVel(3);
103 Eigen::Vector3f newAcc(3);
106 if (curForce->toEigen().norm() > forceThreshold)
108 newAcc = curForce->toEigen() * in.getAccGain();
110 else if (vel->
toEigen().norm() > 0)
113 newAcc = -in.getDecGain() * vel->
toEigen().normalized();
117 newAcc = Eigen::Vector3f::Zero();
122 newVel = vel->
toEigen() + newAcc * duration.toMilliSecondsDouble() * 0.001;
124 if (newVel.norm() > in.getmaxVelocity())
126 newVel = newVel.normalized() * in.getmaxVelocity();
140 float torqueThreshold = in.gettorqueThreshold();
143 Eigen::Vector3f newRotVel(3);
144 Eigen::Vector3f newRotAcc(3);
147 if (curTorque->toEigen().norm() > torqueThreshold)
149 newRotAcc = curTorque->toEigen() * in.getRotAccGain();
151 else if (velRot->
toEigen().norm() > 0)
154 newRotAcc = -in.getRotDccGain() * velRot->
toEigen().normalized();
158 newRotAcc = Eigen::Vector3f::Zero();
163 Eigen::Vector3f velRotDelta = newRotAcc * duration.toMilliSecondsDouble() * 0.001;
165 if (velRotDelta.norm() > in.getmaxRotAcc())
167 velRotDelta = velRotDelta.normalized() * in.getmaxRotAcc();
170 newRotVel = velRot->
toEigen() + velRotDelta;
172 if (newRotVel.norm() > in.getmaxVelocity())
174 newRotVel = newRotVel.normalized() * in.getmaxRotVelocity();
187 out.setcurrentVelocity(
new FramedDirection(newVel, vel->frame, vel->agent));
188 out.setcurrentRotVelocity(
new FramedDirection(newRotVel, velRot->frame, velRot->agent));
201 c->getTCPControlUnit()->setTCPVelocity(robotNodeSetName, tcpName, newFramedVel,