NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
VerticalSpinePassiveController.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
28 // This application
29 #include "VerticalSpineModel.h"
30 // This library
31 //#include "core/tgBasicActuator.h"
33 #include "core/tgString.h"
34 #include "sensors/tgDataObserver.h"
35 // The C++ Standard Library
36 #include <cassert>
37 #include <stdexcept>
38 #include <vector>
39 
40 #include "helpers/FileHelpers.h"
41 
43  m_updateTime(0.01),
44  m_dataObserver("logs/vertspine_passive_")
45 {
46 }
47 
49  m_dataObserver.onSetup(subject);
50  // Since this class only updates the logs every so often (according to
51  // m_updateTime), need to track a counter of time between steps.
52  updateTime = 0.0;
53 
54  // Debugging: what does this model look like?
55  //std::cout << "This VerticalSpineModel has the following contents:" << std::endl;
56  //std::cout << subject << std::endl;
57 }
58 
60 {
61  // first, check if our input arguments are sane
62  if( dt <= 0.0)
63  {
64  throw std::invalid_argument("dt is not positive");
65  }
66  else
67  {
68  // check our update time. This is so that samples are taken only every
69  // certain number of steps, not all the time.
70  updateTime += dt;
71  if( updateTime >= m_updateTime )
72  {
73  // Take a step: call the observers' step function.
74  // TO FIX: why do we have to call the data logger's onStep individually?
75  notifyStep(updateTime);
76  m_dataObserver.onStep(subject, updateTime);
77  // then, reset the counter to zero
78  updateTime = 0.0;
79  }
80  }
81  // log only.
82  //notifyStep(dt);
83  //m_dataObserver.onStep(subject, dt);
84 }
virtual void onStep(VerticalSpineModel &subject, double dt)
Convenience function for combining strings with ints, mostly for naming structures.
Contains the definition of class VerticalSpinePassiveController.
Contains the definition of class VerticalSpineModel.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
A series of functions to assist with file input/output.
Definition of tgObserver class.
virtual void onStep(tgModel &model, double dt)
virtual void onSetup(tgModel &model)
virtual void onSetup(VerticalSpineModel &subject)