VirtualRobotReaderExampleClient.cpp
Go to the documentation of this file.
1
2
4
7
9
11
13 "VirtualRobotReaderExampleClient");
14
16{
18
21 {
24
25 defs->topic(debugObserver);
26
27 defs->optional(properties.robotName, "p.robotName", "The name of the robot to use.");
28 defs->optional(properties.updateFrequency,
29 "p.updateFrequency [Hz]",
30 "The frequency of the running loop.");
31
32 return defs;
33 }
34
35 std::string
37 {
38 return "VirtualRobotReaderExampleClient";
39 }
40
41 void
45
46 void
48 {
49 ARMARX_IMPORTANT << "Running virtual robot synchronization example.";
50
51 task = new SimpleRunningTask<>([this]() { this->run(); });
52 task->start();
53 }
54
55 void
60
61 void
65
66 void
67 VirtualRobotReaderExampleClient::run()
68 {
69 Metronome metronome(Frequency::Hertz(properties.updateFrequency));
70 while (task and not task->isStopped())
71 {
72 const armem::Time now = armem::Time::Now();
73
74 // Initialize the robot if needed.
75 if (robot == nullptr)
76 {
77 // The TIMING_* macros are optional, you do not need them.
78 TIMING_START(getRobot);
79
80 robot = virtualRobotReaderPlugin->get().getRobot(properties.robotName, now);
81 if (robot)
82 {
83 // Only print timing once the robot is loadable & loaded.
85 }
86 else
87 {
88 ARMARX_WARNING << deactivateSpam(10) << "Could not create virtual robot.";
89 }
90 }
91 if (robot)
92 {
93 ARMARX_INFO << deactivateSpam(60) << "Synchronizing robot.";
94
95 TIMING_START(synchronizeRobot);
96 ARMARX_CHECK(virtualRobotReaderPlugin->get().synchronizeRobot(*robot, now));
97 TIMING_END_STREAM(synchronizeRobot, ARMARX_INFO);
98
99
100 // Do something with the robot (your code follows here, there are just a examples) ...
101
102 Eigen::Matrix4f globalPose = robot->getGlobalPose();
103 (void)globalPose;
104
105 std::vector<std::string> nodeNames = robot->getRobotNodeNames();
106 (void)nodeNames;
107
108 // End.
109 }
110
111 metronome.waitForNextTick();
112 }
113 }
114
115} // namespace armarx::robot_state
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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
Brief description of class VirtualRobotReaderExampleClient.
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)> >