WaitForForce.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2014-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotSkillTemplates::ForceControlGroup
19 * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "WaitForForce.h"
26
28
29#include <RobotSkillTemplates/statecharts/ForceControlGroup/ForceControlGroupStatechartContext.generated.h>
30
31using namespace armarx;
32using namespace ForceControlGroup;
33
34// DO NOT EDIT NEXT LINE
35WaitForForce::SubClassRegistry WaitForForce::Registry(WaitForForce::GetName(),
37
39 XMLStateTemplate<WaitForForce>(stateData), WaitForForceGeneratedBase<WaitForForce>(stateData)
40{
41}
42
43void
45{
46 // put your user code for the enter-point here
47 // execution time should be short (<100ms)
48
49 TimeUtil::MSSleep(in.getDelay());
50
51 ForceControlGroupStatechartContext* c = getContext<ForceControlGroupStatechartContext>();
52 DatafieldRefBasePtr rawforce;
53 DatafieldRefBasePtr rawtorque;
54 DatafieldRefBasePtr force;
55 DatafieldRefBasePtr torque;
56 if (in.isObserverSensorChannelNameSet())
57 {
58 rawforce = c->getForceTorqueObserver()->getDataFieldRef(
59 new DataFieldIdentifier(c->getForceTorqueObserver()->getObserverName(),
60 in.getObserverSensorChannelName(),
61 "forces"));
62 rawtorque = c->getForceTorqueObserver()->getDataFieldRef(
63 new DataFieldIdentifier(c->getForceTorqueObserver()->getObserverName(),
64 in.getObserverSensorChannelName(),
65 "torques"));
66 }
67 else if (in.isSensorNameSet())
68 {
69 std::string sensor = in.getSensorName();
70
71 rawforce = c->getForceTorqueObserver()->getForceDatafield(sensor);
72 rawtorque = c->getForceTorqueObserver()->getTorqueDatafield(sensor);
73 }
74
75 else
76 {
77 throw LocalException() << "Either SensorName or ObserverSensorChannelName must be set!";
78 }
79 force = c->getForceTorqueObserver()->createNulledDatafield(rawforce);
80 torque = c->getForceTorqueObserver()->createNulledDatafield(rawtorque);
81
82 local.setforceRef(DatafieldRefPtr::dynamicCast(force));
83 local.settorqueRef(DatafieldRefPtr::dynamicCast(torque));
84 ARMARX_IMPORTANT << "Installing force torque condition: force threshold: "
85 << in.getForceMagnitudeThreshold()
86 << " torque threshold: " << in.getTorqueMagnitudeThreshold();
87 Literal literalForce(
88 force, "magnitudelarger", Literal::createParameterList(in.getForceMagnitudeThreshold()));
89 Literal literalTorque(
90 torque, "magnitudelarger", Literal::createParameterList(in.getTorqueMagnitudeThreshold()));
91 installConditionForForceTorqueThresholdReached(literalForce || literalTorque);
92}
93
94void
96{
97 while (!isRunningTaskStopped())
98 {
99 ARMARX_INFO << deactivateSpam(0.5) << "Current force value: "
100 << local.getforceRef()->getDataField()->get<FramedDirection>()->toEigen().norm()
101 << " threshold: " << in.getForceMagnitudeThreshold();
103 }
104}
105
106void
108{
109 // put your user code for the exit point here
110 // execution time should be short (<100ms)
111 ForceControlGroupStatechartContext* c = getContext<ForceControlGroupStatechartContext>();
112 ARMARX_INFO << deactivateSpam(0.5) << "Final force value: "
113 << local.getforceRef()->getDataField()->get<FramedDirection>()->toEigen().norm()
114 << " threshold: " << in.getForceMagnitudeThreshold();
115
116 c->getForceTorqueObserver()->removeFilteredDatafield(local.getforceRef());
117 c->getForceTorqueObserver()->removeFilteredDatafield(local.gettorqueRef());
118}
119
120// DO NOT EDIT NEXT FUNCTION
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
constexpr T c
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
WaitForForce(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
Literals are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:209
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition Term.cpp:142
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)