LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
linearmotiontransform.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef LINEARMOTIONTRANSFORM_H_
23 #define LINEARMOTIONTRANSFORM_H_
24 
25 #include <QObject>
26 #include <QString>
27 #include <QMap>
28 #include <QVector>
29 
30 #include "../../dimensionsglobal.h"
31 
32 namespace LinearMotionTransformTriggers
33 {
34  enum Component
35  {
39  };
40  enum Type
41  {
42  UNSET = 0, //do not change
43  EQUAL, //really only useful when a value will be converged on
44  FROM_LESSER, //trigger that fires when the value is crossed from less than v (left to right on numberline)
45  FROM_GREATER, //trigger that fires when the value is crossed from greater than v (right to left on numberline)
46  UNCONDITIONAL //on every computation; useful with slotTimetic()
47  };
48  enum Freq //only useful with Type == EQUAL for now
49  {
50  SINGLE, //only goes off once per EQUAL match.
51  //value must un-equal trigger and then come back to equal before next signal
52 
53  REPEATED // it will go off on every subsequent repeated evaluation that EQUALs
54  };
55 }
56 
58 {
59  Q_OBJECT
60 
61 public:
62 
63  virtual qreal setStartTime(const qreal time); //returns old start time
64  virtual qreal startTime();
65  virtual void activate();
66  virtual void deactivate();
67  virtual bool isActive() const;
68  virtual void restart(const qreal newStartTime);
69 
70  virtual qreal setAutocount(const qreal incTime); //automatically counts time on timetics. (see slotTimetic())
71  // returns old autocount increment
72  virtual void disableAutocount();
73 
74  virtual qreal setInitialDisplacement(const qreal di);
75  virtual qreal setInitialVelocity(const qreal vi);
76  virtual qreal setInitialAcceleration(const qreal ai);
77 
78  virtual qreal initialDisplacement() const;
79  virtual qreal initialVelocity() const;
80  virtual qreal initialAcceleration() const;
81 
82  virtual qreal displacement(const qreal time);
83  virtual qreal velocity(const qreal time);
84  virtual qreal acceleration(const qreal time);
85 
86  virtual void vec(const qreal time,qreal& d,qreal& v, qreal& a);
87  virtual QVector<qreal> vec(const qreal time);
88 
89  virtual void setTrigger(quint32 component,
91  const qreal val,
92  QObject * receiver,
93  const char * slot,
95  virtual void clearTrigger(quint32 component);
96 
97  //not hard enforced. interface spec that tells a correctly-implemented tr to never return + or - values for (d,v,a)
98  virtual void positiveOnly(bool v=true);
99  virtual void negativeOnly(bool v=true);
100 
101 public Q_SLOTS:
102 
103  virtual void slotTimetic(const qreal absTime=0); //absolute time coordinate (increasing)
104 
105 Q_SIGNALS:
106 
107  void signalDisplacementTrigger(qreal t,qreal d, qreal last_t,qreal last_d, LinearMotionTransformTriggers::Type reason);
108  void signalVelocityTrigger(qreal t,qreal v,qreal last_t,qreal last_v, LinearMotionTransformTriggers::Type reason);
109  void signalAccelerationTrigger(qreal t,qreal a,qreal last_t,qreal last_a, LinearMotionTransformTriggers::Type reason);
110 
111  void signalRecomputed(qreal t,qreal d,qreal v,qreal a);
112 
113 protected:
114  LinearMotionTransform(const qreal startTime=0.0);
115  virtual ~LinearMotionTransform();
116 
117  //called when initial conditions/parameters are changed
118  // (careful to not slice when subclassing and overriding)
119  virtual void parametersChanged();
120  virtual void update(const qreal t,const qreal d,const qreal v,const qreal a);
121 
122  bool m_active;
124  bool m_posOnly;
125  bool m_negOnly;
126  qreal m_startTime; //abs time
129  qreal m_autocountAccumulator; //abs time
130  qreal m_initialDisplacement; //these in general ADD to the specific transform params
133 
135  qreal m_lastComputedTime; //relative time (to startTime)
139 
144 
149 
154 
155 private:
156  void updateValuesOnly(const qreal t,const qreal d,const qreal v,const qreal a);
157  bool checkDisplacementTrigger(const qreal t,const qreal d,const qreal v,const qreal a);
158  bool checkVelocityTrigger(const qreal t,const qreal d,const qreal v,const qreal a);
159  bool checkAccelerationTrigger(const qreal t,const qreal d,const qreal v,const qreal a);
160  bool checkTrigger(const qreal t,
161  const qreal val,const qreal lastVal,
164  const qreal trigVal,
165  bool& sr);
166 };
167 
168 #endif /* LINEARMOTIONTRANSFORM_H_ */