NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgRBString.h
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 
19 #ifndef TG_RB_STRING_H
20 #define TG_RB_STRING_H
21 
31 #include "core/tgModel.h"
32 
33 #include "core/tgSubject.h"
34 
35 #include "core/tgBaseString.h"
36 #include "core/tgRod.h"
37 
38 #include <set>
39 #include <map>
40 
41 class tgWorld;
42 class tgLinearString;
43 
44 class tgRBString: public tgBaseString
45 {
46 public:
47 
48  struct Config
49  {
50  public:
51  // To make the complier happy. Probably should neber be called
52  Config();
53 
54  Config( std::size_t segments,
55  const tgRod::Config& rodConf,
56  const tgBaseString::Config& stringConf,
57  double minTotalLength = 0.1); // todo: find better default
58 
59  std::size_t m_segments;
60  tgRod::Config m_rodConfig;
61  tgBaseString::Config m_stringConfig;
62  double m_minTotalLength;
63  };
64 
65  tgRBString(const tgTags& tags,
66  tgRBString::Config& config,
67  double restLength);
68 
69  tgRBString(std::string space_separated_tags,
70  tgRBString::Config& config,
71  double restLength);
72 
73  virtual ~tgRBString() {}
74 
76  virtual void setup(tgWorld& world);
77 
78  // @todo: Is there a way that we can get rid of the need to override this function in subclasses of tgModel?
79  // comment_BRT: only if we can somehow make tgModel a template class,
80  // we need to know what class we're notifying
81  virtual void step(double dt);
82 
83  void changeMuscles (double lengthPercent, double dt);
84 
85  virtual void teardown();
86 
87  virtual void moveMotors(double dt);
88 
89  virtual void tensionMinLengthController(const double targetTension,
90  float dt);
91 
92  virtual const double getStartLength() const;
93 
94  /* May want to calculate the point to point distance between
95  * connection points. Need to store a lot more things to do
96  * that.
97  */
98 
99  virtual const double getCurrentLength() const;
100 
101  virtual const double getTension() const;
102 
103  virtual const double getRestLength() const;
104 
105  virtual const double getVelocity() const;
106 
107  const int getSegments() const
108  {
109  return m_config.m_segments;
110  }
111 
112 private:
113 
114  const double computeVelocity(const double dt) const;
115 
116  void logHistory(const double dt);
117 
118 private:
119  std::vector<tgLinearString*> allMuscles;
120  std::vector<tgRod*> allSegments;
121 
122  Config m_config;
123 
124  // Compute at setup based on number of segments and stiffness
125  // If setup can be eliminated this can be const
126  double m_effectiveStiffness;
127 
128  bool history;
129 };
130 
131 #endif // TG_RB_STRING_TEST_H
virtual void teardown()
Definition: tgRBString.cpp:112
Contains the definition of abstract base class tgBaseString. Assumes that the string is linear (F = -...
virtual void moveMotors(double dt)
Definition: tgRBString.cpp:161
Definition of tgSubject class.
Contains the definition of class tgModel. $Id$.
virtual void setup(tgWorld &world)
Definition: tgRBString.cpp:77
virtual void step(double dt)
Definition: tgRBString.cpp:117
Contains the definition of class tgRod $Id$.
Definition: tgTags.h:43