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
27using namespace armarx;
28using namespace PlatformGroup;
29
30#include <VirtualRobot/MathTools.h>
31
32// DO NOT EDIT NEXT LINE
33MoveToNext::SubClassRegistry MoveToNext::Registry(MoveToNext::GetName(),
35
37 XMLStateTemplate<MoveToNext>(stateData), MoveToNextGeneratedBase<MoveToNext>(stateData)
38{
39}
40
41void
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
70void
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
134void
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
144std::string
146{
147 return "MoveToNext";
148}
149
150// DO NOT EDIT NEXT FUNCTION
DebugDrawerInterfacePrx debugDrawer
MoveToNext(XMLStateConstructorParams stateData)
void visualizeTargetPose(PlatformContext *context, Vector3Ptr &currentTarget, float positionalAccuracy)
static SubClassRegistry Registry
Definition MoveToNext.h:55
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
SystemObserverInterfacePrx systemObserverPrx
The Vector3 class.
Definition Pose.h:113
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< SingleTypeVariantList > SingleTypeVariantListPtr
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
const LogSender::manipulator flush
Definition LogSender.h:251
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64