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