NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
VerticalSpineModel.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 VERTICAL_SPINE_MODEL_H
20 #define VERTICAL_SPINE_MODEL_H
21 
29 // This library
30 #include "core/tgModel.h"
31 #include "core/tgSubject.h"
32 // The C++ Standard Library
33 #include <map>
34 #include <set>
35 #include <string>
36 #include <vector>
37 
38 #include "sensors/tgDataObserver.h"
39 
40 // Forward declarations
42 class tgStructure;
43 class tgStructureInfo;
44 
45 // Declare the configuration struct(s) here. This allows us to re-use the
46 // struct type later, and also pass it around in functions.
47 
48 // A structure containing all the parameters of a spine vertebra (rigid body only.)
49 // This assumes that a vertebra is four rods.
51  std::string vertebra_name; // a name for this type of vertebra. This is used for naming the rods when calling addRodPairs.
52  double mass; // mass of this rigid body, kg
53  double radius; // radius of the cylinders that make up this body (length)
54  double leg_length; // the length of one of the cylinders, a "leg" of the tetrahedron (length)
55  double height; // total height of one vertebra, from the bottommost node to topmost (length)
56  double friction; // A constant passed down to the underlying bullet physics solver (unitless)
57  double rollFriction; // A constant passed down to the underlying bullet physics solver (unitless)
58  double restitution; // A constant passed down to the underlying bullet physics solver (unitless)
59 };
60 
61 class VerticalSpineModel: public tgSubject<VerticalSpineModel>, public tgModel
62 {
63 public:
64 
68  typedef std::map<std::string, std::vector<tgSpringCableActuator*> > MuscleMap;
69 
76  VerticalSpineModel(size_t segments);
77 
82  {}
83 
92  virtual void setup(tgWorld& world);
93 
98  virtual void step(const double dt);
99 
107  const std::vector<tgSpringCableActuator*>& getMuscles (const std::string& key) const;
108 
112  const std::vector<tgSpringCableActuator*>& getAllMuscles() const;
113 
119  size_t getSegments() const
120  {
121  return m_segments;
122  }
123 
124 private:
125 
138  static void addNodes(tgStructure& vertebra, ConfigVertebra& conf_vertebra);
139 
143  static void trace(const tgStructureInfo& structureInfo, tgModel& model);
144  // A version that includes the tgStructure:
145  static void trace(const tgStructure& structure,
146  const tgStructureInfo& structureInfo, tgModel& model);
147 
152  static void addRodPairs(tgStructure& vertebra, ConfigVertebra& conf_vertebra);
153 
161  static double getDensity(ConfigVertebra& conf_vertebra);
162 
170  static double getEdgeLength(ConfigVertebra& conf_vertebra);
171 
177  static void addSegments(tgStructure& spine, const tgStructure& vertebra,
178  double edge, size_t segmentCount);
179 
187  static void addVertebra(tgStructure& spine, ConfigVertebra& conf_vertebra,
188  size_t vertebra_number);
189 
193  static void addMuscles(tgStructure& spine);
194 
198  static void mapMuscles(VerticalSpineModel::MuscleMap& muscleMap, tgModel&
199  model, size_t segmentCount);
200 
205  std::vector<tgSpringCableActuator*> allMuscles;
206 
211  MuscleMap muscleMap;
212 
216  const size_t m_segments;
217 };
218 
219 #endif
virtual void step(const double dt)
size_t getSegments() const
const std::vector< tgSpringCableActuator * > & getMuscles(const std::string &key) const
virtual void setup(tgWorld &world)
Definition of tgSubject class.
VerticalSpineModel(size_t segments)
Contains the definition of class tgModel.
Definition of tgObserver class.
std::map< std::string, std::vector< tgSpringCableActuator * > > MuscleMap
const std::vector< tgSpringCableActuator * > & getAllMuscles() const