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 "DetectForceFlank.h"
24
25#include <thread>
26
28
29using namespace armarx;
30using namespace ForceTorqueUtility;
31
32// DO NOT EDIT NEXT LINE
33DetectForceFlank::SubClassRegistry DetectForceFlank::Registry(DetectForceFlank::GetName(),
35
36void
38{
39 ARMARX_CHECK_EXPRESSION(in.getTriggerOnDecreasingForceVectorLength() ||
40 in.getTriggerOnIncreasingForceVectorLength());
41
42 const float forceThreshold = in.getForceVectorLengthThreshold();
43 DatafieldRefPtr forceDf = DatafieldRefPtr::dynamicCast(
44 getForceTorqueObserver()->getForceDatafield(in.getFTDatafieldName()));
45 const Eigen::Vector3f weights = in.getForceWeights()->toEigen();
46 const float initialForce =
47 forceDf->getDataField()->get<FramedDirection>()->toEigen().cwiseProduct(weights).norm();
48
49 while (!isRunningTaskStopped()) // stop run function if returning true
50 {
51
52 const float force =
53 forceDf->getDataField()->get<FramedDirection>()->toEigen().cwiseProduct(weights).norm();
54 ARMARX_INFO << deactivateSpam(1) << VAROUT(force) << " " << VAROUT(initialForce);
55 if ((in.getTriggerOnDecreasingForceVectorLength() && force < initialForce &&
56 initialForce - force >= forceThreshold) ||
57 (in.getTriggerOnIncreasingForceVectorLength() && force > initialForce &&
58 force - initialForce >= forceThreshold))
59 {
60 emitSuccess();
61 return;
62 }
63 std::this_thread::sleep_for(std::chrono::milliseconds{10});
64 }
65 emitFailure();
66}
67
68// DO NOT EDIT NEXT FUNCTION
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
#define VAROUT(x)
DetectForceFlank(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)