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
38  {
39  }
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
52  {
53  task->stop();
54  }
55 
56  void
58  {
59  }
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.
79  TIMING_END_STREAM(getRobot, ARMARX_INFO);
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
VirtualRobotReaderExampleClient.h
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:85
TIMING_START
#define TIMING_START(name)
Definition: TimeUtil.h:289
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:51
armarx::robot_state::VirtualRobotReaderExampleClient::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: VirtualRobotReaderExampleClient.cpp:51
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
TIMING_END_STREAM
#define TIMING_END_STREAM(name, os)
Definition: TimeUtil.h:310
armarx::robot_state::VirtualRobotReaderExampleClient::VirtualRobotReaderExampleClient
VirtualRobotReaderExampleClient()
armarx::robot_state
Definition: VirtualRobotReaderExampleClient.cpp:10
armarx::robot_state::VirtualRobotReaderExampleClient::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: VirtualRobotReaderExampleClient.cpp:42
Metronome.h
armarx::robot_state::VirtualRobotReaderExampleClient::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: VirtualRobotReaderExampleClient.cpp:37
armarx::robot_state::VirtualRobotReaderExampleClient::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: VirtualRobotReaderExampleClient.cpp:15
ExpressionException.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::robot_state::VirtualRobotReaderExampleClient::getDefaultName
std::string getDefaultName() const override
Definition: VirtualRobotReaderExampleClient.cpp:31
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:34
Time.h
armarx::robot_state::VirtualRobotReaderExampleClient::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: VirtualRobotReaderExampleClient.cpp:57
armarx::Logging::deactivateSpam
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
armarx::core::time::Frequency::Hertz
static Frequency Hertz(std::int64_t hertz)
Definition: Frequency.cpp:20
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193