DetectForceFlank.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ForceTorqueUtility
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include <thread>
24 
26 
27 #include "DetectForceFlank.h"
28 
29 using namespace armarx;
30 using namespace ForceTorqueUtility;
31 
32 // DO NOT EDIT NEXT LINE
33 DetectForceFlank::SubClassRegistry DetectForceFlank::Registry(DetectForceFlank::GetName(), &DetectForceFlank::CreateInstance);
34 
36 {
37  ARMARX_CHECK_EXPRESSION(in.getTriggerOnDecreasingForceVectorLength() || in.getTriggerOnIncreasingForceVectorLength());
38 
39  const float forceThreshold = in.getForceVectorLengthThreshold();
40  DatafieldRefPtr forceDf = DatafieldRefPtr::dynamicCast(getForceTorqueObserver()->getForceDatafield(in.getFTDatafieldName()));
41  const Eigen::Vector3f weights = in.getForceWeights()->toEigen();
42  const float initialForce = forceDf->getDataField()->get<FramedDirection>()->toEigen().cwiseProduct(weights).norm();
43 
44  while (!isRunningTaskStopped()) // stop run function if returning true
45  {
46 
47  const float force = forceDf->getDataField()->get<FramedDirection>()->toEigen().cwiseProduct(weights).norm();
48  ARMARX_INFO << deactivateSpam(1) << VAROUT(force) << " " << VAROUT(initialForce);
49  if (
50  (
51  in.getTriggerOnDecreasingForceVectorLength() &&
52  force < initialForce &&
53  initialForce - force >= forceThreshold
54  ) ||
55  (
56  in.getTriggerOnIncreasingForceVectorLength() &&
57  force > initialForce &&
58  force - initialForce >= forceThreshold
59  )
60  )
61  {
62  emitSuccess();
63  return;
64  }
65  std::this_thread::sleep_for(std::chrono::milliseconds{10});
66  }
67  emitFailure();
68 }
69 
70 
71 // DO NOT EDIT NEXT FUNCTION
73 {
74  return XMLStateFactoryBasePtr(new DetectForceFlank(stateData));
75 }
76 
armarx::ForceTorqueUtility::DetectForceFlank::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DetectForceFlank.cpp:72
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
DetectForceFlank.h
IceInternal::Handle< DatafieldRef >
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::ForceTorqueUtility::DetectForceFlank::DetectForceFlank
DetectForceFlank(const XMLStateConstructorParams &stateData)
Definition: DetectForceFlank.h:32
FramedPose.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:83
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ForceTorqueUtility::DetectForceFlank::run
void run() override
Definition: DetectForceFlank.cpp:35
armarx::ForceTorqueUtility::DetectForceFlank::Registry
static SubClassRegistry Registry
Definition: DetectForceFlank.h:44