NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgSpringCableActuator.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 
26 // This Module
27 #include "tgSpringCableActuator.h"
28 #include "tgSpringCable.h"
29 #include "tgWorld.h"
30 // The C++ Standard Library
31 #include <cmath>
32 #include <iostream>
33 #include <stdexcept>
34 
35 using namespace std;
36 
38  double d,
39  double p,
40  bool h,
41  double mf,
42  double tVel,
43  double mnAL,
44  double mnRL,
45  double rot) :
46  stiffness(s),
47  damping(d),
48  pretension(p),
49  hist(h),
50  maxTens(mf),
51  targetVelocity(tVel),
52  minActualLength(mnAL),
53  minRestLength(mnRL),
54  rotation(rot)
55 {
57  if (s < 0.0)
58  {
59  throw std::invalid_argument("stiffness is negative.");
60  }
61  else if (d < 0.0)
62  {
63  throw std::invalid_argument("damping is negative.");
64  }
65  /* Pretension is checked in Muscle2P, and can be any value
66  * i.e. starting with a slack string
67  */
68  else if (mf < 0.0)
69  {
70  throw std::invalid_argument("max tension is negative.");
71  }
72  else if (mnAL < 0.0)
73  {
74  throw std::invalid_argument("min Actual Length is negative.");
75  }
76  else if (mnRL < 0.0)
77  {
78  throw std::invalid_argument("min Rest Length is negative.");
79  }
80  else if (abs(rot) > M_PI * 2.0)
81  {
82  throw std::invalid_argument("Abs of rotation is greater than 2pi. Are you sure you're setting the right parameters?");
83  }
84 }
85 
87 {
88  pretension *= sf;
89  maxTens *= sf;
90  targetVelocity *= sf;
91  minActualLength *= sf;
92  minRestLength *= sf;
93 }
94 
95 
96 
97 void tgSpringCableActuator::constructorAux()
98 {
99  if (m_config.targetVelocity < 0.0)
100  {
101  throw std::invalid_argument("Target velocity is negative.");
102  }
103  else if (m_config.minActualLength < 0.0)
104  {
105  throw std::invalid_argument("Minimum length is negative.");
106  }
107  else if (m_restLength < 0.0)
108  {
109  throw std::invalid_argument("Starting rest length is negative.");
110  }
111 }
113  const tgTags& tags,
115  tgModel(tags),
116  m_springCable(springCable),
117  m_config(config),
119  m_restLength(springCable->getRestLength()),
120  m_startLength(springCable->getActualLength()),
121  m_prevVelocity(0.0)
122 {
123  constructorAux();
124 
125  // Postcondition
126  assert(invariant());
127  assert(m_springCable == springCable);
128 }
129 
131 {
132  delete m_springCable;
133  delete m_pHistory;
134 }
135 
137 {
138  tgModel::setup(world);
139 }
140 
142 {
144 }
145 
147 {
148  if (dt <= 0.0)
149  {
150  throw std::invalid_argument("dt is not positive.");
151  }
152  else
153  {
154  tgModel::step(dt);
155  }
156 }
157 
159 {
160  return m_startLength;
161 }
162 
164 {
165  return m_springCable->getActualLength();
166 }
167 
169 {
170  return m_springCable->getTension();
171 }
172 
174 {
175  return m_springCable->getRestLength();
176 }
177 
179 {
180  return m_springCable->getVelocity();
181 }
182 
184 {
185  return *m_pHistory;
186 }
187 
188 bool tgSpringCableActuator::invariant() const
189 {
190  return
191  // Only know this about history here, can't confirm how child
192  // classes need to log
193  (m_pHistory != NULL) &&
194  (m_config.targetVelocity >= 0.0) &&
195  (m_config.minActualLength >= 0.0) &&
196  (m_startLength >= 0.0);
197 }
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
Definitions of class tgSpringCable.
virtual const double getVelocity() const
virtual const double getTension() const
virtual void setup(tgWorld &world)
virtual const double getStartLength() const
virtual void step(double dt)
Definition: tgModel.cpp:84
virtual const double getRestLength() const
virtual const tgSpringCableActuator::SpringCableActuatorHistory & getHistory() const
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
tgSpringCableActuator(tgSpringCable *springCable, const tgTags &tags, tgSpringCableActuator::Config &config)
virtual const double getVelocity() const
Contains the definition of class tgWorld $Id$.
virtual const double getTension() const =0
virtual void step(double dt)
virtual const double getRestLength() const
Config(double s=1000.0, double d=10.0, double p=0.0, bool h=false, double mf=1000.0, double tVel=100.0, double mnAL=0.1, double mnRL=0.1, double rot=0)
virtual const double getActualLength() const =0
virtual const double getCurrentLength() const
SpringCableActuatorHistory *const m_pHistory
Definition: tgTags.h:44