30 using namespace ForceTorqueUtility;
43 const float forceThreshold = in.getForceThreshold();
46 DatafieldRefPtr forceDf = DatafieldRefPtr::dynamicCast(getForceTorqueObserver()->getForceDatafield(in.getFTDatafieldName()));
47 const Eigen::Vector3f weights = in.getForceWeights()->toEigen();
48 const Eigen::Vector3f axis = in.getAxis()->toEigen().normalized();
49 auto getForceAlongAxis = [&]() ->
float
51 return forceDf->getDataField()->get<
FramedDirection>()->
toEigen().cwiseProduct(weights).transpose() * axis;
54 in.getTriggerInAxisDirection();
55 in.getTriggerCounterAxisDirection();
56 std::deque<float> spikes(in.getWindowSizeMs() / 10, getForceAlongAxis());
58 while (!isRunningTaskStopped())
60 spikes.push_back(getForceAlongAxis());
63 float refValue = spikes.at(0);
65 bool risingEdgeDetected =
false;
66 bool fallingEdgeDetected =
false;
68 bool f2rDetected =
false;
69 bool r2fDetected =
false;
71 for (
const float spike : spikes)
79 else if (spike > refValue + forceThreshold)
82 risingEdgeDetected =
true;
83 f2rDetected |= fallingEdgeDetected;
93 else if (spike < refValue - forceThreshold)
96 fallingEdgeDetected =
true;
97 r2fDetected |= risingEdgeDetected;
101 if ((in.getTriggerInAxisDirection() && r2fDetected) || (in.getTriggerCounterAxisDirection() && f2rDetected))
107 std::this_thread::sleep_for(std::chrono::milliseconds{10});