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
24
25#include <VirtualRobot/math/Helpers.h>
26#include <VirtualRobot/math/Line.h>
27#include <VirtualRobot/math/LinearInterpolatedOrientation.h>
28
30
31
32using namespace armarx;
33using namespace ::visionx;
34
35class MyTrajectory : public math::SimpleAbstractFunctionR1R6
36{
37public:
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
71private:
72 std::vector<math::Line> posFuncts;
73 std::vector<math::LinearInterpolatedOrientation> oriFuncts;
74 float duration;
75};
76
77void
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
104void
109
110void
114
115void
119
126
127void
128visionx::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
133ArMarkerLocalizationResultList
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
148ArMarkerLocalizationResultList
150{
151 return LocalizeAllMarkersNow(Ice::emptyCurrent);
152}
#define M_PI
Definition MathTools.h:17
Eigen::Vector3f GetPosition(float t) override
Eigen::Quaternionf GetOrientation(float t) override
MyTrajectory(std::vector< Eigen::Matrix4f > poses, float duration)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
The FramedPose class.
Definition FramedPose.h:281
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
void reportImageAvailable(const std::string &, const Ice::Current &) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
math::SimpleAbstractFunctionR1R6Ptr trajectory
ArMarkerLocalizationResultList GetLatestLocalizationResult(const Ice::Current &) override
ArMarkerLocalizationResultList LocalizeAllMarkersNow(const Ice::Current &) override
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
Quaternion< float, 0 > Quaternionf
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.