NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
SuperBallModel.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 SUPERBALL_MODEL_H
20 #define SUPERBALL_MODEL_H
21 
28 // This library
29 #include "core/tgModel.h"
30 #include "core/tgSubject.h"
31 #include "core/tgRod.h"
32 // The C++ Standard Library
33 #include <vector>
34 #include "heightSensor.h"
35 
36 // Forward declarations
37 class tgBasicActuator;
38 class tgModelVisitor;
39 class tgStructure;
40 class tgWorld;
41 
45 class SuperBallModel : public tgSubject<SuperBallModel>, public tgModel
46 {
47 public:
48 
54  SuperBallModel(tgWorld& world);
55 
60  virtual ~SuperBallModel();
61 
70  virtual void setup(tgWorld& world);
71 
76  void teardown();
77 
82  virtual void step(double dt);
83 
91  virtual void onVisit(tgModelVisitor& r);
92 
97  const std::vector<tgBasicActuator*>& getAllMuscles() const;
98 
102  std::vector<double> getSensorInfo();
103 
104 
108  std::vector< btVector3 > getSensorPositions();
109 
113  std::vector< btVector3 > getSensorOrientations();
114 
115  //Return the center of the sensor positions
116  btVector3 getCenter();
117 
118  //Return the physical world
119  btDynamicsWorld *getWorld();
120 
121  //Given the base 3 nodes, it fills the default node numbering schema
122  void fillNodeNumberingSchema(int a,int b,int c);
123 
124  //Given the new base points fill the map from the new nodes what they would match in default node numbering
125  void fillNodeMappingFromBasePoints(int a,int b,int c);
126 
127  //Fill the list of pointers to the muscles for each node.
128  void fillMusclesPerNode();
129 
130  const std::vector<std::vector<tgBasicActuator*> >& getMusclesPerNodes() const {
131  return musclesPerNodes;
132  }
133 
134  //Returns the node number that is at the same rod with the node i
135  int getOtherEndOfTheRod(int i);
136 
137  //nodeMapping that maps the nodes in current orientation to the nodes in the default orientation
138  int nodeMapping[13];
139  //nodeMapping that maps the nodes in default orientation to the nodes in the current orientation
140  int nodeMappingReverse[13];
141  //muscle connections between the nodes.
142  int muscleConnections[13][13];
143  //contains pointer to the muscle for a given pair of nodes
144  std::vector<std::vector <tgBasicActuator *> > musclesPerNodes;
145 
146 private:
147 
154  void addNodes(tgStructure& s);
155 
161  static void addRods(tgStructure& s);
162 
168  void addMuscles(tgStructure& s);
169 
170  /*
171  * Adds the 12 markers to the end of the rods so that we can visualize
172  * them and track their position
173  */
174  void addMarkers();
175 
179  void addSensors();
180 
181 
182  /*
183  * Moves all the rods (that are actually all the rigid bodies) according to the arguments.
184  * First rotates the structure around 3 axises given 3 angles.
185  * Moves the structure to the target point.
186  * Sets all the bars speed to the given speed vector.
187  * (muscles and markers are moved automatically since they are attached).
188  */
189  void moveModel(btVector3 targetPositionVector,btVector3 rotationVector,btVector3 speedVector);
190 
195  std::vector<tgBasicActuator*> allMuscles;
196  std::vector<std::vector<std::vector<int> > > nodeNumberingSchema;
197  std::vector<btVector3> nodePositions;
198  std::vector<heightSensor> heightSensors;
199 
200  tgWorld& m_world;
201 };
202 
203 #endif // SUPERBALL_MODEL_H
std::vector< double > getSensorInfo()
std::vector< btVector3 > getSensorOrientations()
Definition of tgSubject class.
const std::vector< tgBasicActuator * > & getAllMuscles() const
Contains the definition of class tgModel.
virtual void step(double dt)
virtual ~SuperBallModel()
virtual void setup(tgWorld &world)
std::vector< btVector3 > getSensorPositions()
virtual void onVisit(tgModelVisitor &r)
Contains the definition of class tgRod.
SuperBallModel(tgWorld &world)