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 #include <RobotAPI/interface/observers/ObserverFilters.h>
29 
30 using namespace armarx;
31 using namespace PlaceObjectGroup;
32 
33 // DO NOT EDIT NEXT LINE
34 MoveToPlacePose::SubClassRegistry MoveToPlacePose::Registry(MoveToPlacePose::GetName(), &MoveToPlacePose::CreateInstance);
35 
36 
37 
39  XMLStateTemplate<MoveToPlacePose>(stateData), MoveToPlacePoseGeneratedBase<MoveToPlacePose>(stateData)
40 {
41 }
42 
44 {
45  PlaceObjectGroupStatechartContextBase* context = getContext<PlaceObjectGroupStatechartContextBase>();
46  local.setStartTimeRef(ChannelRefPtr::dynamicCast(context->getSystemObserver()->startTimer("MoveToPlacePoseStartTime")));
47 
48  ARMARX_VERBOSE << VAROUT(in.getForceSensorDatafieldName());
49  local.setForceDatafield(DatafieldRefPtr::dynamicCast(getForceTorqueObserver()->createNulledDatafield(getForceTorqueObserver()->getForceDatafield(in.getForceSensorDatafieldName()))));
50 
51  ARMARX_VERBOSE << VAROUT(in.getForceThreshold());
52  Literal forceCheck(local.getForceDatafield()->getDataFieldIdentifier(), checks::magnitudelarger, {(float)in.getForceThreshold()});
53 
54  installConditionForHighForceDetected(forceCheck);
55  context->getTCPControlUnit()->request();
56 }
57 
59 {
60  while (!isRunningTaskStopped())
61  {
62  ARMARX_INFO << deactivateSpam(0.2) << "Current force: " << local.getForceDatafield()->get<FramedDirection>()->toEigen().norm() << " Threshold: " << in.getForceThreshold();
64  }
65 }
66 
67 
68 
70 {
71  // put your user code for the exit point here
72  // execution time should be short (<100ms)
73  // Not working
74  // if(getTriggeredEndstateEvent() && getTriggeredEndstateEvent()->eventName == createEventHighForceDetected()->eventName)
75  // {
76  // ARMARX_WARNING << "High force detected: " << local.getForceDatafield()->get<FramedDirection>()->toEigen().norm();
77  // }
78  // else
79  {
80  ARMARX_INFO << "Force at end: " << local.getForceDatafield()->get<FramedDirection>()->toEigen().norm();
81  }
82 
83  getForceTorqueObserver()->removeFilteredDatafield(local.getForceDatafield());
84  PlaceObjectGroupStatechartContextBase* context = getContext<PlaceObjectGroupStatechartContextBase>();
85  context->getTCPControlUnit()->release();
86  context->getSystemObserver()->removeTimer(local.getStartTimeRef());
87 
88  auto retreatPose = in.getRetreatPose();
89  retreatPose->changeToGlobal(getRobot());
90  retreatPose->position->z += 100;
91  out.setRetreatPose(retreatPose);
92 
93  auto instances = context->getWorkingMemory()->getObjectInstancesSegment()->getObjectInstancesByClass(in.getObjectClassName());
94 
95  if (instances.size() > 0)
96  {
97  memoryx::ObjectInstanceBasePtr obj = instances.front();
99 
100  memoryx::MotionModelStaticObjectPtr newMotionModel = new memoryx::MotionModelStaticObject(context->getRobotStateComponent());
101  getWorkingMemory()->getObjectInstancesSegment()->setNewMotionModel(obj->getId(), newMotionModel);
102  auto pose = in.getObjectTargetPose();
103  pose->changeFrame(context->getRobot(), context->getRobot()->getRootNode()->getName());
104  getWorkingMemory()->getObjectInstancesSegment()->setObjectPose(obj->getId(),
105  new LinkedPose(pose->toEigen(), pose->getFrame(),
106  context->getRobotStateComponent()->getRobotSnapshot(context->getRobot()->getName())));
107  ARMARX_INFO << "Setting object in WM to pose: " << *in.getObjectTargetPose();
108  }
109  else
110  {
111  ARMARX_WARNING << "No object instance with name '" << in.getObjectClassName() << "' found! Could not change working memory position and motion model of object.";
112  }
113 
114 }
115 
116 
117 // DO NOT EDIT NEXT FUNCTION
119 {
120  return XMLStateFactoryBasePtr(new MoveToPlacePose(stateData));
121 }
122 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
MoveToPlacePose.h
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
armarx::PlaceObjectGroup::MoveToPlacePose::Registry
static SubClassRegistry Registry
Definition: MoveToPlacePose.h:44
armarx::PlaceObjectGroup::MoveToPlacePose::run
void run() override
Definition: MoveToPlacePose.cpp:58
armarx::TimeUtil::MSSleep
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition: TimeUtil.cpp:94
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::PlaceObjectGroup::MoveToPlacePose::MoveToPlacePose
MoveToPlacePose(const XMLStateConstructorParams &stateData)
Definition: MoveToPlacePose.cpp:38
armarx::PlaceObjectGroup::MoveToPlacePose::onEnter
void onEnter() override
Definition: MoveToPlacePose.cpp:43
IceInternal::Handle
Definition: forward_declarations.h:8
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::PlaceObjectGroup::MoveToPlacePose::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: MoveToPlacePose.cpp:118
MotionModelStaticObject.h
memoryx::MotionModelStaticObject
Definition: MotionModelStaticObject.h:34
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
TimeUtil.h
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::PlaceObjectGroup::MoveToPlacePose
Definition: MoveToPlacePose.h:31
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::Literal
Definition: Term.h:208
armarx::LinkedPose
The LinkedPose class.
Definition: LinkedPose.h:60
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PlaceObjectGroup::MoveToPlacePose::onExit
void onExit() override
Definition: MoveToPlacePose.cpp:69
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28