CalculateTargetRobotPose.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::CalculateTargetRobotPoseGroup
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
28
29
30using namespace armarx;
31using namespace CoupledInteractionGroup;
32
33// DO NOT EDIT NEXT LINE
34CalculateTargetRobotPose::SubClassRegistry
37
40 CalculateTargetRobotPoseGeneratedBase<CalculateTargetRobotPose>(stateData)
41{
42}
43
44void
46{
47
49 getContext<CoupledInteractionGroupStatechartContext>();
50 //Eigen::Matrix4f robotPose = context->getRobot()->getRootNode()->getGlobalPose(); //unused variable
51 // Eigen::Matrix4f m = nodePose*objectPose.toEigen();
52 // objectPose = FramedPose(m, context->getRobot()->getRootNode()->getName(), context->getRobotStateComponent()->getSynchronizedRobot()->getName());
53 FramedDirectionPtr curOriVelLeft = in.getCurrentLeftTcpOrientationVelocity();
54 FramedDirectionPtr curOriVelRight = in.getCurrentRightTcpOrientationVelocity();
55 FramedDirectionPtr curVelRight = in.getCurrentRightTcpPositionVelocity();
56 FramedDirectionPtr curVelLeft = in.getCurrentLeftTcpPositionVelocity();
57 Vector3Ptr curVelPlatform = in.getCurrentPlatformVelocity();
58
59 FramedDirectionPtr tableTarget = in.getTableTargetPose();
60
61 Eigen::Vector3f targetLeftTcp;
62 Eigen::Vector3f targetRightTcp;
63 Eigen::Vector3f platformPose;
64 Eigen::Matrix4f relativeTargetPose;
65 Eigen::Vector3f initPlatformPose = in.getInitialPlatformPose()->toEigen();
66
67 armarx::ChannelRefPtr poseRef =
68 context->getChannelRef(context->getPlatformUnitObserverName(), "platformPose");
69 platformPose(0) = poseRef->getDataField("positionX")->getFloat();
70 platformPose(1) = poseRef->getDataField("positionY")->getFloat();
71 platformPose(2) = poseRef->getDataField("rotation")->getFloat();
72 Eigen::Matrix4f tableTargetPose = Eigen::Matrix4f::Identity();
73 tableTargetPose(0, 3) = tableTarget->x;
74 tableTargetPose(1, 3) = tableTarget->y;
75 tableTargetPose(0, 0) = cos(tableTarget->z);
76 tableTargetPose(0, 1) = -sin(tableTarget->z);
77 tableTargetPose(1, 1) = cos(tableTarget->z);
78 tableTargetPose(1, 0) = -sin(tableTarget->z);
79 FramedPosePtr tableGlobalPose = new FramedPose(tableTargetPose, "Global", "");
80 ARMARX_INFO << "Table Global Pose " << tableTargetPose(0, 3) << " " << tableTargetPose(1, 3);
81 tableGlobalPose->changeFrame(context->getRobot(),
82 context->getRobot()->getRootNode()->getName());
83
84 relativeTargetPose = tableGlobalPose->toEigen(); //robotPose.inverse()*tableTargetPose;
85 ARMARX_INFO << "Table Base Pose " << relativeTargetPose(0, 3) << " "
86 << relativeTargetPose(1, 3);
87 float maxVelocityTrans = 100.0;
88 float maxVelocityRot = 0.2;
89 float minVelocityTrans = 0.0;
90 float minVelocityRot = 0.0;
91 float finalDistance =
92 (initPlatformPose(0) - tableTarget->x) * (initPlatformPose(0) - tableTarget->x);
93 finalDistance +=
94 (initPlatformPose(1) - tableTarget->y) * (initPlatformPose(1) - tableTarget->y);
95 finalDistance = sqrt(finalDistance);
96 float remainingDistance =
97 (platformPose(0) - tableTarget->x) * (platformPose(0) - tableTarget->x);
98 remainingDistance += (platformPose(1) - tableTarget->y) * (platformPose(1) - tableTarget->y);
99 remainingDistance = sqrt(remainingDistance);
100 //if (remainingDistance > 0.66*finalDistance)
101 //{
102 // maxVelocityRot = 0.0;
103 // minVelocityRot = 0.0;
104 //}
105 Eigen::Vector3f relativeTarget;
106 float angle = tableTarget->z - platformPose(2);
107
108 if (fabs(angle) > M_PI)
109 {
110 if (angle > 0.0)
111 {
112 angle = angle - 2.0 * M_PI;
113 }
114 else
115 {
116 angle = 2.0 * M_PI + angle;
117 }
118 }
119
120 //float targetGain = in.getTargetGain(); //unused variable
121 //float curVelGain = std::max(1.0 - targetGain, 0.0); //unused variable
122 relativeTarget(0) =
123 std::max(std::min((relativeTargetPose(0, 3)), maxVelocityTrans), -maxVelocityTrans);
124 relativeTarget(1) =
125 std::max(std::min((relativeTargetPose(1, 3)), maxVelocityTrans), -maxVelocityTrans);
126 relativeTarget(2) = std::max(std::min((angle), maxVelocityRot), -maxVelocityRot);
127
128 if (relativeTarget(0) < minVelocityTrans && relativeTarget(0) > 0)
129 {
130 relativeTarget(0) = minVelocityTrans;
131 }
132 else if (relativeTarget(0) > -minVelocityTrans && relativeTarget(0) < 0)
133 {
134 relativeTarget(0) = -minVelocityTrans;
135 }
136
137 if (relativeTarget(1) < minVelocityTrans && relativeTarget(1) > 0)
138 {
139 relativeTarget(1) = minVelocityTrans;
140 }
141 else if (relativeTarget(1) > -minVelocityTrans && relativeTarget(1) < 0)
142 {
143 relativeTarget(1) = -minVelocityTrans;
144 }
145
146 if (relativeTarget(2) < minVelocityRot && relativeTarget(2) > 0)
147 {
148 relativeTarget(2) = minVelocityRot;
149 }
150 else if (relativeTarget(2) > -minVelocityRot && relativeTarget(2) < 0)
151 {
152 relativeTarget(2) = -minVelocityRot;
153 }
154
155 //relativeTarget(0) = 0.0;
156 ARMARX_INFO << "Rotating around " << relativeTarget(2) << " " << remainingDistance << " "
157 << finalDistance << " " << tableTarget->z << " " << platformPose(2);
158 ARMARX_INFO << "Current platform Pose " << platformPose(0) << " " << platformPose(1);
159 ARMARX_INFO << "Current platform Pose " << relativeTargetPose(0, 3) << " "
160 << relativeTargetPose(1, 3);
161 Eigen::Vector3f zeroVec;
162 zeroVec << 0.0, 0.0, 0.0;
163 PlatformUnitInterfacePrx platformPrx = context->getPlatformUnitProxy();
164 //platformPrx->move(tableTargetPose(0,3),relativeTarget(0),relativeTarget(1),relativeTarget(2));
165 platformPrx->move(0, 30, 0);
166
167 emitEvDone();
168 //based on that calculate platform target
169 //fuse with current velocities
170 //Verify in global or ???
171 //get Target Pose
172 //divide steps
173 //put through velocity
174 //turn 0.5 degres
175 //then move arms
176 //out.set
177}
178
179void
181{
182 // put your user code for the execution-phase here
183 // runs in seperate thread, thus can do complex operations
184 // should check constantly whether isRunningTaskStopped() returns true
185}
186
187void
189{
190 // put your user code for the breaking point here
191 // execution time should be short (<100ms)
192}
193
194void
196{
197
198 // put your user code for the exit point here
199 // execution time should be short (<100ms)
200}
201
202// DO NOT EDIT NEXT FUNCTION
203std::string
205{
206 return "CalculateTargetRobotPose";
207}
208
209// DO NOT EDIT NEXT FUNCTION
#define M_PI
Definition MathTools.h:17
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
The FramedPose class.
Definition FramedPose.h:281
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< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
double angle(const Point &a, const Point &b, const Point &c)
Definition point.hpp:109