CalculateApproachTablePose.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::CalculateApproachTablePoseGroup
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 #include <VirtualRobot/MathTools.h>
27 
29 
30 
31 using namespace armarx;
32 using namespace CoupledInteractionGroup;
33 
34 // DO NOT EDIT NEXT LINE
35 CalculateApproachTablePose::SubClassRegistry
38 
41  CalculateApproachTablePoseGeneratedBase<CalculateApproachTablePose>(stateData)
42 {
43 }
44 
45 float
46 CalculateApproachTablePose::getYawAngle(const Eigen::Matrix4f& pose) const
47 {
48  Eigen::Vector3f rpy;
49  VirtualRobot::MathTools::eigen4f2rpy(pose, rpy);
50  return rpy[2];
51 }
52 
53 void
55 {
57  getContext<CoupledInteractionGroupStatechartContext>();
58  float approachDistance = in.getApproachDistance();
59  float finalDistance = in.getFinalDistance();
60  FramedPosePtr tablePose = in.getTablePose();
61  ARMARX_LOG << "Incoming Table Pose " << *tablePose;
62  Eigen::Matrix4f approachoffset = Eigen::Matrix4f::Identity();
63  approachoffset(0, 3) = approachDistance;
64  Eigen::Matrix4f approachPoseGlobal =
65  tablePose->toGlobal(context->getRobot())->toEigen() * approachoffset;
66 
68  finaloffset(0, 3) = finalDistance;
69  Eigen::Matrix4f finalPoseGlobal =
70  tablePose->toGlobal(context->getRobot())->toEigen() * finaloffset;
71 
72  Eigen::Vector3f finalplatformPosVec(
73  finalPoseGlobal(0, 3), finalPoseGlobal(1, 3), getYawAngle(finalPoseGlobal) + M_PI_2);
74 
75  Eigen::Vector3f approachplatformPosVec(approachPoseGlobal(0, 3),
76  approachPoseGlobal(1, 3),
77  getYawAngle(approachPoseGlobal) + M_PI_2);
78 
79  std::vector<Vector3Ptr> approachPoses;
80  approachPoses.push_back(new Vector3(approachplatformPosVec));
81  approachPoses.push_back(new Vector3(finalplatformPosVec));
82  out.setApproachTablePose(approachPoses);
83  emitEvApproachPoseCalculated();
84 
85 
86  // FramedDirectionPtr tablePose = in.getTablePose();
87  // //Convert from Robot Base Frame to global Base frame
88 
89 
90  // Eigen::Matrix4f approachLocal = Eigen::Matrix4f::Identity();
91  // approachLocal(0,3) = tablePose->x;
92  // approachLocal(1,3) = tablePose->y - approachDistance;
93  // Eigen::Matrix4f finalLocal = Eigen::Matrix4f::Identity();
94  // finalLocal(0,3) = tablePose->x;
95  // finalLocal(1,3) = tablePose->y - finalDistance;
96 
97  // Eigen::Matrix4f globalApproachPose = context->getRobot()->getRootNode()->toGlobalCoordinateSystem(approachLocal);
98  // Eigen::Matrix4f globalFinalPose = context->getRobot()->getRootNode()->toGlobalCoordinateSystem(finalLocal);
99 
100  // PosePtr poseApproach(new Pose(globalApproachPose));
101  // PosePtr poseFinal(new Pose(globalFinalPose));
102  // context->getDebugDrawerTopicProxy()->setPoseDebugLayerVisu("Approach Table", poseApproach);
103  // context->getDebugDrawerTopicProxy()->setPoseDebugLayerVisu("Final Table", poseFinal);
104 
105  // /*
106  // Eigen::Matrix4f tableBaseTransform = Eigen::Matrix4f::Identity();
107  // tableBaseTransform(0,3) = tablePose->x;
108  // tableBaseTransform(1,3) = tablePose->y;
109  // tableBaseTransform(0,0) = cos(tablePose->z);
110  // tableBaseTransform(0,1) = -sin(tablePose->z);
111  // tableBaseTransform(1,1) = cos(tablePose->z);
112  // tableBaseTransform(1,0) = -sin(tablePose->z);
113  // Eigen::Matrix4f approachPoseTableTransform = Eigen::Matrix4f::Identity();
114  // approachPoseTableTransform(1,3) = -approachDistance;
115  // Eigen::Matrix4f finalPoseTableTransform = Eigen::Matrix4f::Identity();
116  // finalPoseTableTransform(1,3) = -finalDistance;
117  // Eigen::Matrix4f globalApproachPose = context->getRobot()->getRootNode()->getGlobalPose()*tableBaseTransform*approachPoseTableTransform;
118  // Eigen::Matrix4f globalFinalPose = context->getRobot()->getRootNode()->getGlobalPose()*tableBaseTransform*finalPoseTableTransform;*/
119 
120  // ARMARX_INFO << "Approach and Final Distance " << approachDistance << " " << finalDistance;
121  // armarx::ChannelRefPtr poseRef = context->getChannelRef(context->getPlatformUnitObserverName(), "platformPose");
122  // //currentBaseVec(0) = poseRef->getDataField("positionX")->getFloat();
123  // //currentBaseVec(1) = poseRef->getDataField("positionY")->getFloat();
124  // //currentBaseVec(2) = poseRef->getDataField("rotation")->getFloat();
125  // ARMARX_INFO << "Approach Pose " << globalApproachPose;
126  // ARMARX_INFO << "Approach Pose " << globalFinalPose;
127  // Vector3Ptr approachPose1 = new Vector3();
128 
129 
130  // approachPose1->x = poseRef->getDataField("positionX")->getFloat()+0.75*(globalApproachPose(0,3)-poseRef->getDataField("positionX")->getFloat());
131 
132  // approachPose1->y = poseRef->getDataField("positionY")->getFloat()+0.75*(globalApproachPose(1,3)-poseRef->getDataField("positionY")->getFloat());
133  // approachPose1->z = poseRef->getDataField("rotation")->getFloat()+0.5*(tablePose->z);
134  // approachPose1->x = globalFinalPose(0,3)+2.0*(approachPose1->x-globalFinalPose(0,3));
135  // approachPose1->y = globalFinalPose(1,3)+2.0*(approachPose1->y-globalFinalPose(1,3));
136  // Vector3Ptr approachPose2 = new Vector3();
137  // approachPose2->x = globalApproachPose(0,3);
138  // approachPose2->y = globalApproachPose(1,3);
139  // approachPose2->z = poseRef->getDataField("rotation")->getFloat()+tablePose->z;
140 
141  // Vector3Ptr finalPose = new Vector3();
142  // finalPose->x = globalFinalPose(0,3);
143  // finalPose->y = globalFinalPose(1,3);
144  // finalPose->z = poseRef->getDataField("rotation")->getFloat()+tablePose->z;
145  // std::vector< Vector3Ptr > approachPoses;
146  // approachPoses.push_back(approachPose1);
147  // approachPoses.push_back(approachPose2);
148  // approachPoses.push_back(finalPose);
149  // out.setApproachTablePose(approachPoses);
150  // emitEvApproachPoseCalculated();
151 }
152 
153 void
155 {
156  // put your user code for the execution-phase here
157  // runs in seperate thread, thus can do complex operations
158  // should check constantly whether isRunningTaskStopped() returns true
159 }
160 
161 void
163 {
164  // put your user code for the breaking point here
165  // execution time should be short (<100ms)
166 }
167 
168 void
170 {
171 
172  // put your user code for the exit point here
173  // execution time should be short (<100ms)
174 }
175 
176 // DO NOT EDIT NEXT FUNCTION
177 std::string
179 {
180  return "CalculateApproachTablePose";
181 }
182 
183 // DO NOT EDIT NEXT FUNCTION
186 {
187  return XMLStateFactoryBasePtr(new CalculateApproachTablePose(stateData));
188 }
RemoteRobot.h
armarx::CoupledInteractionGroup::CalculateApproachTablePose::Registry
static SubClassRegistry Registry
Definition: CalculateApproachTablePose.h:52
armarx::CoupledInteractionGroup::CalculateApproachTablePose::GetName
static std::string GetName()
Definition: CalculateApproachTablePose.cpp:178
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
CalculateApproachTablePose.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< FramedPose >
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getRobot
const VirtualRobot::RobotPtr getRobot()
Definition: CoupledInteractionGroupStatechartContext.h:133
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::CoupledInteractionGroup::CalculateApproachTablePose::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CalculateApproachTablePose.cpp:185
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:165
armarx::CoupledInteractionGroup::CalculateApproachTablePose::onBreak
void onBreak() override
Definition: CalculateApproachTablePose.cpp:162
armarx::CoupledInteractionGroup::CalculateApproachTablePose::run
void run() override
Definition: CalculateApproachTablePose.cpp:154
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:118
armarx::CoupledInteractionGroup::CalculateApproachTablePose::onExit
void onExit() override
Definition: CalculateApproachTablePose.cpp:169
armarx::CoupledInteractionGroup::CalculateApproachTablePose::CalculateApproachTablePose
CalculateApproachTablePose(XMLStateConstructorParams stateData)
Definition: CalculateApproachTablePose.cpp:39
armarx::CoupledInteractionGroup::CalculateApproachTablePose::onEnter
void onEnter() override
Definition: CalculateApproachTablePose.cpp:54
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::CoupledInteractionGroup::CalculateApproachTablePose
Definition: CalculateApproachTablePose.h:37