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
26
27#include <VirtualRobot/math/Helpers.h>
28#include <VirtualRobot/math/Line.h>
29#include <VirtualRobot/math/LinearInterpolatedOrientation.h>
30
32
33
34using namespace armarx;
35using namespace ::visionx;
36
37class MyTrajectory : public math::SimpleAbstractFunctionR1R6
38{
39public:
40 MyTrajectory(std::vector<Eigen::Matrix4f> poses, float duration) : duration(duration)
41 {
42 for (size_t i = 0; i < poses.size(); i++)
43 {
44 posFuncts.emplace_back(
45 math::Line::FromPoses(poses.at(i), poses.at((i + 1) % poses.size())));
46 oriFuncts.emplace_back(math::LinearInterpolatedOrientation(
47 math::Helpers::GetOrientation(poses.at(i)),
48 math::Helpers::GetOrientation(poses.at((i + 1) % poses.size())),
49 0,
50 1,
51 true));
52 }
53 }
54
55 Eigen::Vector3f
56 GetPosition(float t) override
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 posFuncts.at(i).Get(f);
62 }
63
65 GetOrientation(float t) override
66 {
67 t = fmod(t / duration, 1.0f) * posFuncts.size();
68 int i = std::min((int)t, (int)posFuncts.size() - 1);
69 float f = t - i;
70 return oriFuncts.at(i).Get(f);
71 }
72
73private:
74 std::vector<math::Line> posFuncts;
75 std::vector<math::LinearInterpolatedOrientation> oriFuncts;
76 float duration;
77};
78
79void
81{
82 agentName = getProperty<std::string>("AgentName").getValue();
83 frameName = getProperty<std::string>("FrameName").getValue();
84
85 Eigen::Vector3f p1(470, 723, 991);
86 Eigen::Vector3f p2(100, 0, 0);
87 Eigen::Vector3f p3(100, 0, 100);
88 Eigen::Vector3f p4(0, 0, 100);
89 float duration = 10.0f;
90 std::vector<Eigen::Matrix4f> poses;
91
92 poses.emplace_back(math::Helpers::CreatePose(p1, Eigen::Matrix3f::Identity()));
93 poses.emplace_back(math::Helpers::CreatePose(
94 p1 + p2,
95 Eigen::Matrix3f::Identity() * Eigen::AngleAxisf(-0.25 * M_PI, Eigen::Vector3f::UnitY())));
96 poses.emplace_back(math::Helpers::CreatePose(
97 p1 + p3,
98 Eigen::Matrix3f::Identity() * Eigen::AngleAxisf(-0.5 * M_PI, Eigen::Vector3f::UnitY())));
99 poses.emplace_back(math::Helpers::CreatePose(
100 p1 + p4,
101 Eigen::Matrix3f::Identity() * Eigen::AngleAxisf(-0.75 * M_PI, Eigen::Vector3f::UnitY())));
102
103 trajectory.reset(new MyTrajectory(poses, duration));
104}
105
106void
111
112void
116
117void
121
128
129void
130visionx::DummyArMarkerLocalizer::reportImageAvailable(const std::string&, const Ice::Current&)
131{
132 ARMARX_WARNING << "This is not a real image processor. Ignoring any input image!";
133}
134
135ArMarkerLocalizationResultList
137{
138 ArMarkerLocalizationResultList result;
139 ArMarkerLocalizationResult marker;
140 marker.id = 1234;
141 float t = (TimeUtil::GetTime() - startTime).toSecondsDouble();
142 marker.pose = new FramedPose(
143 math::Helpers::CreatePose(trajectory->GetPosition(t), trajectory->GetOrientation(t)),
144 frameName,
145 agentName);
146 result.push_back(marker);
147 return result;
148}
149
150ArMarkerLocalizationResultList
152{
153 return LocalizeAllMarkersNow(Ice::emptyCurrent);
154}
155
156
157std::string
159{
160 return "DummyArMarkerLocalizer";
161}
162
163std::string
168
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
#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
Brief description of class DummyArMarkerLocalizer.
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
std::string getDefaultName() const override
Retrieve default name of component.
#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.