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 
26 #include <VirtualRobot/math/Helpers.h>
27 #include <VirtualRobot/math/Line.h>
28 #include <VirtualRobot/math/LinearInterpolatedOrientation.h>
29 
30 
31 using namespace armarx;
32 using namespace ::visionx;
33 
34 class MyTrajectory : public math::SimpleAbstractFunctionR1R6
35 {
36 public:
37 
38 
39  MyTrajectory(std::vector<Eigen::Matrix4f> poses, float duration)
40  : duration(duration)
41  {
42  for (size_t i = 0 ; i < poses.size(); i++)
43  {
44  posFuncts.emplace_back(math::Line::FromPoses(poses.at(i), poses.at((i + 1) % poses.size())));
45  oriFuncts.emplace_back(math::LinearInterpolatedOrientation(math::Helpers::GetOrientation(poses.at(i)), math::Helpers::GetOrientation(poses.at((i + 1) % poses.size())), 0, 1, true));
46  }
47  }
48 
49  Eigen::Vector3f GetPosition(float t) override
50  {
51  t = fmod(t / duration, 1.0f) * posFuncts.size();
52  int i = std::min((int)t, (int)posFuncts.size() - 1);
53  float f = t - i;
54  return posFuncts.at(i).Get(f);
55  }
57  {
58  t = fmod(t / duration, 1.0f) * posFuncts.size();
59  int i = std::min((int)t, (int)posFuncts.size() - 1);
60  float f = t - i;
61  return oriFuncts.at(i).Get(f);
62  }
63 
64 private:
65  std::vector<math::Line> posFuncts;
66  std::vector<math::LinearInterpolatedOrientation> oriFuncts;
67  float duration;
68 
69 
70 };
71 
72 
73 void DummyArMarkerLocalizer::onInitComponent()
74 {
75  agentName = getProperty<std::string>("AgentName").getValue();
76  frameName = getProperty<std::string>("FrameName").getValue();
77 
78  Eigen::Vector3f p1(470, 723, 991);
79  Eigen::Vector3f p2(100, 0, 0);
80  Eigen::Vector3f p3(100, 0, 100);
81  Eigen::Vector3f p4(0, 0, 100);
82  float duration = 10.0f;
83  std::vector<Eigen::Matrix4f> poses;
84 
85  poses.emplace_back(math::Helpers::CreatePose(p1, Eigen::Matrix3f::Identity()));
86  poses.emplace_back(math::Helpers::CreatePose(p1 + p2, Eigen::Matrix3f::Identity()*Eigen::AngleAxisf(-0.25 * M_PI, Eigen::Vector3f::UnitY())));
87  poses.emplace_back(math::Helpers::CreatePose(p1 + p3, Eigen::Matrix3f::Identity()*Eigen::AngleAxisf(-0.5 * M_PI, Eigen::Vector3f::UnitY())));
88  poses.emplace_back(math::Helpers::CreatePose(p1 + p4, Eigen::Matrix3f::Identity()*Eigen::AngleAxisf(-0.75 * M_PI, Eigen::Vector3f::UnitY())));
89 
90  trajectory.reset(new MyTrajectory(poses, duration));
91 
92 }
93 
94 
95 void DummyArMarkerLocalizer::onConnectComponent()
96 {
97  startTime = TimeUtil::GetTime();
98 }
99 
100 
101 void DummyArMarkerLocalizer::onDisconnectComponent()
102 {
103 
104 }
105 
106 
107 void DummyArMarkerLocalizer::onExitComponent()
108 {
109 
110 }
111 
112 armarx::PropertyDefinitionsPtr DummyArMarkerLocalizer::createPropertyDefinitions()
113 {
115  getConfigIdentifier()));
116 }
117 
118 
119 
120 void visionx::DummyArMarkerLocalizer::reportImageAvailable(const std::string&, const Ice::Current&)
121 {
122  ARMARX_WARNING << "This is not a real image processor. Ignoring any input image!";
123 }
124 
125 ArMarkerLocalizationResultList visionx::DummyArMarkerLocalizer::LocalizeAllMarkersNow(const Ice::Current&)
126 {
127  ArMarkerLocalizationResultList result;
128  ArMarkerLocalizationResult marker;
129  marker.id = 1234;
130  float t = (TimeUtil::GetTime() - startTime).toSecondsDouble();
131  marker.pose = new FramedPose(math::Helpers::CreatePose(trajectory->GetPosition(t), trajectory->GetOrientation(t)), frameName, agentName);
132  result.push_back(marker);
133  return result;
134 }
135 
136 ArMarkerLocalizationResultList DummyArMarkerLocalizer::GetLatestLocalizationResult(const Ice::Current&)
137 {
138  return LocalizeAllMarkersNow(Ice::emptyCurrent);
139 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::DummyArMarkerLocalizerPropertyDefinitions
Definition: DummyArMarkerLocalizer.h:38
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
MyTrajectory::GetPosition
Eigen::Vector3f GetPosition(float t) override
Definition: DummyArMarkerLocalizer.cpp:49
DummyArMarkerLocalizer.h
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
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:120
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:39
visionx::DummyArMarkerLocalizer::LocalizeAllMarkersNow
ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current &) override
Definition: DummyArMarkerLocalizer.cpp:125
MyTrajectory::GetOrientation
Eigen::Quaternionf GetOrientation(float t) override
Definition: DummyArMarkerLocalizer.cpp:56
min
T min(T t1, T t2)
Definition: gdiam.h:42
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
MyTrajectory
Definition: DummyArMarkerLocalizer.cpp:34