Main Page · Modules · All Classes · Class Hierarchy
MAController.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include <boost/bind.hpp>
25 #include <boost/tuple/tuple.hpp>
26 
27 #include "core/MACoreTypes.hpp"
28 #include "core/MAContainerLocker.hpp"
29 #include "core/MASignal.hpp"
30 #include "types/skits/MASkitBase.hpp"
31 #include "types/MARobotStateUpdater.hpp"
32 
38 // boost::mem_fn() is needed to be backward compatible with gcc 3.x
39 // http://lists.mech.kuleuven.be/pipermail/orocos-dev/2006-July/001777.html
40 // http://www.gitorious.org/orocos-toolchain/rtt/commit/9d229df407bd1f67332998d2b693ed5f285053d2
41 #define MA_BIND_TRANSITION(_class, _action, _check) \
42  _action##Str = #_action; \
43  Transitions[#_action] = boost::make_tuple(boost::bind<MA::DeviceGeneratorsMap>(boost::mem_fn(&_class::_action), this), \
44  boost::bind<bool>(boost::mem_fn(&_class::_check), this), \
45  MA::DeviceGeneratorsMap());
46 
47 // boost::mem_fn() is needed to be backward compatible with gcc 3.x
48 // http://lists.mech.kuleuven.be/pipermail/orocos-dev/2006-July/001777.html
49 // http://www.gitorious.org/orocos-toolchain/rtt/commit/9d229df407bd1f67332998d2b693ed5f285053d2
50 #define MA_BIND_TRANSITION_ACTION(_class, _action) \
51  _action##Str = #_action; \
52  Transitions[#_action] = boost::make_tuple(boost::bind<MA::DeviceGeneratorsMap>(boost::mem_fn(&_class::_action), this), \
53  MA::BoolFuncPtr(), \
54  MA::DeviceGeneratorsMap());
55 
56 #define MA_DECLARE_TRANSITION(_action, _check) \
57 private: \
58  MA::DeviceGeneratorsMap _action(); \
59 public: \
60  std::string _action##Str; \
61  bool _check() const;
62 
63 #define MA_DECLARE_TRANSITION_ACTION(_action) \
64 private: \
65  MA::DeviceGeneratorsMap _action(); \
66 public: \
67  std::string _action##Str;
68 
69 namespace MA
70 {
72 typedef boost::function<MA::DeviceGeneratorsMap ()> TransitionStartFuncPtr;
74 typedef boost::tuple<TransitionStartFuncPtr, BoolFuncPtr, DeviceGeneratorsMap> TransitionTuple;
75 /*
76  * Transition map
77  * name -> (duration, pointer to starter function, pointer to isSuccess()-like function)
78  */
79 typedef boost::unordered_map<std::string, TransitionTuple> TransitionMap;
80 
82 typedef enum
83 {
84  MotorController = 0,
85  LedController,
86  SpeakerController,
87  OtherController
88 } ControllerType;
89 }
90 
95 {
96  MA_SLOT_CLASS
99 public:
100 
108  explicit MAController(MA::ControllerType controller_type);
109  virtual ~MAController();
110 
118  MC::StringList GetTransitionNames() const;
119 
129  MC::StringList GetActiveTransitionsByDevice(const MADevice& device);
130 
147  virtual int StartTransition(const std::string& name);
148 
156  virtual void StopTransition(const std::string& name);
157 
167  virtual MA::DeviceGeneratorsMap GetSkitTransitionGenerators(MA::SkitBaseSPtr skit) = 0;
168 
178  bool IsTransitionActive(const std::string& name);
179 
187  bool IsAnyActiveTransition();
188 
196  bool IsAnyActiveSkitTransition();
197 
207  bool IsTransitionSuccessful(const std::string& name);
208 
218  bool TransitionHasCheck(const std::string& name);
219 
227  virtual MA::DeviceList GetMotors() const = 0;
228 
229 protected:
230 
238  void GeneratorContainerExpired(MAGeneratorContainer& container);
239 
249  MA::TransitionMap::iterator RegisterSkitTransition(const std::string& skit_name);
250 
251 private:
252 
262  int GetDeviceGeneratorsDuration(MA::DeviceGeneratorsMap& device_generators);
263 
264 public:
265 
273  static void SetVerbose(bool new_state);
274 
282  static bool IsVerbose();
283 
284 protected:
286  MA::ControllerType Type;
288  MA::TransitionMap Transitions;
289 };
290 
Container locker class.
Base class for the controllers.
Device class.
Definition: MADevice.hpp:57
#define MC_DISABLE_COPY(class_name)
Helper macro to disable the copy constructor and assignment operator of a class (object copying) ...
Definition: MCDefs.hpp:604
Generator container class.
Robot state updater base class.
#define MA_CONTAINER_LOCK_ID_VARIABLE(_container)
Declaring a variable ID for a container.
MA::ControllerType Type
Controller type.
MA::TransitionMap Transitions
The map of the transitions.