CheckHandForces.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 GraspObject::GraspObjectGroup
19  * @author [Author Name] ( [Author Email] )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "CheckHandForces.h"
26 #include "GraspObjectGroupStatechartContext.generated.h"
27 
28 using namespace armarx;
29 using namespace GraspObjectGroup;
30 
31 // DO NOT EDIT NEXT LINE
32 CheckHandForces::SubClassRegistry CheckHandForces::Registry(CheckHandForces::GetName(), &CheckHandForces::CreateInstance);
33 
34 
35 
37  XMLStateTemplate<CheckHandForces>(stateData), CheckHandForcesGeneratedBase<CheckHandForces>(stateData)
38 {
39 }
40 
42 {
43  GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
44  float maxForceMagnitude = 10.0;
45  Eigen::Matrix4f leftTcpPoseBase = context->getRobot()->getRobotNode(in.getLeftHandName())->getPoseInRootFrame();
46  Eigen::Matrix4f rightTcpPoseBase = context->getRobot()->getRobotNode(in.getRightHandName())->getPoseInRootFrame();
47 
48  if (!in.getLeftHandForceChecked() && !in.getLeftHandClosed())
49  {
50  //ConditionIdentifier condForcesTooHigh;
51  DatafieldRefPtr forceRefLeft = DatafieldRefPtr::dynamicCast(context->getForceTorqueObserver()->getForceDatafield(in.getLeftHandName()));
52  FramedDirectionPtr curForceLeft = forceRefLeft->getDataField()->get<FramedDirection>();
53 
54 
55  Eigen::Vector3f leftHandForces = curForceLeft->toEigen();
56 
57  //Literal forcesTooHigh(DataFieldIdentifier(context->getForceTorqueObserverName(),"Wrist 2 L","forces"), "magnitudelarger", Literal::createParameterList(maxForceMagnitude));
58  if (leftHandForces.norm() > maxForceMagnitude && in.getRightHandClosed())
59  {
60  out.setLeftTcpTargetPoseUpdated(FramedPose(leftTcpPoseBase, "Armar3_Base", "Armar3"));
61  out.setRightTcpTargetPoseUpdated(FramedPose(rightTcpPoseBase, "Armar3_Base", "Armar3"));
62  emitBothHandForceDetected();
63  }
64  else if (leftHandForces.norm() > maxForceMagnitude)
65  {
66  out.setLeftTcpTargetPoseUpdated(FramedPose(leftTcpPoseBase, "Armar3_Base", "Armar3"));
67  out.setRightTcpTargetPoseUpdated(in.getRightTcpTargetPose());
68  emitLeftHandForceDetected();
69  }
70  else
71  {
72  out.setLeftTcpTargetPoseUpdated(in.getLeftTcpTargetPose());
73  out.setRightTcpTargetPoseUpdated(in.getRightTcpTargetPose());
74  emitNoHandForcesDetected();
75  }
76 
77  out.setLeftHandForceChecked(true);
78  out.setRightHandForceChecked(false);
79  //out.setLeftHandClosed(true);
80  }
81  else if (!in.getRightHandForceChecked() && !in.getRightHandClosed())
82  {
83  //ConditionIdentifier condForcesTooHigh;
84  DatafieldRefPtr forceRefRight = DatafieldRefPtr::dynamicCast(context->getForceTorqueObserver()->getForceDatafield(in.getRightHandName()));
85  FramedDirectionPtr curForceRight = forceRefRight->getDataField()->get<FramedDirection>();
86  //Literal forcesTooHigh(DataFieldIdentifier(context->getForceTorqueObserverName(),"Wrist 2 L","forces"), "magnitudelarger", Literal::createParameterList(maxForceMagnitude));
87  //condForcesTooHigh = installCondition(forcesTooHigh, createEvent<RightHandForceDetected>());
88 
89  Eigen::Vector3f rightHandForces = curForceRight->toEigen();
90 
91  //Literal forcesTooHigh(DataFieldIdentifier(context->getForceTorqueObserverName(),"Wrist 2 L","forces"), "magnitudelarger", Literal::createParameterList(maxForceMagnitude));
92  if (rightHandForces.norm() > maxForceMagnitude && in.getLeftHandClosed())
93  {
94  out.setRightTcpTargetPoseUpdated(FramedPose(rightTcpPoseBase, "Armar3_Base", "Armar3"));
95  out.setLeftTcpTargetPoseUpdated(FramedPose(leftTcpPoseBase, "Armar3_Base", "Armar3"));
96  emitBothHandForceDetected();
97  }
98  else if (rightHandForces.norm() > maxForceMagnitude)
99  {
100  out.setRightTcpTargetPoseUpdated(FramedPose(rightTcpPoseBase, "Armar3_Base", "Armar3"));
101  out.setLeftTcpTargetPoseUpdated(in.getLeftTcpTargetPose());
102  emitRightHandForceDetected();
103  }
104  else
105  {
106  out.setRightTcpTargetPoseUpdated(in.getRightTcpTargetPose());
107  out.setLeftTcpTargetPoseUpdated(in.getLeftTcpTargetPose());
108  emitNoHandForcesDetected();
109  }
110 
111  out.setLeftHandForceChecked(false);
112  out.setRightHandForceChecked(true);
113  //out.setRightHandClosed(true);
114  }
115  else
116  {
117  out.setLeftHandForceChecked(false);
118  out.setRightHandForceChecked(false);
119  }
120 
121 }
122 
124 {
125  // put your user code for the execution-phase here
126  // runs in seperate thread, thus can do complex operations
127  // should check constantly whether isRunningTaskStopped() returns true
128 
129  // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
130  // while (!isRunningTaskStopped()) // stop run function if returning true
131  // {
132  // // do your calculations
133  // }
134 
135 }
136 
138 {
139  // put your user code for the breaking point here
140  // execution time should be short (<100ms)
141 }
142 
144 {
145  // put your user code for the exit point here
146  // execution time should be short (<100ms)
147 
148 }
149 
150 
151 // DO NOT EDIT NEXT FUNCTION
153 {
154  return XMLStateFactoryBasePtr(new CheckHandForces(stateData));
155 }
156 
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
armarx::GraspObjectGroup::CheckHandForces::onBreak
void onBreak() override
Definition: CheckHandForces.cpp:137
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::GraspObjectGroup::CheckHandForces::run
void run() override
Definition: CheckHandForces.cpp:123
armarx::GraspObjectGroup::CheckHandForces::CheckHandForces
CheckHandForces(const XMLStateConstructorParams &stateData)
Definition: CheckHandForces.cpp:36
armarx::GraspObjectGroup::CheckHandForces::onEnter
void onEnter() override
Definition: CheckHandForces.cpp:41
IceInternal::Handle< DatafieldRef >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::GraspObjectGroup::CheckHandForces::onExit
void onExit() override
Definition: CheckHandForces.cpp:143
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:83
armarx::GraspObjectGroup::CheckHandForces::Registry
static SubClassRegistry Registry
Definition: CheckHandForces.h:45
CheckHandForces.h
armarx::GraspObjectGroup::CheckHandForces::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CheckHandForces.cpp:152
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::GraspObjectGroup::CheckHandForces
Definition: CheckHandForces.h:31