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