NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
ImpedanceControl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
25 // This module
26 #include "ImpedanceControl.h"
27 // This library
28 #include "tgBaseString.h"
29 
35 static const double kDefaultOffsetTension = 0.001;
36 
42 static const double kDefaultLengthStiffness = 0.0;
43 
49 static const double kDefaultVelocityStiffness = 0.0;
50 
52  _offsetTension(kDefaultOffsetTension),
53  _lengthStiffness(kDefaultLengthStiffness),
54  _velStiffness(kDefaultVelocityStiffness)
55 {
56  // Postcondition
57  assert(invariant());
58  assert(_offsetTension == kDefaultOffsetTension);
59  assert(_lengthStiffness == kDefaultLengthStiffness);
60  assert(_velStiffness == kDefaultVelocityStiffness);
61 }
62 
64  double lengthStiffness,
65  double velStiffness) :
66  _offsetTension(offsetTension),
67  _lengthStiffness(lengthStiffness),
68  _velStiffness(velStiffness)
69 {
70  // Precondition
71  assert(offsetTension >= 0.0);
72  assert(lengthStiffness >= 0.0);
73  assert(velStiffness >= 0.0);
74 
75  // Postcondition
76  assert(invariant());
77  assert(_offsetTension == offsetTension);
78  assert(_lengthStiffness == lengthStiffness);
79  assert(_velStiffness == velStiffness);
80 }
81 
93 static inline double determineVelocity(double ds, double dt)
94 {
95  return (dt > 0.0) ? (ds / dt) : 0.0;
96 }
97 
110 static inline double determineSetTension(double offset,
111  double displacement,
112  double velocity)
113 {
114  return std::max(static_cast<double>(0.0), offset + displacement + velocity);
115 }
116 
117 double
119  double deltaTimeSeconds,
120  double newPosition,
121  double offsetVel)
122 {
123  return controlTension( mString,
124  deltaTimeSeconds,
125  newPosition,
127  offsetVel);
128 }
129 
130 double
131 ImpedanceControl::controlTension(tgBaseString* const mString,
132  double deltaTimeSeconds,
133  double newPosition ,
134  double offsetTension,
135  double offsetVel)
136 {
137  // Precondition
138  assert(mString != NULL);
139 
140  const double actualLength = mString->getCurrentLength();
141  const double vel = mString->getVelocity();
142 
143  const double setTension =
144  determineSetTension(offsetTension,
145  _lengthStiffness * (actualLength - newPosition),
146  _velStiffness * (vel - offsetVel));
147 
148  mString->tensionMinLengthController(setTension,
149  deltaTimeSeconds);
150 
151  // Postcondition
152  assert(setTension >= 0.0);
153 
154  return setTension;
155 }
156 
157 void ImpedanceControl::setOffsetTension(double offsetTension)
158 {
159  // Precondition
160  assert(offsetTension >= 0.0);
161 
162  _offsetTension = offsetTension;
163 
164  // Postcondition
165  assert(invariant());
166  assert(_offsetTension == offsetTension);
167 }
168 
169 void ImpedanceControl::setLengthStiffness(double lengthStiffness)
170 {
171  // Precondition
172  assert(lengthStiffness >= 0.0);
173 
174  _lengthStiffness = lengthStiffness;
175 
176  // Postcondition
177  assert(invariant());
178  assert(_lengthStiffness == lengthStiffness);
179 }
180 
181 void ImpedanceControl::setVelStiffness(double velStiffness)
182 {
183  // Precondition
184  assert(velStiffness >= 0.0);
185 
186  _velStiffness = velStiffness;
187 
188  // Postcondition
189  assert(invariant());
190  assert(_velStiffness == velStiffness);
191 }
192 
193 bool ImpedanceControl::invariant() const
194 {
195  return
196  (_offsetTension >= 0.0) &&
197  (_lengthStiffness >= 0.0) &&
198  (_velStiffness >= 0.0);
199 }
Contains the definition of abstract base class tgBaseString. Assumes that the string is linear (F = -...
void setLengthStiffness(double lengthStiffness)
ImpedanceControl()
Constructors.
void setVelStiffness(double velStiffness)
double control(tgBaseString *const mString, double deltaTimeSeconds, double newPosition, double offsetVel=0)
Control Functions.
Contains the definition of class ImpedanceControl. $Id$.
void setOffsetTension(double offsetTension)