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