NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
NestedStructureSineWaves.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
29 
30 // Its subject
32 
33 // NTRTSim
34 #include "core/tgLinearString.h"
35 #include "core/ImpedanceControl.h"
36 #include "tgcreator/tgUtil.h"
37 
39  in_controller(new ImpedanceControl(300, 0, 0)),
40  out_controller(new ImpedanceControl(100, 200, 400)),
41  segments(1.0),
42  insideLength(20.0),
43  outsideLength(15.0),
44  offsetSpeed(0.0),
45  cpgAmplitude(20.0),
46  cpgFrequency(2.51),
47  bodyWaves(1.0),
48  simTime(0.0),
49  cycle(0.0),
50  target(0.0)
51 {
52  phaseOffsets.clear();
53  phaseOffsets.push_back(M_PI/2);
54  phaseOffsets.push_back(0);
55  phaseOffsets.push_back(0);
56 }
57 
59 {
60  delete in_controller;
61  delete out_controller;
62 }
63 
64 void NestedStructureSineWaves::applyImpedanceControlInside(const std::vector<tgLinearString*> stringList, double dt)
65 {
66  for(std::size_t i = 0; i < stringList.size(); i++)
67  {
68  double setTension = in_controller->control(stringList[i],
69  dt,
70  insideLength
71  );
72  #if (0) // Conditional compile for verbose control
73  std::cout << "Inside String " << i << " tension " << setTension
74  << " act tension " << stringList[i]->getMuscle()->getTension()
75  << " length " << stringList[i]->getMuscle()->getActualLength() << std::endl;
76  #endif
77  }
78 }
79 
80 void NestedStructureSineWaves::applyImpedanceControlOutside(const std::vector<tgLinearString*> stringList,
81  double dt,
82  std::size_t phase)
83 {
84  for(std::size_t i = 0; i < stringList.size(); i++)
85  {
86  cycle = sin(simTime * cpgFrequency + 2 * bodyWaves * M_PI * i / (segments) + phaseOffsets[phase]);
87  target = offsetSpeed + cycle*cpgAmplitude;
88 
89  double setTension = out_controller->control(stringList[i],
90  dt,
91  outsideLength,
92  target
93  );
94  #if(0) // Conditional compile for verbose control
95  std::cout << "Outside String " << i << " com tension " << setTension
96  << " act tension " << stringList[i]->getMuscle()->getTension()
97  << " length " << stringList[i]->getMuscle()->getActualLength() << std::endl;
98  #endif
99  }
100 }
101 
103 {
104  simTime += dt;
105 
106  segments = subject.getSegments();
107 
108  applyImpedanceControlInside(subject.getMuscles("inner top"), dt);
109  applyImpedanceControlInside(subject.getMuscles("inner left") , dt);
110  applyImpedanceControlInside(subject.getMuscles("inner right"), dt);
111 
112  applyImpedanceControlOutside(subject.getMuscles("inner top"), dt, 0);
113  applyImpedanceControlOutside(subject.getMuscles("inner left"), dt, 1);
114  applyImpedanceControlOutside(subject.getMuscles("inner right"), dt, 2);
115 }
116 
117 
void applyImpedanceControlOutside(const std::vector< tgLinearString * > stringList, double dt, std::size_t phase)
Contains the definition of class NestedStructureTestModel.
double control(tgBaseString *const mString, double deltaTimeSeconds, double newPosition, double offsetVel=0)
Control Functions.
Contains the definition of class ImpedanceControl. $Id$.
Contains the definition of class tgLinearString.
Contains the definition of class NestedStructureSineWaves.
virtual void onStep(NestedStructureTestModel &subject, double dt)
Contains the definition of class tgUtil and overloaded operator<<() free functions.
void applyImpedanceControlInside(const std::vector< tgLinearString * > stringList, double dt)