CheckTargetPoseReached.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::CheckTargetPoseReachedGroup
19 * @author [Author Name] ( [Author Email] )
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
29
31
32using namespace armarx;
33using namespace CoupledInteractionGroup;
34
35// DO NOT EDIT NEXT LINE
36CheckTargetPoseReached::SubClassRegistry
39
42 CheckTargetPoseReachedGeneratedBase<CheckTargetPoseReached>(stateData)
43{
44}
45
46bool
48 FramedDirectionPtr refForces,
49 FramedDirectionPtr refTorques,
50 float forceThreshhold,
51 float torqueThreshhold)
52{
54 getContext<CoupledInteractionGroupStatechartContext>();
55 ARMARX_INFO << "here stop" << tcpName;
56 DatafieldRefPtr force = DatafieldRefPtr::dynamicCast(
57 context->getForceTorqueUnitObserver()->getForceDatafield(tcpName));
58 DatafieldRefPtr torque = DatafieldRefPtr::dynamicCast(
59 context->getForceTorqueUnitObserver()->getTorqueDatafield(tcpName));
60 ARMARX_INFO << "here stop";
61 FramedDirectionPtr curForce = force->getDataField()->get<FramedDirection>();
62 ARMARX_INFO << "here stop1";
63 curForce = FramedDirection::ChangeFrame(context->getRobot(), *curForce, "Armar3_Base");
64 ARMARX_INFO << "here stop2";
65 FramedDirectionPtr curTorque = torque->getDataField()->get<FramedDirection>();
66 curTorque = FramedDirection::ChangeFrame(context->getRobot(), *curTorque, "Armar3_Base");
67
68 float deviationForce = (curForce->toEigen() - refForces->toEigen()).norm();
69 float deviationTorque = (curTorque->toEigen() - refTorques->toEigen()).norm();
70 ARMARX_INFO << "dev Force Torque " << deviationForce << " " << deviationTorque;
71
72 if (deviationForce > forceThreshhold && deviationTorque > torqueThreshhold)
73 {
74 return true;
75 }
76
77 return false;
78}
79
80void
82{
83 //TODO implement check Get final Target
84 //get current
85 //check
86 Eigen::Vector3f platformPose;
88 getContext<CoupledInteractionGroupStatechartContext>();
89 armarx::ChannelRefPtr poseRef =
90 context->getChannelRef(context->getPlatformUnitObserverName(), "platformPose");
91 platformPose(0) = poseRef->getDataField("positionX")->getFloat();
92 platformPose(1) = poseRef->getDataField("positionY")->getFloat();
93 platformPose(2) = poseRef->getDataField("rotation")->getFloat();
94 FramedDirectionPtr tableTargetPose = in.getTableTargetPose();
95 float distance =
96 sqrt((platformPose(0) - tableTargetPose->x) * (platformPose(0) - tableTargetPose->x) +
97 (platformPose(1) - tableTargetPose->y) * (platformPose(1) - tableTargetPose->y));
98 float angleDistance = fabs(platformPose(2) - tableTargetPose->z);
99 ARMARX_INFO << "Distance in CheckTargetPoseReached " << distance << " " << angleDistance;
100 ARMARX_INFO << "Robot Pose " << platformPose(0) << " " << platformPose(1) << " "
101 << platformPose(2);
102 ARMARX_INFO << "Target Pose " << tableTargetPose->x << " " << tableTargetPose->y << " "
103 << tableTargetPose->z;
104 float distancetravelled = sqrt(
105 (platformPose(0) - in.getInitialPose()->x) * (platformPose(0) - in.getInitialPose()->x) +
106 (platformPose(1) - in.getInitialPose()->y) * (platformPose(1) - in.getInitialPose()->y));
107 ARMARX_INFO << "Distance travelled " << distancetravelled;
108 std::string leftTcpName("TCP L");
109 std::string rightTcpName("TCP R");
110 Eigen::Vector3f nullVec;
111 nullVec << 0, 0, 0;
112 FramedDirectionPtr refForce = new FramedDirection(nullVec, "Armar3_Base", "Armar3");
113 FramedDirectionPtr refTorque = new FramedDirection(nullVec, "Armar3_Base", "Armar3");
114
115 if (checkForceTorqueExceeded(leftTcpName, refForce, refTorque, 8.0, 0.0) ||
116 checkForceTorqueExceeded(rightTcpName, refForce, refTorque, 12.0, 0.0))
117 {
118 PlatformUnitInterfacePrx platformPrx = context->getPlatformUnitProxy();
119 //platformPrx->move(tableTargetPose(0,3),relativeTarget(0),relativeTarget(1),relativeTarget(2));
120 platformPrx->move(0, 0, 0);
121
122 // If the platform didn't move too much, we emit a special signal (push affordance not verified)
123 Eigen::Vector3f initial = in.getInitialPose()->toEigen();
124 ARMARX_INFO << "Initial platform pose: " << initial;
125 ARMARX_INFO << "Current platform pose: " << platformPose;
126 ARMARX_INFO << "Distance travelled: " << (initial - platformPose).norm();
127
128 if ((initial - platformPose).norm() < 500)
129 {
130 emitEvForcesTooHighNotReached();
131 }
132
133 emitEvTargetPoseReached();
134 }
135 else
136 {
137 emitEvTargetPoseNotReached();
138 }
139}
140
141void
143{
144 // put your user code for the execution-phase here
145 // runs in seperate thread, thus can do complex operations
146 // should check constantly whether isRunningTaskStopped() returns true
147}
148
149void
151{
152 // put your user code for the breaking point here
153 // execution time should be short (<100ms)
154}
155
156void
158{
159
161 getContext<CoupledInteractionGroupStatechartContext>();
162 context->getTCPControlUnit()->release();
163 // put your user code for the exit point here
164 // execution time should be short (<100ms)
165}
166
167// DO NOT EDIT NEXT FUNCTION
168std::string
170{
171 return "CheckTargetPoseReached";
172}
173
174// DO NOT EDIT NEXT FUNCTION
bool checkForceTorqueExceeded(std::string tcpName, FramedDirectionPtr refForces, FramedDirectionPtr refTorques, float forceThreshhold, float torqueThreshhold)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotConstPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
ChannelRefPtr getChannelRef(const std::string &observerName, const std::string &channelName) override
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< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
float angleDistance(float angle1, float angle2)
double norm(const Point &a)
Definition point.hpp:102
double distance(const Point &a, const Point &b)
Definition point.hpp:95