NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBaseCPGNode.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 "tgBaseCPGNode.h"
29 // This library
31 #include "CPGEquations.h"
32 // The C++ Standard Library
33 #include <iostream>
34 #include <stdexcept>
35 
36 using namespace std;
37 
38 tgBaseCPGNode::tgBaseCPGNode() :
39  m_pMotorControl(NULL),
40  m_pCPGSystem(NULL),
41  m_nodeNumber(-1)
42 {
43 }
44 
45 tgBaseCPGNode::~tgBaseCPGNode()
46 {
47  delete m_pMotorControl;
48  // Model deletes the CPG system
49  // Should have already torn down.
50 }
51 
52 void tgBaseCPGNode::setupControl(tgImpedanceController& ipc)
53 {
54  if (m_nodeNumber == -1)
55  {
56  throw std::runtime_error("Not yet initialized");
57  }
58  else
59  {
60  m_pMotorControl = &ipc;
61  }
62 }
63 
64 double tgBaseCPGNode::getCPGValue() const
65 {
66  double cpgValue = 0.0;
67  if (m_pCPGSystem == NULL)
68  {
69  throw std::runtime_error("CPG not initialized!");
70  }
71  else
72  {
73  cpgValue = (*m_pCPGSystem)[m_nodeNumber];
74  }
75  return cpgValue;
76 }
77 
78 tgImpedanceController& tgBaseCPGNode::motorControl() const
79 {
80  if (m_pMotorControl == NULL)
81  {
82  throw std::runtime_error("Motor control has not been set.");
83  }
84  else
85  {
86  return *m_pMotorControl;
87  }
88 }
89 
90 void tgBaseCPGNode::updateTensionSetpoint(double newTension)
91 {
92  if (newTension >= 0.0)
93  {
94  m_pMotorControl->setOffsetTension(newTension);
95  }
96  else
97  {
98  throw std::runtime_error("Tension setpoint is less than zero!");
99  }
100 }
101 
102 void tgBaseCPGNode::updateControlLength(double newControlLength)
103 {
104  if (newControlLength >= 0.0)
105  {
106  m_controlLength = newControlLength;
107  }
108  else
109  {
110  throw std::runtime_error("Length setpoint is less than zero!");
111  }
112 }
Contains the definition of class ImpedanceControl. $Id$.
void updateTensionSetpoint(double newTension)
void updateControlLength(double newControlLength)
Definition of class CPGEquations.
void setOffsetTension(double offsetTension)
Definition of class tgBaseCPGNode.