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