NTRT Simulator  Version: Master
 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  bool moveCPA,
47  bool moveCPB) :
48  stiffness(s),
49  damping(d),
50  pretension(p),
51  hist(h),
52  maxTens(mf),
53  targetVelocity(tVel),
54  minActualLength(mnAL),
55  minRestLength(mnRL),
56  rotation(rot),
57  moveCablePointAToEdge(moveCPA),
58  moveCablePointBToEdge(moveCPB)
59 {
61  if (s < 0.0)
62  {
63  throw std::invalid_argument("stiffness is negative.");
64  }
65  else if (d < 0.0)
66  {
67  throw std::invalid_argument("damping is negative.");
68  }
69  /* Pretension is checked in Muscle2P, and can be any value
70  * i.e. starting with a slack string
71  */
72  else if (mf < 0.0)
73  {
74  throw std::invalid_argument("max tension is negative.");
75  }
76  else if (mnAL < 0.0)
77  {
78  throw std::invalid_argument("min Actual Length is negative.");
79  }
80  else if (mnRL < 0.0)
81  {
82  throw std::invalid_argument("min Rest Length is negative.");
83  }
84  else if (abs(rot) > M_PI * 2.0)
85  {
86  throw std::invalid_argument("Abs of rotation is greater than 2pi. Are you sure you're setting the right parameters?");
87  }
88 }
89 
91 {
92  pretension *= sf;
93  maxTens *= sf;
94  targetVelocity *= sf;
95  minActualLength *= sf;
96  minRestLength *= sf;
97 }
98 
99 
100 
101 void tgSpringCableActuator::constructorAux()
102 {
103  if (m_config.targetVelocity < 0.0)
104  {
105  throw std::invalid_argument("Target velocity is negative.");
106  }
107  else if (m_config.minActualLength < 0.0)
108  {
109  throw std::invalid_argument("Minimum length is negative.");
110  }
111  else if (m_restLength < 0.0)
112  {
113  throw std::invalid_argument("Starting rest length is negative.");
114  }
115 }
117  const tgTags& tags,
119  tgModel(tags),
120  m_springCable(springCable),
121  m_config(config),
123  m_restLength(springCable->getRestLength()),
124  m_startLength(springCable->getActualLength()),
125  m_prevVelocity(0.0)
126 {
127  constructorAux();
128 
129  // Postcondition
130  assert(invariant());
131  assert(m_springCable == springCable);
132 }
133 
135 {
136  delete m_springCable;
137  delete m_pHistory;
138 }
139 
141 {
142  tgModel::setup(world);
143 }
144 
146 {
148 }
149 
151 {
152  if (dt <= 0.0)
153  {
154  throw std::invalid_argument("dt is not positive.");
155  }
156  else
157  {
158  tgModel::step(dt);
159  }
160 }
161 
163 {
164  return m_startLength;
165 }
166 
168 {
169  return m_springCable->getActualLength();
170 }
171 
173 {
174  return m_springCable->getTension();
175 }
176 
178 {
179  return m_springCable->getRestLength();
180 }
181 
183 {
184  return m_springCable->getVelocity();
185 }
186 
188 {
189  return *m_pHistory;
190 }
191 
192 bool tgSpringCableActuator::invariant() const
193 {
194  return
195  // Only know this about history here, can't confirm how child
196  // classes need to log
197  (m_pHistory != NULL) &&
198  (m_config.targetVelocity >= 0.0) &&
199  (m_config.minActualLength >= 0.0) &&
200  (m_startLength >= 0.0);
201 }
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
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, bool moveCPA=true, bool moveCPB=true)
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
virtual const double getActualLength() const =0
virtual const double getCurrentLength() const
SpringCableActuatorHistory *const m_pHistory
Definition: tgTags.h:44