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
31using namespace armarx;
32using namespace CoupledInteractionGroup;
33
34// DO NOT EDIT NEXT LINE
35CalculateApproachTablePose::SubClassRegistry
38
44
45float
46CalculateApproachTablePose::getYawAngle(const Eigen::Matrix4f& pose) const
47{
48 Eigen::Vector3f rpy;
49 VirtualRobot::MathTools::eigen4f2rpy(pose, rpy);
50 return rpy[2];
51}
52
53void
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
67 Eigen::Matrix4f finaloffset = Eigen::Matrix4f::Identity();
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
153void
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
161void
163{
164 // put your user code for the breaking point here
165 // execution time should be short (<100ms)
166}
167
168void
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
177std::string
179{
180 return "CalculateApproachTablePose";
181}
182
183// DO NOT EDIT NEXT FUNCTION
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
The Vector3 class.
Definition Pose.h:113
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_LOG
Definition Logging.h:165
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272