VirtualRobotReaderExampleClient.cpp
Go to the documentation of this file.
1
2
4
7
9
11{
13
16 {
19
20 defs->topic(debugObserver);
21
22 defs->optional(properties.robotName, "p.robotName", "The name of the robot to use.");
23 defs->optional(properties.updateFrequency,
24 "p.updateFrequency [Hz]",
25 "The frequency of the running loop.");
26
27 return defs;
28 }
29
30 std::string
32 {
33 return "VirtualRobotReaderExampleClient";
34 }
35
36 void
40
41 void
43 {
44 ARMARX_IMPORTANT << "Running virtual robot synchronization example.";
45
46 task = new SimpleRunningTask<>([this]() { this->run(); });
47 task->start();
48 }
49
50 void
55
56 void
60
61 void
62 VirtualRobotReaderExampleClient::run()
63 {
64 Metronome metronome(Frequency::Hertz(properties.updateFrequency));
65 while (task and not task->isStopped())
66 {
67 const armem::Time now = armem::Time::Now();
68
69 // Initialize the robot if needed.
70 if (robot == nullptr)
71 {
72 // The TIMING_* macros are optional, you do not need them.
73 TIMING_START(getRobot);
74
75 robot = virtualRobotReaderPlugin->get().getRobot(properties.robotName, now);
76 if (robot)
77 {
78 // Only print timing once the robot is loadable & loaded.
80 }
81 else
82 {
83 ARMARX_WARNING << deactivateSpam(10) << "Could not create virtual robot.";
84 }
85 }
86 if (robot)
87 {
88 ARMARX_INFO << deactivateSpam(60) << "Synchronizing robot.";
89
90 TIMING_START(synchronizeRobot);
91 ARMARX_CHECK(virtualRobotReaderPlugin->get().synchronizeRobot(*robot, now));
92 TIMING_END_STREAM(synchronizeRobot, ARMARX_INFO);
93
94
95 // Do something with the robot (your code follows here, there are just a examples) ...
96
97 Eigen::Matrix4f globalPose = robot->getGlobalPose();
98 (void)globalPose;
99
100 std::vector<std::string> nodeNames = robot->getRobotNodeNames();
101 (void)nodeNames;
102
103 // End.
104 }
105
106 metronome.waitForNextTick();
107 }
108 }
109
110} // namespace armarx::robot_state
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
static Frequency Hertz(std::int64_t hertz)
Definition Frequency.cpp:20
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition Logging.cpp:99
bool isStopped()
Retrieve whether stop() has been called.
static DateTime Now()
Definition DateTime.cpp:51
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition Metronome.h:57
void onInitComponent() override
Pure virtual hook for the subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
Pure virtual hook for the subclass.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define TIMING_START(name)
Helper macro to do timing tests.
Definition TimeUtil.h:289
#define TIMING_END_STREAM(name, os)
Prints duration.
Definition TimeUtil.h:310
armarx::core::time::DateTime Time
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
SimpleRunningTask(Ts...) -> SimpleRunningTask< std::function< void(void)> >