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
26#include <VirtualRobot/RobotNodeSet.h>
27
28using namespace armarx;
29using namespace ForceControlGroup;
30
31#include <RobotAPI/interface/observers/ObserverFilters.h>
32
33// DO NOT EDIT NEXT LINE
34MoveOnLineUntilContact::SubClassRegistry
35 MoveOnLineUntilContact::Registry(MoveOnLineUntilContact::GetName(),
37
40 MoveOnLineUntilContactGeneratedBase<MoveOnLineUntilContact>(stateData)
41{
42}
43
44void
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
79void
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
101void
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
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
MoveOnLineUntilContact(const 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
Terms are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:112
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#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)