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