NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tensionsensor.cpp
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
28 //#include "RPModel.h"
29 // This library
30 #include "core/tgBasicActuator.h"
31 #include "core/tgRod.h"
32 #include "tgcreator/tgBuildSpec.h"
34 #include "tgcreator/tgRodInfo.h"
35 #include "tgcreator/tgStructure.h"
37 // The Bullet Physics library
38 #include "LinearMath/btVector3.h"
39 // The C++ Standard Library
40 #include <stdexcept>
41 #include <iostream>
42 #include <fstream>
43 
44 namespace
45 {
46  // see tgBasicActuator and tgRod for a descripton of these rod parameters
47  // (specifically, those related to the motor moving the strings.)
48  // NOTE that any parameter that depends on units of length will scale
49  // with the current gravity scaling. E.g., with gravity as 98.1,
50  // the length units below are in decimeters.
51 
52  // Note: This current model of the SUPERball rod is 1.5m long by 3 cm radius,
53  // which is 0.00424 m^3.
54  // For SUPERball v1.5, mass = 3.5kg per strut, which comes out to
55  // 0.825 kg / (decimeter^3).
56 
57  // similarly, frictional parameters are for the tgRod objects.
58 
59  //const double sf = 20;//scaling factor with respect to meter scale. E.g., centimeter scale is achieved by setting sf = 100
60  //const double length_scale = 0.25; //1 makes 4 m long rods
61  // In meter scale, the robot is too small, while in centimeter scale, the robot rotates freely (free energy!)
62  // Also, don't forget to change gravity scale in AppThruster.cpp and T6Thruster.cpp!
63 
64  const struct Config
65  {
66  double density;
67  double radius;
68  double stiffness;
69  double damping;
70  double rod_length;
71  double rod_space;
72  double friction;
73  double rollFriction;
74  double restitution;
75  double pretension;
76  bool hist;
77  double maxTens;
78  double targetVelocity;
79  }
80  c =
81  {
82  2700/pow(sf,3),//0.688, // density (kg / length^3)
83  0.0254*sf,//0.31, // radius (length)
84  600,//1192.5*10,//613.0, // stiffness (kg / sec^2) was 1500
85  500, // damping (kg / sec)
86  4*sf*length_scale, // rod_length (length)
87  .02*sf, // rod_space (length)
88  0.99, // friction (unitless)
89  0.1, // rollFriction (unitless)
90  0.0, // restitution (?)
91  150*sf, //610, // pretension -> set to 4 * 613, the previous value of the rest length controller
92  0, // History logging (boolean)
93  300*sf, // maxTens
94  .02, //sf, // targetVelocity
95 
96  // Use the below values for earlier versions of simulation.
97  // 1.006,
98  // 0.31,
99  // 300000.0,
100  // 3000.0,
101  // 15.0,
102  // 7.5,
103  };
104 
105 } // namespace
106 
107 RPModel::RPModel() : tgModel()
108 {
109 }
110 
111 RPModel::~RPModel()
112 {
113 }
114 
115 void RPModel::setup(tgWorld& world)
116 {
117 
118  allAbstractMarkers=tgCast::filter<tgModel, abstractMarker> (getDescendants());
119 
120 }
121 
122 void RPModel::step(double dt)
123 {
124  // Precondition
125  if (dt <= 0.0)
126  {
127  throw std::invalid_argument("dt is not positive");
128  }
129  else
130  {
131  // Notify observers (controllers) of the step so that they can take action
132  notifyStep(dt);
133  tgModel::step(dt); // Step any children
134  }
135  for(int k=1;k<36;k++){
136  std::cout << allActuators[k]->getTension() << " ";
137  }
138  std::cout << std::endl;
139 
140 }
141 
142 
143 void RPModel::onVisit(tgModelVisitor& r)
144 {
145  tgModel::onVisit(r);
146 }
147 
148 const std::vector<tgBasicActuator*>& RPModel::getAllActuators() const
149 {
150  return allActuators;
151 }
152 
153 
154 const std::vector<tgRod*>& RPModel::getAllRods() const
155 {
156  return allRods;
157 }
158 
159 const std::vector<tgBaseRigid*>& RPModel::getAllBaseRigids() const
160 {
161  return allBaseRigids;
162 }
163 
164 const std::vector<abstractMarker*>& RPModel::getAllAbstractMarkers() const
165 {
166  return allAbstractMarkers;
167 }
168 
169 void RPModel::teardown()
170 {
171  notifyTeardown();
173 }
virtual void teardown()
Definition: tgModel.cpp:68
Definition of class tgRodInfo.
virtual void step(double dt)
Definition: tgModel.cpp:84
Definition of class tgBasicActuatorInfo.
virtual void onVisit(const tgModelVisitor &r) const
Definition: tgModel.cpp:107
Contains the definition of class tgBasicActuator.
Definition of class tgStructure.
Definition of class tgStructureInfo.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.