VirtualRobotReaderExampleClient.cpp
Go to the documentation of this file.
1 
2 
4 
7 
9 
10 
12 {
14 
16  {
19 
20  defs->topic(debugObserver);
21 
22  defs->optional(properties.robotName, "p.robotName",
23  "The name of the robot to use.");
24  defs->optional(properties.updateFrequency, "p.updateFrequency [Hz]",
25  "The frequency of the running loop.");
26 
27  return defs;
28  }
29 
30 
32  {
33  return "VirtualRobotReaderExampleClient";
34  }
35 
36 
38  {
39  }
40 
41 
43  {
44  ARMARX_IMPORTANT << "Running virtual robot synchronization example.";
45 
46  task = new SimpleRunningTask<>([this]()
47  {
48  this->run();
49  });
50  task->start();
51  }
52 
53 
55  {
56  task->stop();
57  }
58 
59 
61  {
62  }
63 
64 
65  void VirtualRobotReaderExampleClient::run()
66  {
67  Metronome metronome(Frequency::Hertz(properties.updateFrequency));
68  while (task and not task->isStopped())
69  {
70  const armem::Time now = armem::Time::Now();
71 
72  // Initialize the robot if needed.
73  if (robot == nullptr)
74  {
75  // The TIMING_* macros are optional, you do not need them.
76  TIMING_START(getRobot);
77 
78  robot = virtualRobotReaderPlugin->get().getRobot(properties.robotName, now);
79  if (robot)
80  {
81  // Only print timing once the robot is loadable & loaded.
82  TIMING_END_STREAM(getRobot, ARMARX_INFO);
83  }
84  else
85  {
86  ARMARX_WARNING << deactivateSpam(10) << "Could not create virtual robot.";
87  }
88  }
89  if (robot)
90  {
91  ARMARX_INFO << deactivateSpam(60) << "Synchronizing robot.";
92 
93  TIMING_START(synchronizeRobot);
94  ARMARX_CHECK(virtualRobotReaderPlugin->get().synchronizeRobot(*robot, now));
95  TIMING_END_STREAM(synchronizeRobot, ARMARX_INFO);
96 
97 
98  // Do something with the robot (your code follows here, there are just a examples) ...
99 
100  Eigen::Matrix4f globalPose = robot->getGlobalPose();
101  (void) globalPose;
102 
103  std::vector<std::string> nodeNames = robot->getRobotNodeNames();
104  (void) nodeNames;
105 
106  // End.
107  }
108 
109  metronome.waitForNextTick();
110  }
111  }
112 
113 } // namespace armarx::robot_state
VirtualRobotReaderExampleClient.h
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:70
TIMING_START
#define TIMING_START(name)
Definition: TimeUtil.h:280
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::robot_state::VirtualRobotReaderExampleClient::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: VirtualRobotReaderExampleClient.cpp:54
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:300
armarx::robot_state::VirtualRobotReaderExampleClient::VirtualRobotReaderExampleClient
VirtualRobotReaderExampleClient()
armarx::robot_state
Definition: VirtualRobotReaderExampleClient.cpp:11
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:74
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
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:35
Time.h
armarx::robot_state::VirtualRobotReaderExampleClient::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: VirtualRobotReaderExampleClient.cpp:60
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:92
armarx::core::time::Frequency::Hertz
static Frequency Hertz(std::int64_t hertz)
Definition: Frequency.cpp:23
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186