MIRA
SCITOSModule.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 MetraLabs GmbH (MLAB), GERMANY.
3  * All rights reserved.
4  * Contact: info@MetraLabs.com
5  *
6  * Commercial Usage:
7  * Licensees holding valid commercial licenses may use this file in
8  * accordance with the commercial license agreement provided with the
9  * software or, alternatively, in accordance with the terms contained in
10  * a written agreement between you and MetraLabs.
11  *
12  * GNU General Public License Usage:
13  * Alternatively, this file may be used under the terms of the GNU
14  * General Public License version 3.0 as published by the Free Software
15  * Foundation and appearing in the file LICENSE.GPL3 included in the
16  * packaging of this file. Please review the following information to
17  * ensure the GNU General Public License version 3.0 requirements will be
18  * met: http://www.gnu.org/copyleft/gpl.html.
19  * Alternatively you may (at your option) use any later version of the GNU
20  * General Public License if such license has been publicly approved by
21  * MetraLabs (or its successors, if any).
22  *
23  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
24  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
25  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HAS BEEN
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
31  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
32  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
33  */
34 
43 #ifndef _MIRA_SCITOSMODULE_H_
44 #define _MIRA_SCITOSMODULE_H_
45 
46 #include <factory/Factory.h>
47 #include <xml/XMLDom.h>
49 
50 #include <fw/Framework.h>
51 
52 #include <SCITOSDefines.h>
53 
54 namespace mira { namespace robot {
55 
57 
60 
62 
67 {
69 public:
70 
72  Authority(ANONYMOUS | HIDDEN),
73  mIsRunning(false) {}
74 
75  virtual ~SCITOSModule() { stop(); }
76 
78  template<typename Reflector>
79  void reflect(Reflector& r)
80  {
81  r.roproperty("Status", mNodeInfo.status, "The status of the module",
82  PropertyHints::enumeration("unknown;bootup;stopped;operational;pre-operational"));
83  }
84 
90  void initialize(SCITOSManager* manager, mira::can::CANOpenNodeInfo nodeInfo,
91  XMLDom* xml);
92 
93  virtual std::string getName() const
94  {
95  return getClass().getMetaInfo("Name");
96  }
97 
101  void updateStatus(mira::can::CANOpenNodeStatus status);
106 
107  void pauseModule();
108  void resumeModule();
109  void destructModule();
110 
111 protected:
112 
113  void processInitialization();
114  void onError(const mira::can::CANMessage& message, const Time& time);
115 
125  template <typename T>
126  void deserializeConfig(T& module, bool isOptional = true)
127  {
128  deserializeConfig(getName(), module, isOptional);
129  }
130 
135  template <typename T>
136  void deserializeConfig(const std::string& name, T& module, bool isOptional = true)
137  {
138  if (mXML->root().find(name) == mXML->root().end()) {
139  if (isOptional) {
140  MIRA_LOG(WARNING) << "SCITOSManager: No configuration for module '" << name << "', running with defaults";
141  return;
142  } else
143  MIRA_THROW(XInvalidConfig, "SCITOSManager: No configuration for module '" << name << "', which is required";)
144  }
145 
146  XMLDeserializer s(*mXML);
147  s.deserialize(name, module);
148  }
149 
153  virtual void onInitialize() = 0; // must be implemented for each module!
154  virtual void onPause() {}
155  virtual void onResume() {}
156  virtual void onDestruct() {}
157 
158  uint32 addPDOListener(can::PDOCallback pFunc, uint32 pPDO);
159 
164  void waitForHWTimestamp();
165 
166  std::set<uint32> mErrors;
167 
168  std::vector<uint32> mPDOCallbacks;
172  boost::thread mInitializationThread;
174 };
175 
176 typedef boost::shared_ptr<SCITOSModule> SCITOSModulePtr;
177 
179 
180 }}
181 
182 #endif
mira::can::CANOpenNodeInfo mNodeInfo
Informations about the CANOpen node.
Definition: SCITOSModule.h:171
virtual ~SCITOSModule()
Definition: SCITOSModule.h:75
void deserializeConfig(const std::string &name, T &module, bool isOptional=true)
See above.
Definition: SCITOSModule.h:136
Base class for all driver modules of a SCITOS robot.
Definition: SCITOSModule.h:66
SCITOSModule()
Definition: SCITOSModule.h:71
std::set< uint32 > mErrors
Definition: SCITOSModule.h:166
void reflect(Reflector &r)
Reflect method for serialization.
Definition: SCITOSModule.h:79
void deserialize(const std::string &name, T &value)
std::vector< uint32 > mPDOCallbacks
Definition: SCITOSModule.h:168
XMLDom * mXML
Definition: SCITOSModule.h:169
boost::function< void(const CANMessage &, const Time &)> PDOCallback
PropertyHint enumeration(const std::string &values)
boost::shared_ptr< SCITOSModule > SCITOSModulePtr
Definition: SCITOSModule.h:176
virtual void statusChanged(mira::can::CANOpenNodeStatus status)
Overload if listening on status changed.
Definition: SCITOSModule.h:105
#define MIRA_LOG(level)
virtual void onDestruct()
Definition: SCITOSModule.h:156
bool mIsRunning
Definition: SCITOSModule.h:173
#define MIRA_THROW(ex, msg)
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
SCITOSManager * mManager
The pointer to the manager.
Definition: SCITOSModule.h:170
virtual void onResume()
Definition: SCITOSModule.h:155
virtual std::string getName() const
Definition: SCITOSModule.h:93
#define MLAB_SCITOS_EXPORT
Definition: SCITOSDefines.h:57
boost::thread mInitializationThread
Definition: SCITOSModule.h:172
Defines for the SCITOS robot drivers.
void deserializeConfig(T &module, bool isOptional=true)
module must have the specific subclass type to deserialize to subclass (not base class).
Definition: SCITOSModule.h:126
The SCITOSManager manages all driver modules of a SCITOS robot.
Definition: SCITOSManager.h:64
virtual void onPause()
Definition: SCITOSModule.h:154