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 
25 #include "CheckTargetPoseReached.h"
26 
29 
31 
32 using namespace armarx;
33 using namespace CoupledInteractionGroup;
34 
35 // DO NOT EDIT NEXT LINE
36 CheckTargetPoseReached::SubClassRegistry
39 
42  CheckTargetPoseReachedGeneratedBase<CheckTargetPoseReached>(stateData)
43 {
44 }
45 
46 bool
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 
80 void
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 
141 void
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 
149 void
151 {
152  // put your user code for the breaking point here
153  // execution time should be short (<100ms)
154 }
155 
156 void
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
168 std::string
170 {
171  return "CheckTargetPoseReached";
172 }
173 
174 // DO NOT EDIT NEXT FUNCTION
177 {
178  return XMLStateFactoryBasePtr(new CheckTargetPoseReached(stateData));
179 }
RemoteRobot.h
armarx::CoupledInteractionGroup::CheckTargetPoseReached::checkForceTorqueExceeded
bool checkForceTorqueExceeded(std::string tcpName, FramedDirectionPtr refForces, FramedDirectionPtr refTorques, float forceThreshhold, float torqueThreshhold)
Definition: CheckTargetPoseReached.cpp:47
armarx::angleDistance
float angleDistance(float angle1, float angle2)
Definition: BasicControllers.h:163
armarx::CoupledInteractionGroup::CheckTargetPoseReached::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CheckTargetPoseReached.cpp:176
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getPlatformUnitProxy
PlatformUnitInterfacePrx getPlatformUnitProxy()
Definition: CoupledInteractionGroupStatechartContext.h:187
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getForceTorqueUnitObserver
ForceTorqueUnitObserverInterfacePrx getForceTorqueUnitObserver()
Definition: CoupledInteractionGroupStatechartContext.h:221
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::CoupledInteractionGroup::CheckTargetPoseReached::Registry
static SubClassRegistry Registry
Definition: CheckTargetPoseReached.h:56
armarx::CoupledInteractionGroup::CheckTargetPoseReached
Definition: CheckTargetPoseReached.h:37
armarx::StatechartContext::getChannelRef
ChannelRefPtr getChannelRef(const std::string &observerName, const std::string &channelName) override
Definition: StatechartContext.cpp:152
CheckTargetPoseReached.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::CoupledInteractionGroup::CheckTargetPoseReached::onBreak
void onBreak() override
Definition: CheckTargetPoseReached.cpp:150
IceInternal::Handle< FramedDirection >
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getRobot
const VirtualRobot::RobotPtr getRobot()
Definition: CoupledInteractionGroupStatechartContext.h:133
DatafieldRef.h
armarx::FramedDirection::ChangeFrame
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
Definition: FramedPose.cpp:91
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getPlatformUnitObserverName
std::string getPlatformUnitObserverName()
Definition: CoupledInteractionGroupStatechartContext.h:207
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::CoupledInteractionGroup::CheckTargetPoseReached::run
void run() override
Definition: CheckTargetPoseReached.cpp:142
armarx::CoupledInteractionGroup::CheckTargetPoseReached::CheckTargetPoseReached
CheckTargetPoseReached(XMLStateConstructorParams stateData)
Definition: CheckTargetPoseReached.cpp:40
armarx::CoupledInteractionGroup::CheckTargetPoseReached::GetName
static std::string GetName()
Definition: CheckTargetPoseReached.cpp:169
armarx::CoupledInteractionGroup::CheckTargetPoseReached::onExit
void onExit() override
Definition: CheckTargetPoseReached.cpp:157
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:704
armarx::channels::PlatformUnitObserver::platformPose
const PlatformUnitDatafieldCreator platformPose("platformPose")
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getTCPControlUnit
TCPControlUnitInterfacePrx getTCPControlUnit()
Definition: CoupledInteractionGroupStatechartContext.h:157
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:86
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:37
armarx::Vector3::toEigen
virtual Eigen::Vector3f toEigen() const
Definition: Pose.cpp:134
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:118
armarx::CoupledInteractionGroup::CheckTargetPoseReached::onEnter
void onEnter() override
Definition: CheckTargetPoseReached.cpp:81
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:95
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ChannelRef.h
norm
double norm(const Point &a)
Definition: point.hpp:102