Main Page · Modules · All Classes · Class Hierarchy
MADevice.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 "MAContainerLocker.hpp"
25 #include "MACoreTypes.hpp"
26 #include "MANum.hpp"
27 #include "MASignal.hpp"
28 
29 #include <boost/shared_ptr.hpp>
30 
31 #include <string>
32 #include <vector>
33 
34 class MAController;
35 class MADevice;
36 class MAGeneratorBase;
38 
44 namespace MA
45 {
46 typedef enum
47 {
48  NormalSampling = 0,
49  InterpolationSampling,
50  PreciseAveraging,
51 } SamplingType;
52 }
53 
58 {
59  MA_CONTAINER_LOCK_ID_VARIABLE(GeneratorContainers)
60 public:
62  typedef MASignal<MADevice&> DeviceValueChangeSignalType;
63 
64  MADevice(const std::string& name, const std::string& display_name, bool motor = false);
65  virtual ~MADevice();
66 
67  static MA::DeviceList& GetDevices();
68  static MA::DeviceList& GetMotors();
69  static std::string GetMotorDisplayName(const std::string& motor_name);
70  void BlockExpiredContainerSignal();
71  void UnblockJustExpiredSignal();
72  bool IsJustExpiredSignalBlocked() const;
73  bool IsMotor() const;
74  virtual void SetPower(bool new_state);
75  bool IsPowerOn() const;
76  void SetInMotion(bool new_state);
77  bool IsInMotion() const;
78  virtual bool IsOverloaded() const;
79  float GetForce() const;
80  void SetController(MAController& controller);
81  MAController* GetController() const;
82  const std::string& GetName() const;
83  const std::string& GetDisplayName() const;
84  MAGeneratorContainer* AddGenerator(MAGeneratorBase& new_generator);
85  void AddGeneratorContainer(MAGeneratorContainer& new_container);
86  MAGeneratorContainer* AddGeneratorDelay(int msec);
87  bool HasGeneratorContainer(MAGeneratorContainer& container) const;
88  void SwapGeneratorContainer(MAGeneratorContainer& old_container, MAGeneratorContainer& new_container);
89  void DeleteGeneratorContainer(MAGeneratorContainer& container);
90  void ClearGenerators();
91  void StartGenerators();
92  virtual bool RunGenerators();
93 private:
94  float GetBlendedValue();
95 public:
96  virtual void SetNextValue(float new_value);
97  void SetSoftLimit(float new_limit);
98  float GetSoftLimit();
99  void ResetSoftLimit();
100 private:
101  void ScaleGenerators(float min, float max, float new_max);
102 protected:
103  void SetMinMaxValues(float min, float max);
104 public:
105  bool HasGenerator() const;
106  bool HasRealGenerator() const;
107  void DumpGenerators() const;
108  float GetNextValue() const;
109  float GetMinValue() const;
110  float GetMaxValue() const;
111  float GetValueChange() const;
112  bool HasSensorValue() const;
113  float GetSensorValue() const;
114  void SetRealSensorValue(float new_value);
115  float GetRealSensorValue() const;
116  void SetRealSensorValues(const MC::FloatList& values);
117  const MC::FloatList& GetRealSensorValues() const;
118  // Note: The second parameter is valid for interpolation as interval
119  void SetSamplingMode(MA::SamplingType sampling_mode, int param = 0);
120  MA::SamplingType GetSamplingMode() const;
121 
123  boost::shared_ptr<DeviceValueChangeSignalType> DeviceValueChangeSignal;
124 protected:
126  std::string Name;
128  std::string DisplayName;
130  bool Motor;
134  float Force;
140  bool PowerOn;
142  bool InMotion;
145 private:
147  float SoftLimit;
149  MA::SamplingType SamplingMode;
150  /*
151  * The real sensor value
152  * (infinite value -> the real sensor value has not been initialized.)
153  */
154  float RealSensorValue;
155  /*
156  * The previous real sensor value
157  * (infinite value -> the real sensor value has not been initialized.)
158  */
159  float PreviousRealSensorValue;
160  /*
161  * The sensor value
162  * (infinite value -> the sensor value has not been initialized.)
163  * Note: If the sensor value is interpolated caused by sampling rate,
164  * this variable will hold the interpolated version of the sensor
165  * values.
166  */
167  float SensorValue;
169  MC::FloatList RealSensorValues;
181  MA::GeneratorContainerList GeneratorContainers;
182 };
183 
float SoftLimit
Optional soft limit for the device value.
Definition: MADevice.hpp:147
int LastGeneratedValueTimestamp
Timestamp of the last generated value.
Definition: MADevice.hpp:179
Container locker class.
std::string DisplayName
Device display name.
Definition: MADevice.hpp:128
float Force
Motor force value.
Definition: MADevice.hpp:134
float LastGeneratedValue
The stored last generated value.
Definition: MADevice.hpp:177
bool InMotion
Whenever the motor is in motion.
Definition: MADevice.hpp:142
int SamplingCounter
A counter for sampling.
Definition: MADevice.hpp:173
MA::GeneratorContainerList GeneratorContainers
Value generator containers.
Definition: MADevice.hpp:181
float OverLoadLimitInIdle
Overload limit when in idle state.
Definition: MADevice.hpp:138
Base class for the controllers.
Device class.
Definition: MADevice.hpp:57
float OverLoadLimitWhenMoving
Overload limit when moving.
Definition: MADevice.hpp:136
bool PowerOn
Whenever switched on/off.
Definition: MADevice.hpp:140
MA::SamplingType SamplingMode
Sampling mode.
Definition: MADevice.hpp:149
MASignal< MADevice & > DeviceValueChangeSignalType
Device value change signal type.
Definition: MADevice.hpp:62
MANum< float > NextValue
Next device value.
Definition: MADevice.hpp:132
MC::FloatList RealSensorValues
High granularity sensor values.
Definition: MADevice.hpp:169
Generator container class.
float SamplingDelta
Sampling delta to generate new values.
Definition: MADevice.hpp:175
std::string Name
Device name.
Definition: MADevice.hpp:126
MAController * Controller
The controller where the motor belongs to.
Definition: MADevice.hpp:144
int SamplingInterval
Defines the sampling interval for the sensor device if needed.
Definition: MADevice.hpp:171
#define MA_CONTAINER_LOCK_ID_VARIABLE(_container)
Declaring a variable ID for a container.
Base class for generators.
boost::shared_ptr< DeviceValueChangeSignalType > DeviceValueChangeSignal
Device value change signal.
Definition: MADevice.hpp:123
bool Motor
Whenever it is a motor.
Definition: MADevice.hpp:130