MoveToNext.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::MovePlatformToLandmarkGroup
19  * @author Valerij Wittenbeck ( valerij dot wittenbeck at student dot kit dot edu )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "MoveToNext.h"
26 
27 using namespace armarx;
28 using namespace PlatformGroup;
29 
30 #include <VirtualRobot/MathTools.h>
31 
32 // DO NOT EDIT NEXT LINE
34 
35 
36 
38  XMLStateTemplate < MoveToNext > (stateData),
39  MoveToNextGeneratedBase<MoveToNext>(stateData)
40 {
41 }
42 
43 void MoveToNext::visualizeTargetPose(PlatformContext* context, Vector3Ptr& currentTarget, float positionalAccuracy)
44 {
45  Eigen::Matrix3f rot;
46  rot = Eigen::AngleAxisf(0, Eigen::Vector3f::UnitX())
47  * Eigen::AngleAxisf(0, Eigen::Vector3f::UnitY())
48  * Eigen::AngleAxisf(currentTarget->z, Eigen::Vector3f::UnitZ());
49  // PosePtr targetPose = new Pose(rot, Eigen::Vector3f(currentTarget->x, currentTarget->y, 0));
50  // context->debugDrawer->setPoseVisu("Platform", "PlatformTargetPose", targetPose);
51  DrawColor color {0, 0, 1, 0.3};
52  const Eigen::Vector3f eigPos
53  {
54  currentTarget->x, currentTarget->y, 0
55  };
56  Vector3Ptr pos = new Vector3(eigPos);
57  //debug layer
58  Eigen::Vector3f dir {0, 1, 0};
59  dir = rot * dir;
60  // PosePtr pose = ::armarx::PosePtr{new ::armarx::Pose{rot, eigPos}};
61  context->debugDrawer->setArrowVisu("Platform", "PlatformTargetPose", pos,
62  new armarx::Vector3(dir),
63  armarx::DrawColor {0, 0, 1, 1},
64  100,
65  10);
66  context->debugDrawer->setSphereVisu("Platform", "PlatformTargetPoseAccuracy", pos, color, positionalAccuracy);
67 
68 }
69 
71 {
72 
73  PlatformContext* context = getContext<PlatformContext>();
74  ChannelRefPtr counter = getInput<ChannelRef>("positionCounter");
75  int positionIndex = counter->getDataField("value")->getInt();
76  ARMARX_DEBUG << "Entering positionIndex:" << positionIndex << flush;
77  SingleTypeVariantListPtr points = getInput<SingleTypeVariantList>("targetPositions");
78 
79  local.setAdjustedPositionalAccuracy(in.getpositionalAccuracy());
80  local.setAdjustedOrientationalAccuracy(in.getorientationalAccuracy());
81 
82  ARMARX_DEBUG << "points->getSize:" << points->getSize() << flush;
83 
84  if (positionIndex < points->getSize())
85  {
86  Vector3Ptr currentTarget = points->getVariant(positionIndex)->get<Vector3>();
87  ARMARX_VERBOSE << "going to Platform Target:" << currentTarget->toEigen().transpose() << flush;
88  float positionalAccuracy = in.getpositionalAccuracy();
89  //context->platformUnitPrx->moveTo(currentTarget->x, currentTarget->y, currentTarget->z, positionalAccuracy, orientationalAccuracy);
90  local.setAbsoluteTargetPosition(currentTarget);
91  visualizeTargetPose(context, currentTarget, positionalAccuracy);
92 
93  if (positionIndex < points->getSize() - 1)
94  {
95  //waypoints
96  ARMARX_INFO << "NOT Stopping after this waypoint";
97  local.setStopOnWaypoints(false);
98  ARMARX_INFO << "Accuracy increase position: " << in.getIntermediateWaypointPositionAccuracyFactor();
99  ARMARX_INFO << "Accuracy increase orientation: " << in.getIntermediateWaypointOrientationAccuracyFactor();
100  local.setAdjustedPositionalAccuracy(in.getpositionalAccuracy() * in.getIntermediateWaypointPositionAccuracyFactor());
101  local.setAdjustedOrientationalAccuracy(in.getorientationalAccuracy() * in.getIntermediateWaypointOrientationAccuracyFactor());
102  local.setVerifyTargetPose(false);
103  }
104  else // last waypoint
105  {
106  ARMARX_INFO << "Stopping after this waypoint";
107  local.setStopOnWaypoints(true);
108  local.setVerifyTargetPose(true);
109  }
110 
111  }
112  else
113  {
114  // this is AFTER the last waypoint
115 
116  Vector3Ptr currentTarget = points->getVariant(points->getSize() - 1)->get<Vector3>();
117  local.setAbsoluteTargetPosition(currentTarget);
118  cancelSubstates();
119  setTimeoutEvent(getInput<int>("waitAfterLast"), createEvent<EvEndpointReached>());
120  }
121 
122  ARMARX_INFO << "Positional accuracy: " << local.getAdjustedPositionalAccuracy();
123  ARMARX_INFO << "Orientational accuracy: " << local.getAdjustedOrientationalAccuracy();
124 
125  context->systemObserverPrx->incrementCounter(counter);
126 }
127 
129 {
130  PlatformContext* context = getContext<PlatformContext>();
131  //context->debugDrawer->removePoseVisu("Platform", "PlatformTargetPose");
132  context->debugDrawer->removeSphereVisu("Platform", "PlatformTargetPoseAccuracy");
133  context->debugDrawer->removeArrowVisu("Platform", "PlatformTargetPose");
134 }
135 
136 
137 // DO NOT EDIT NEXT FUNCTION
138 std::string MoveToNext::GetName()
139 {
140  return "MoveToNext";
141 }
142 
143 // DO NOT EDIT NEXT FUNCTION
145 {
146  return XMLStateFactoryBasePtr(new MoveToNext(stateData));
147 }
148 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::StatechartContext::systemObserverPrx
SystemObserverInterfacePrx systemObserverPrx
Definition: StatechartContext.h:187
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::PlatformGroup::MoveToNext::MoveToNext
MoveToNext(XMLStateConstructorParams stateData)
Definition: MoveToNext.cpp:37
armarx::PlatformGroup::MoveToNext::onExit
void onExit() override
Definition: MoveToNext.cpp:128
armarx::PlatformGroup::MoveToNext::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: MoveToNext.cpp:144
armarx::PlatformGroup::MoveToNext::onEnter
void onEnter() override
Definition: MoveToNext.cpp:70
armarx::PlatformGroup::MoveToNext::visualizeTargetPose
void visualizeTargetPose(PlatformContext *context, Vector3Ptr &currentTarget, float positionalAccuracy)
Definition: MoveToNext.cpp:43
IceInternal::Handle< Vector3 >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::PlatformGroup::MoveToNext::Registry
static SubClassRegistry Registry
Definition: MoveToNext.h:52
armarx::PlatformGroup::MoveToNext
Definition: MoveToNext.h:37
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
armarx::PlatformContext
Definition: PlatformContext.h:64
armarx::PlatformGroup::MoveToNext::GetName
static std::string GetName()
Definition: MoveToNext.cpp:138
MoveToNext.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PlatformContext::debugDrawer
DebugDrawerInterfacePrx debugDrawer
Definition: PlatformContext.h:122