NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
T6TensionController.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 
27 // This module
28 #include "T6TensionController.h"
29 // This application
30 #include "T6Model.h"
31 // This library
32 #include "core/tgBasicActuator.h"
33 // The C++ Standard Library
34 #include <cassert>
35 #include <stdexcept>
36 
38  m_tension(tension)
39 {
40  if (tension < 0.0)
41  {
42  throw std::invalid_argument("Negative tension");
43  }
44 }
45 
47 {
48  std::size_t n = m_controllers.size();
49  for(std::size_t i = 0; i < n; i++)
50  {
51  delete m_controllers[i];
52  }
53  m_controllers.clear();
54 }
55 
57 {
58  const std::vector<tgBasicActuator*> actuators = subject.getAllActuators();
59  for (size_t i = 0; i < actuators.size(); ++i)
60  {
61  tgBasicActuator * const pActuator = actuators[i];
62  assert(pActuator != NULL);
63  tgTensionController* m_tensController = new tgTensionController(pActuator, m_tension);
64  m_controllers.push_back(m_tensController);
65  }
66 
67 }
68 
69 void T6TensionController::onStep(T6Model& subject, double dt)
70 {
71  if (dt <= 0.0)
72  {
73  throw std::invalid_argument("dt is not positive");
74  }
75  else
76  {
77  std::size_t n = m_controllers.size();
78  for(std::size_t i = 0; i < n; i++)
79  {
80  m_controllers[i]->control(dt, m_tension);
81  }
82  }
83 }
virtual void onStep(T6Model &subject, double dt)
virtual void onSetup(T6Model &subject)
Contains the definition of class tgBasicActuator.
Contains the definition of class T6TensionController.
const std::vector< tgBasicActuator * > & getAllActuators() const
Definition: T6Model.cpp:234
T6TensionController(const double tension=.01)