DummyArMarkerLocalizer.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package VisionX::ArmarXObjects::DummyArMarkerLocalizer
17  * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "DummyArMarkerLocalizer.h"
24 
25 #include <VirtualRobot/math/Helpers.h>
26 #include <VirtualRobot/math/Line.h>
27 #include <VirtualRobot/math/LinearInterpolatedOrientation.h>
28 
30 
31 
32 using namespace armarx;
33 using namespace ::visionx;
34 
35 class MyTrajectory : public math::SimpleAbstractFunctionR1R6
36 {
37 public:
38  MyTrajectory(std::vector<Eigen::Matrix4f> poses, float duration) : duration(duration)
39  {
40  for (size_t i = 0; i < poses.size(); i++)
41  {
42  posFuncts.emplace_back(
43  math::Line::FromPoses(poses.at(i), poses.at((i + 1) % poses.size())));
44  oriFuncts.emplace_back(math::LinearInterpolatedOrientation(
45  math::Helpers::GetOrientation(poses.at(i)),
46  math::Helpers::GetOrientation(poses.at((i + 1) % poses.size())),
47  0,
48  1,
49  true));
50  }
51  }
52 
53  Eigen::Vector3f
54  GetPosition(float t) override
55  {
56  t = fmod(t / duration, 1.0f) * posFuncts.size();
57  int i = std::min((int)t, (int)posFuncts.size() - 1);
58  float f = t - i;
59  return posFuncts.at(i).Get(f);
60  }
61 
63  GetOrientation(float t) override
64  {
65  t = fmod(t / duration, 1.0f) * posFuncts.size();
66  int i = std::min((int)t, (int)posFuncts.size() - 1);
67  float f = t - i;
68  return oriFuncts.at(i).Get(f);
69  }
70 
71 private:
72  std::vector<math::Line> posFuncts;
73  std::vector<math::LinearInterpolatedOrientation> oriFuncts;
74  float duration;
75 };
76 
77 void
78 DummyArMarkerLocalizer::onInitComponent()
79 {
80  agentName = getProperty<std::string>("AgentName").getValue();
81  frameName = getProperty<std::string>("FrameName").getValue();
82 
83  Eigen::Vector3f p1(470, 723, 991);
84  Eigen::Vector3f p2(100, 0, 0);
85  Eigen::Vector3f p3(100, 0, 100);
86  Eigen::Vector3f p4(0, 0, 100);
87  float duration = 10.0f;
88  std::vector<Eigen::Matrix4f> poses;
89 
90  poses.emplace_back(math::Helpers::CreatePose(p1, Eigen::Matrix3f::Identity()));
91  poses.emplace_back(math::Helpers::CreatePose(
92  p1 + p2,
93  Eigen::Matrix3f::Identity() * Eigen::AngleAxisf(-0.25 * M_PI, Eigen::Vector3f::UnitY())));
94  poses.emplace_back(math::Helpers::CreatePose(
95  p1 + p3,
96  Eigen::Matrix3f::Identity() * Eigen::AngleAxisf(-0.5 * M_PI, Eigen::Vector3f::UnitY())));
97  poses.emplace_back(math::Helpers::CreatePose(
98  p1 + p4,
99  Eigen::Matrix3f::Identity() * Eigen::AngleAxisf(-0.75 * M_PI, Eigen::Vector3f::UnitY())));
100 
101  trajectory.reset(new MyTrajectory(poses, duration));
102 }
103 
104 void
105 DummyArMarkerLocalizer::onConnectComponent()
106 {
107  startTime = TimeUtil::GetTime();
108 }
109 
110 void
111 DummyArMarkerLocalizer::onDisconnectComponent()
112 {
113 }
114 
115 void
116 DummyArMarkerLocalizer::onExitComponent()
117 {
118 }
119 
121 DummyArMarkerLocalizer::createPropertyDefinitions()
122 {
124  new DummyArMarkerLocalizerPropertyDefinitions(getConfigIdentifier()));
125 }
126 
127 void
128 visionx::DummyArMarkerLocalizer::reportImageAvailable(const std::string&, const Ice::Current&)
129 {
130  ARMARX_WARNING << "This is not a real image processor. Ignoring any input image!";
131 }
132 
133 ArMarkerLocalizationResultList
135 {
136  ArMarkerLocalizationResultList result;
137  ArMarkerLocalizationResult marker;
138  marker.id = 1234;
139  float t = (TimeUtil::GetTime() - startTime).toSecondsDouble();
140  marker.pose = new FramedPose(
141  math::Helpers::CreatePose(trajectory->GetPosition(t), trajectory->GetOrientation(t)),
142  frameName,
143  agentName);
144  result.push_back(marker);
145  return result;
146 }
147 
148 ArMarkerLocalizationResultList
149 DummyArMarkerLocalizer::GetLatestLocalizationResult(const Ice::Current&)
150 {
151  return LocalizeAllMarkersNow(Ice::emptyCurrent);
152 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::DummyArMarkerLocalizerPropertyDefinitions
Definition: DummyArMarkerLocalizer.h:42
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:36
MyTrajectory::GetPosition
Eigen::Vector3f GetPosition(float t) override
Definition: DummyArMarkerLocalizer.cpp:54
DummyArMarkerLocalizer.h
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
M_PI
#define M_PI
Definition: MathTools.h:17
FramedPose.h
visionx::DummyArMarkerLocalizer::reportImageAvailable
void reportImageAvailable(const std::string &, const Ice::Current &) override
Definition: DummyArMarkerLocalizer.cpp:128
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::Quaternion< float, 0 >
IceUtil::Handle< class PropertyDefinitionContainer >
MyTrajectory::MyTrajectory
MyTrajectory(std::vector< Eigen::Matrix4f > poses, float duration)
Definition: DummyArMarkerLocalizer.cpp:38
visionx::DummyArMarkerLocalizer::LocalizeAllMarkersNow
ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current &) override
Definition: DummyArMarkerLocalizer.cpp:134
MyTrajectory::GetOrientation
Eigen::Quaternionf GetOrientation(float t) override
Definition: DummyArMarkerLocalizer.cpp:63
min
T min(T t1, T t2)
Definition: gdiam.h:44
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
MyTrajectory
Definition: DummyArMarkerLocalizer.cpp:35