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"
29 
30 using namespace armarx;
31 using namespace CoupledInteractionGroup;
32 
33 // DO NOT EDIT NEXT LINE
35 
36 
37 
39  XMLStateTemplate < CheckTargetPoseReached > (stateData), CheckTargetPoseReachedGeneratedBase < CheckTargetPoseReached > (stateData)
40 {
41 }
42 
43 bool CheckTargetPoseReached::checkForceTorqueExceeded(std::string tcpName, FramedDirectionPtr refForces, FramedDirectionPtr refTorques, float forceThreshhold, float torqueThreshhold)
44 {
45  CoupledInteractionGroupStatechartContext* context = getContext<CoupledInteractionGroupStatechartContext>();
46  ARMARX_INFO << "here stop" << tcpName;
47  DatafieldRefPtr force = DatafieldRefPtr::dynamicCast(context->getForceTorqueUnitObserver()->getForceDatafield(tcpName));
48  DatafieldRefPtr torque = DatafieldRefPtr::dynamicCast(context->getForceTorqueUnitObserver()->getTorqueDatafield(tcpName));
49  ARMARX_INFO << "here stop";
50  FramedDirectionPtr curForce = force->getDataField()->get<FramedDirection>();
51  ARMARX_INFO << "here stop1";
52  curForce = FramedDirection::ChangeFrame(context->getRobot(), *curForce, "Armar3_Base");
53  ARMARX_INFO << "here stop2";
54  FramedDirectionPtr curTorque = torque->getDataField()->get<FramedDirection>();
55  curTorque = FramedDirection::ChangeFrame(context->getRobot(), *curTorque, "Armar3_Base");
56 
57  float deviationForce = (curForce->toEigen() - refForces->toEigen()).norm();
58  float deviationTorque = (curTorque->toEigen() - refTorques->toEigen()).norm();
59  ARMARX_INFO << "dev Force Torque " << deviationForce << " " << deviationTorque;
60 
61  if (deviationForce > forceThreshhold && deviationTorque > torqueThreshhold)
62  {
63  return true;
64  }
65 
66  return false;
67 
68 }
69 
71 {
72  //TODO implement check Get final Target
73  //get current
74  //check
75  Eigen::Vector3f platformPose;
76  CoupledInteractionGroupStatechartContext* context = getContext<CoupledInteractionGroupStatechartContext>();
77  armarx::ChannelRefPtr poseRef = context->getChannelRef(context->getPlatformUnitObserverName(), "platformPose");
78  platformPose(0) = poseRef->getDataField("positionX")->getFloat();
79  platformPose(1) = poseRef->getDataField("positionY")->getFloat();
80  platformPose(2) = poseRef->getDataField("rotation")->getFloat();
81  FramedDirectionPtr tableTargetPose = in.getTableTargetPose();
82  float distance = sqrt((platformPose(0) - tableTargetPose->x) * (platformPose(0) - tableTargetPose->x) + (platformPose(1) - tableTargetPose->y) * (platformPose(1) - tableTargetPose->y));
83  float angleDistance = fabs(platformPose(2) - tableTargetPose->z);
84  ARMARX_INFO << "Distance in CheckTargetPoseReached " << distance << " " << angleDistance;
85  ARMARX_INFO << "Robot Pose " << platformPose(0) << " " << platformPose(1) << " " << platformPose(2);
86  ARMARX_INFO << "Target Pose " << tableTargetPose->x << " " << tableTargetPose->y << " " << tableTargetPose->z;
87  float distancetravelled = sqrt((platformPose(0) - in.getInitialPose()->x) * (platformPose(0) - in.getInitialPose()->x) + (platformPose(1) - in.getInitialPose()->y) * (platformPose(1) - in.getInitialPose()->y));
88  ARMARX_INFO << "Distance travelled " << distancetravelled;
89  std::string leftTcpName("TCP L");
90  std::string rightTcpName("TCP R");
91  Eigen::Vector3f nullVec;
92  nullVec << 0, 0, 0;
93  FramedDirectionPtr refForce = new FramedDirection(nullVec, "Armar3_Base", "Armar3");
94  FramedDirectionPtr refTorque = new FramedDirection(nullVec, "Armar3_Base", "Armar3");
95 
96  if (checkForceTorqueExceeded(leftTcpName, refForce, refTorque, 8.0, 0.0) ||
97  checkForceTorqueExceeded(rightTcpName, refForce, refTorque, 12.0, 0.0))
98  {
99  PlatformUnitInterfacePrx platformPrx = context->getPlatformUnitProxy();
100  //platformPrx->move(tableTargetPose(0,3),relativeTarget(0),relativeTarget(1),relativeTarget(2));
101  platformPrx->move(0, 0, 0);
102 
103  // If the platform didn't move too much, we emit a special signal (push affordance not verified)
104  Eigen::Vector3f initial = in.getInitialPose()->toEigen();
105  ARMARX_INFO << "Initial platform pose: " << initial;
106  ARMARX_INFO << "Current platform pose: " << platformPose;
107  ARMARX_INFO << "Distance travelled: " << (initial - platformPose).norm();
108 
109  if ((initial - platformPose).norm() < 500)
110  {
111  emitEvForcesTooHighNotReached();
112  }
113 
114  emitEvTargetPoseReached();
115  }
116  else
117  {
118  emitEvTargetPoseNotReached();
119  }
120 }
121 
123 {
124  // put your user code for the execution-phase here
125  // runs in seperate thread, thus can do complex operations
126  // should check constantly whether isRunningTaskStopped() returns true
127 
128 }
129 
131 {
132  // put your user code for the breaking point here
133  // execution time should be short (<100ms)
134 }
135 
137 {
138 
139  CoupledInteractionGroupStatechartContext* context = getContext<CoupledInteractionGroupStatechartContext>();
140  context->getTCPControlUnit()->release();
141  // put your user code for the exit point here
142  // execution time should be short (<100ms)
143 
144 }
145 
146 // DO NOT EDIT NEXT FUNCTION
148 {
149  return "CheckTargetPoseReached";
150 }
151 
152 // DO NOT EDIT NEXT FUNCTION
154 {
155  return XMLStateFactoryBasePtr(new CheckTargetPoseReached(stateData));
156 }
157 
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
RemoteRobot.h
armarx::CoupledInteractionGroup::CheckTargetPoseReached::checkForceTorqueExceeded
bool checkForceTorqueExceeded(std::string tcpName, FramedDirectionPtr refForces, FramedDirectionPtr refTorques, float forceThreshhold, float torqueThreshhold)
Definition: CheckTargetPoseReached.cpp:43
armarx::angleDistance
float angleDistance(float angle1, float angle2)
Definition: BasicControllers.h:163
armarx::CoupledInteractionGroup::CheckTargetPoseReached::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CheckTargetPoseReached.cpp:153
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getPlatformUnitProxy
PlatformUnitInterfacePrx getPlatformUnitProxy()
Definition: CoupledInteractionGroupStatechartContext.h:137
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getForceTorqueUnitObserver
ForceTorqueUnitObserverInterfacePrx getForceTorqueUnitObserver()
Definition: CoupledInteractionGroupStatechartContext.h:161
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::CoupledInteractionGroup::CheckTargetPoseReached::Registry
static SubClassRegistry Registry
Definition: CheckTargetPoseReached.h:49
armarx::CoupledInteractionGroup::CheckTargetPoseReached
Definition: CheckTargetPoseReached.h:34
armarx::StatechartContext::getChannelRef
ChannelRefPtr getChannelRef(const std::string &observerName, const std::string &channelName) override
Definition: StatechartContext.cpp:142
CheckTargetPoseReached.h
armarx::CoupledInteractionGroup::CheckTargetPoseReached::onBreak
void onBreak() override
Definition: CheckTargetPoseReached.cpp:130
IceInternal::Handle< FramedDirection >
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getRobot
const VirtualRobot::RobotPtr getRobot()
Definition: CoupledInteractionGroupStatechartContext.h:101
DatafieldRef.h
armarx::FramedDirection::ChangeFrame
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
Definition: FramedPose.cpp:86
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getPlatformUnitObserverName
std::string getPlatformUnitObserverName()
Definition: CoupledInteractionGroupStatechartContext.h:152
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::CoupledInteractionGroup::CheckTargetPoseReached::run
void run() override
Definition: CheckTargetPoseReached.cpp:122
armarx::CoupledInteractionGroup::CheckTargetPoseReached::CheckTargetPoseReached
CheckTargetPoseReached(XMLStateConstructorParams stateData)
Definition: CheckTargetPoseReached.cpp:38
armarx::CoupledInteractionGroup::CheckTargetPoseReached::GetName
static std::string GetName()
Definition: CheckTargetPoseReached.cpp:147
armarx::CoupledInteractionGroup::CheckTargetPoseReached::onExit
void onExit() override
Definition: CheckTargetPoseReached.cpp:136
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::channels::PlatformUnitObserver::platformPose
const PlatformUnitDatafieldCreator platformPose("platformPose")
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getTCPControlUnit
TCPControlUnitInterfacePrx getTCPControlUnit()
Definition: CoupledInteractionGroupStatechartContext.h:117
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::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:38
armarx::Vector3::toEigen
virtual Eigen::Vector3f toEigen() const
Definition: Pose.cpp:134
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:88
armarx::CoupledInteractionGroup::CheckTargetPoseReached::onEnter
void onEnter() override
Definition: CheckTargetPoseReached.cpp:70
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ChannelRef.h
norm
double norm(const Point &a)
Definition: point.hpp:94