MoveToPlacePose.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::PlaceObjectGroup
19 * @author David ( david dot schiebener 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 "MoveToPlacePose.h"
26
28
29#include <RobotAPI/interface/observers/ObserverFilters.h>
30
32
33using namespace armarx;
34using namespace PlaceObjectGroup;
35
36// DO NOT EDIT NEXT LINE
37MoveToPlacePose::SubClassRegistry MoveToPlacePose::Registry(MoveToPlacePose::GetName(),
39
42 MoveToPlacePoseGeneratedBase<MoveToPlacePose>(stateData)
43{
44}
45
46void
48{
49 PlaceObjectGroupStatechartContextBase* context =
50 getContext<PlaceObjectGroupStatechartContextBase>();
51 local.setStartTimeRef(ChannelRefPtr::dynamicCast(
52 context->getSystemObserver()->startTimer("MoveToPlacePoseStartTime")));
53
54 ARMARX_VERBOSE << VAROUT(in.getForceSensorDatafieldName());
55 local.setForceDatafield(
56 DatafieldRefPtr::dynamicCast(getForceTorqueObserver()->createNulledDatafield(
57 getForceTorqueObserver()->getForceDatafield(in.getForceSensorDatafieldName()))));
58
59 ARMARX_VERBOSE << VAROUT(in.getForceThreshold());
60 Literal forceCheck(local.getForceDatafield()->getDataFieldIdentifier(),
61 checks::magnitudelarger,
62 {(float)in.getForceThreshold()});
63
64 installConditionForHighForceDetected(forceCheck);
65 context->getTCPControlUnit()->request();
66}
67
68void
70{
71 while (!isRunningTaskStopped())
72 {
73 ARMARX_INFO << deactivateSpam(0.2) << "Current force: "
74 << local.getForceDatafield()->get<FramedDirection>()->toEigen().norm()
75 << " Threshold: " << in.getForceThreshold();
77 }
78}
79
80void
82{
83 // put your user code for the exit point here
84 // execution time should be short (<100ms)
85 // Not working
86 // if(getTriggeredEndstateEvent() && getTriggeredEndstateEvent()->eventName == createEventHighForceDetected()->eventName)
87 // {
88 // ARMARX_WARNING << "High force detected: " << local.getForceDatafield()->get<FramedDirection>()->toEigen().norm();
89 // }
90 // else
91 {
92 ARMARX_INFO << "Force at end: "
93 << local.getForceDatafield()->get<FramedDirection>()->toEigen().norm();
94 }
95
96 getForceTorqueObserver()->removeFilteredDatafield(local.getForceDatafield());
97 PlaceObjectGroupStatechartContextBase* context =
98 getContext<PlaceObjectGroupStatechartContextBase>();
99 context->getTCPControlUnit()->release();
100 context->getSystemObserver()->removeTimer(local.getStartTimeRef());
101
102 auto retreatPose = in.getRetreatPose();
103 retreatPose->changeToGlobal(getRobot());
104 retreatPose->position->z += 100;
105 out.setRetreatPose(retreatPose);
106
107 auto instances =
108 context->getWorkingMemory()->getObjectInstancesSegment()->getObjectInstancesByClass(
109 in.getObjectClassName());
110
111 if (instances.size() > 0)
112 {
113 memoryx::ObjectInstanceBasePtr obj = instances.front();
115
117 new memoryx::MotionModelStaticObject(context->getRobotStateComponent());
118 getWorkingMemory()->getObjectInstancesSegment()->setNewMotionModel(obj->getId(),
119 newMotionModel);
120 auto pose = in.getObjectTargetPose();
121 pose->changeFrame(context->getRobot(), context->getRobot()->getRootNode()->getName());
122 getWorkingMemory()->getObjectInstancesSegment()->setObjectPose(
123 obj->getId(),
124 new LinkedPose(pose->toEigen(),
125 pose->getFrame(),
126 context->getRobotStateComponent()->getRobotSnapshot(
127 context->getRobot()->getName())));
128 ARMARX_INFO << "Setting object in WM to pose: " << *in.getObjectTargetPose();
129 }
130 else
131 {
133 << "No object instance with name '" << in.getObjectClassName()
134 << "' found! Could not change working memory position and motion model of object.";
135 }
136}
137
138// 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)
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
The LinkedPose class.
Definition LinkedPose.h:61
Literals are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:209
MoveToPlacePose(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
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_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
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
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)
IceInternal::Handle< MotionModelStaticObject > MotionModelStaticObjectPtr