RTUnit.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2018
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27
28#include <array>
29#include <fstream>
30#include <memory>
31#include <sstream>
32#include <thread>
33
37
39
41
42/**
43 * @defgroup Library-ethercat ethercat
44 * @ingroup armarx_control
45 * A description of the library ethercat.
46 */
48{
49
50 /**
51 * @class RTUnit
52 * @ingroup Library-ethercat
53 * @brief Brief description of class RTUnit.
54 *
55 * Detailed description of class RTUnit.
56 */
57 class RTUnit : virtual public Logging, virtual public RobotUnit
58 {
59
60 public:
61 RTUnit();
62 ~RTUnit() override;
63
64 /**
65 * @see armarx::ManagedIceObject::getDefaultName()
66 */
67 std::string
68 getDefaultName() const override
69 {
70 return "EtherCATRTUnit";
71 }
72
73 protected:
74 void onInitRobotUnit() override;
75 void onConnectRobotUnit() override;
76 void onDisconnectRobotUnit() override;
77 void onExitRobotUnit() override;
78
79 void initializeKinematicUnit() override;
80
81 void joinControlThread() override;
82
83 void publish(armarx::StringVariantBaseMap debugObserverMap = {},
84 armarx::StringVariantBaseMap timingMap = {}) override;
85
86 /**
87 * @see PropertyUser::createPropertyDefinitions()
88 */
90
91
92 protected:
93 static MultiNodeRapidXMLReader ReadHardwareConfigFile(std::string hardwareConfigFilePath,
94 std::string rootNodeName);
95
96 //all the stuff to run the rt Thread
97 void startRTThread();
98
99 // void stopRTThread();
100
101 /** the run method of the rt thread */
102 virtual void rtRun();
103
104 bool initBusRTThread();
105
106 void controlLoopRTThread();
107
113
114 /**
115 * @brief Allows to switch controllers while calibrating
116 *
117 * use
118 * rtSetJointController(JointController* c, std::size_t index)
119 * to switch controllers
120 */
121 virtual void
125
126 /**
127 * @brief Hook to add calibration code
128 *
129 * This function is called in the rt loop! So you should not take too long!
130 *
131 * read sensors and write targets
132 * while calibrating return CalibrationStatus::Calibrating
133 * if done return CalibrationStatus::Done
134 *
135 * @return Whether done or still calibrating
136 */
137 virtual CalibrationStatus
139 {
141 }
142
143 bool
145 {
146 return _calibrationStatus == CalibrationStatus::Calibrating;
147 }
148
149 std::uintmax_t
151 {
152 return _iterationCount;
153 }
154
155 private:
157 std::atomic_uintmax_t _iterationCount = 0;
158
159 protected:
161
162 std::thread rtTask;
163 std::atomic_bool taskRunning{false};
164
165 //timestamps for the pdo updates
167
169
170 VirtualRobot::RobotNodeSetPtr rtRobotJointSet, rtRobotBodySet;
171 std::vector<std::pair<VirtualRobot::RobotNodePtr, SensorValue1DoFGravityTorque*>>
173
174 IceUtil::Time
176 {
177 return IceUtil::Time::microSeconds(properties.rtLoopTimeInUS);
178 }
179
180 void startBackupLogging();
182 std::thread backupLoggingTask;
183 std::atomic_bool backupLoggingRunning{false};
184
192
193 struct
194 {
195 std::string busConfigFilePath;
199 int rtLoopTimeInUS = 1000;
201
205 std::string periodicLoggingDirectory = "/tmp/periodic_rt_logging/";
206
210
211 std::string robotJointsNodeSet = "RobotJoints";
212 std::string robotColNodeSet = "RobotCol";
214
216 };
217
218} // namespace armarx::control::ethercat
The RobotUnit class manages a robot and its controllers.
Definition RobotUnit.h:192
IceUtil::Time getControlThreadTargetPeriod() const override
The ControlThread's period.
Definition RTUnit.h:175
std::atomic_bool taskRunning
Definition RTUnit.h:163
void joinControlThread() override
Implementations have to join their ControlThread in this hook. (used by RobotUnit::finishRunning())
Definition RTUnit.cpp:194
PeriodicLoggingMode periodicLoggingMode
Definition RTUnit.h:202
void publish(armarx::StringVariantBaseMap debugObserverMap={}, armarx::StringVariantBaseMap timingMap={}) override
Publishes data.
Definition RTUnit.cpp:203
VirtualRobot::RobotPtr robot
Definition RTUnit.h:168
VirtualRobot::RobotNodeSetPtr rtRobotJointSet
Definition RTUnit.h:170
VirtualRobot::RobotNodeSetPtr rtRobotBodySet
Definition RTUnit.h:170
struct armarx::control::ethercat::RTUnit::@220041145354046113147030301166073356361324314346 properties
std::atomic_bool backupLoggingRunning
Definition RTUnit.h:183
std::vector< std::pair< VirtualRobot::RobotNodePtr, SensorValue1DoFGravityTorque * > > nodeJointDataVec
Definition RTUnit.h:172
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition RTUnit.cpp:209
void onExitRobotUnit() override
called in onExitComponent before calling finishRunning
Definition RTUnit.cpp:134
armarx::control::ethercat::Timeouts ethercatTimeouts
Definition RTUnit.h:215
unsigned int periodicLoggingIntervalInSeconds
Definition RTUnit.h:203
static MultiNodeRapidXMLReader ReadHardwareConfigFile(std::string hardwareConfigFilePath, std::string rootNodeName)
Definition RTUnit.cpp:435
std::uintmax_t getIterationCount()
Definition RTUnit.h:150
void onConnectRobotUnit() override
called in onConnectComponent
Definition RTUnit.cpp:116
virtual CalibrationStatus rtCalibrate()
Hook to add calibration code.
Definition RTUnit.h:138
virtual void rtCalibrateActivateControlers()
Allows to switch controllers while calibrating.
Definition RTUnit.h:122
unsigned int errorCountersReadingPeriodInMS
Definition RTUnit.h:208
IceUtil::Time currentPDOUpdateTimestamp
Definition RTUnit.h:166
unsigned int periodicLoggingHistorySize
Definition RTUnit.h:204
virtual void rtRun()
the run method of the rt thread
Definition RTUnit.cpp:305
void initializeKinematicUnit() override
Initializes the KinematicUnit.
Definition RTUnit.cpp:144
void onInitRobotUnit() override
called in onInitComponent
Definition RTUnit.cpp:70
void onDisconnectRobotUnit() override
called in onDisconnecComponent
Definition RTUnit.cpp:128
std::string getDefaultName() const override
Definition RTUnit.h:68
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.