NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgCPGStringControl_mod.cpp
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 
19 #include "tgCPGStringControl_mod.h"
20 
22 #include "util/CPGEquations.h"
23 #include "core/tgBasicActuator.h"
24 
25 #include <iostream>
26 #include <stdexcept>
27 
28 tgCPGStringControl_mod::tgCPGStringControl_mod(const double controlStep) :
29 tgCPGActuatorControl(controlStep)
30 {
31  if (m_controlStep < 0.0)
32  {
33  throw std::invalid_argument("Negative control step");
34  }
35 }
36 
37 tgCPGStringControl_mod::~tgCPGStringControl_mod()
38 {
39 
40 }
41 
43 {
44  m_controlTime += dt;
45  m_totalTime += dt;
46 
47  tgBasicActuator& m_sca = *(tgCast::cast<tgSpringCableActuator, tgBasicActuator>(subject));
48 
52  {
53  // Encoder inversion for hardware comparison.
54  if (m_nodeNumber == 2 || m_nodeNumber == 4 || m_nodeNumber == 5 || m_nodeNumber == 6 || m_nodeNumber == 7 || m_nodeNumber == 8)//||m_nodeNumber == 9|| m_nodeNumber == 10 )
55  {
56  m_commandedTension = motorControl().control(m_sca, m_controlTime, controlLength(), -getCPGValue());
57  }
58  else
59  {
60  m_commandedTension = motorControl().control(m_sca, m_controlTime, controlLength(), getCPGValue());
61  }
62  m_controlTime = 0;
63  }
64  else
65  {
66  m_sca.moveMotors(dt);
67  }
68 }
Contains the definition of class ImpedanceControl. $Id$.
virtual void moveMotors(double dt)
virtual void onStep(tgSpringCableActuator &subject, double dt)
Contains the definition of class tgBasicActuator.
Definition of class CPGEquations.
double control(tgBasicController &mLocalController, double deltaTimeSeconds, double newPosition, double offsetVel=0)
Control Functions.