MoveOnLineUntilContact.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 "MoveOnLineUntilContact.h"
26 
27 using namespace armarx;
28 using namespace ForceControlGroup;
29 
30 #include <RobotAPI/interface/observers/ObserverFilters.h>
31 
32 // DO NOT EDIT NEXT LINE
33 MoveOnLineUntilContact::SubClassRegistry MoveOnLineUntilContact::Registry(MoveOnLineUntilContact::GetName(), &MoveOnLineUntilContact::CreateInstance);
34 
35 
36 
38  XMLStateTemplate < MoveOnLineUntilContact > (stateData), MoveOnLineUntilContactGeneratedBase < MoveOnLineUntilContact > (stateData)
39 {
40 }
41 
43 {
44  // put your user code for the enter-point here
45  // execution time should be short (<100ms)
46  DatafieldRefPtr filteredForceDF;
47  std::string ftSensorName;
48  if (in.isForceSensorDatafieldSet())
49  {
50  filteredForceDF = in.getForceSensorDatafield();
51  }
52  else
53  {
54  if (in.isFTSensorNameSet())
55  {
56  ftSensorName = in.getFTSensorName();
57  }
58  else
59  {
60  ftSensorName = getRobot()->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getName();
61  }
62 
63  DatafieldRefBasePtr forceDF = getForceTorqueObserver()->getForceDatafield(ftSensorName);
64  filteredForceDF = DatafieldRefPtr::dynamicCast(getForceTorqueObserver()->createNulledDatafield(forceDF));
65  }
66  local.setForceRef(filteredForceDF);
67  Literal forceCheck(filteredForceDF->getDataFieldIdentifier(), checks::magnitudelarger, {in.getForceThreshold()});
68  installConditionForHighForceDetected(Term(forceCheck).getImpl(), "Condition for reaching a high force");
69 }
70 
72 {
73  // put your user code for the execution-phase here
74  // runs in seperate thread, thus can do complex operations
75  // should check constantly whether isRunningTaskStopped() returns true
76 
77  // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
78  while (!isRunningTaskStopped()) // stop run function if returning true
79  {
80  ARMARX_INFO << deactivateSpam(0.2) << "measured force: " << local.getForceRef()->get<FramedDirection>()->toEigen().norm() << " " << in.getForceThreshold();
81  }
82 
83 }
84 
85 //void MoveOnLineUntilContact::onBreak()
86 //{
87 // // put your user code for the breaking point here
88 // // execution time should be short (<100ms)
89 //}
90 
92 {
93  // put your user code for the exit point here
94  // execution time should be short (<100ms)
95  ARMARX_INFO << "Final measure force: " << local.getForceRef()->get<FramedDirection>()->toEigen().norm();
96  if (!in.isForceSensorDatafieldSet())
97  {
98  getForceTorqueObserver()->removeFilteredDatafield(local.getForceRef());
99  }
100 }
101 
102 
103 // DO NOT EDIT NEXT FUNCTION
105 {
106  return XMLStateFactoryBasePtr(new MoveOnLineUntilContact(stateData));
107 }
108 
armarx::ForceControlGroup::MoveOnLineUntilContact::MoveOnLineUntilContact
MoveOnLineUntilContact(const XMLStateConstructorParams &stateData)
Definition: MoveOnLineUntilContact.cpp:37
armarx::ForceControlGroup::MoveOnLineUntilContact::Registry
static SubClassRegistry Registry
Definition: MoveOnLineUntilContact.h:45
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::ForceControlGroup::MoveOnLineUntilContact
Definition: MoveOnLineUntilContact.h:31
armarx::ForceControlGroup::MoveOnLineUntilContact::onEnter
void onEnter() override
Definition: MoveOnLineUntilContact.cpp:42
armarx::ForceControlGroup::MoveOnLineUntilContact::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: MoveOnLineUntilContact.cpp:104
MoveOnLineUntilContact.h
armarx::Term
Definition: Term.h:111
IceInternal::Handle< DatafieldRef >
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::ForceControlGroup::MoveOnLineUntilContact::run
void run() override
Definition: MoveOnLineUntilContact.cpp:71
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
armarx::Literal
Definition: Term.h:208
armarx::ForceControlGroup::MoveOnLineUntilContact::onExit
void onExit() override
Definition: MoveOnLineUntilContact.cpp:91
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28