29 #include <VirtualRobot/Robot.h>
30 #include <VirtualRobot/RobotNodeSet.h>
36 #include <RobotSkillTemplates/statecharts/ForceControlGroup/ForceControlGroupStatechartContext.generated.h>
40 using namespace ForceControlGroup;
44 ZeroForceControlVelocityCalcuation::GetName(),
59 setTimeoutEvent(in.gettimeout(), createEventTimeout());
62 ForceControlGroupStatechartContext*
c = getContext<ForceControlGroupStatechartContext>();
65 if (in.istcpNameSet())
67 tcpName = in.gettcpName();
71 tcpName =
c->getRobot()->getRobotNodeSet(in.getrobotNodeSetName())->getTCP()->getName();
81 installConditionForSensorUpdate(
update && update_torque);
85 if (in.istimestampSet())
87 duration = now - in.gettimestamp()->toTime();
91 duration = IceUtil::Time::milliSecondsDouble(0);
95 std::string robotNodeSetName = in.getrobotNodeSetName();
105 float forceThreshold = in.getforceThreshold();
108 Eigen::Vector3f newVel(3);
109 Eigen::Vector3f newAcc(3);
112 if (curForce->toEigen().norm() > forceThreshold)
114 newAcc = curForce->toEigen() * in.getAccGain();
116 else if (vel->
toEigen().norm() > 0)
119 newAcc = -in.getDecGain() * vel->
toEigen().normalized();
123 newAcc = Eigen::Vector3f::Zero();
128 newVel = vel->
toEigen() + newAcc * duration.toMilliSecondsDouble() * 0.001;
130 if (newVel.norm() > in.getmaxVelocity())
132 newVel = newVel.normalized() * in.getmaxVelocity();
146 float torqueThreshold = in.gettorqueThreshold();
149 Eigen::Vector3f newRotVel(3);
150 Eigen::Vector3f newRotAcc(3);
153 if (curTorque->toEigen().norm() > torqueThreshold)
155 newRotAcc = curTorque->toEigen() * in.getRotAccGain();
157 else if (velRot->
toEigen().norm() > 0)
160 newRotAcc = -in.getRotDccGain() * velRot->
toEigen().normalized();
164 newRotAcc = Eigen::Vector3f::Zero();
169 Eigen::Vector3f velRotDelta = newRotAcc * duration.toMilliSecondsDouble() * 0.001;
171 if (velRotDelta.norm() > in.getmaxRotAcc())
173 velRotDelta = velRotDelta.normalized() * in.getmaxRotAcc();
176 newRotVel = velRot->
toEigen() + velRotDelta;
178 if (newRotVel.norm() > in.getmaxVelocity())
180 newRotVel = newRotVel.normalized() * in.getmaxRotVelocity();
191 out.setcurrentVelocity(
new FramedDirection(newVel, vel->frame, vel->agent));
192 out.setcurrentRotVelocity(
new FramedDirection(newRotVel, velRot->frame, velRot->agent));
201 c->getRobot(), *newFramedVel,
c->getRobot()->getRootNode()->getName());
203 <<
"current newVel in platform: " << newFramedVel->output();
205 c->getRobot(), *newFramedRotVel,
c->getRobot()->getRootNode()->getName());
207 <<
"current newVel in platform: " << newFramedRotVel->output();
210 c->getTCPControlUnit()->setTCPVelocity(
211 robotNodeSetName, tcpName, newFramedVel, newFramedRotVel);