NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgRod.cpp
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 
26 // This module
27 #include "tgRod.h"
28 #include "tgModelVisitor.h"
29 // The Bullet Physics library
30 #include "BulletDynamics/Dynamics/btRigidBody.h"
31 #include "btBulletDynamicsCommon.h"
32 // The C++ Standard Library
33 #include <cassert>
34 #include <stdexcept>
35 #include <sstream> //for the tgSenseable methods.
36 #include <iostream> //for strings.
37 
38 tgRod::Config::Config(double r, double d,
39  double f, double rf, double res) :
40  radius(r),
41  density(d),
42  friction(f),
43  rollFriction(rf),
44  restitution(res)
45 {
46  if (density < 0.0) { throw std::range_error("Negative density"); }
47  if (radius < 0.0) { throw std::range_error("Negative radius"); }
48  if (friction < 0.0) { throw std::range_error("Negative friction"); }
49  if (rollFriction < 0.0) { throw std::range_error("Negative roll friction"); }
50  if (restitution < 0.0) { throw std::range_error("Negative restitution"); }
51  if (restitution > 1.0) { throw std::range_error("Restitution > 1"); }
52  // Postcondition
53  assert(density >= 0.0);
54  assert(radius >= 0.0);
55  assert(friction >= 0.0);
56  assert((rollFriction >= 0.0) && (rollFriction <= 1.0));
57  assert((restitution >= 0.0) && (restitution <= 1.0));
58 }
59 
60 tgRod::tgRod(btRigidBody* pRigidBody,
61  const tgTags& tags,
62  const double length) :
63  tgBaseRigid(pRigidBody, tags),
64  m_length(length)
65 {
66  if (pRigidBody == NULL)
67  {
68  throw std::invalid_argument("Pointer to btRigidBody is NULL");
69  }
70 
71  // Postcondition
72  assert(invariant());
73  assert(m_pRigidBody == pRigidBody);
74 }
75 
77 
78 void tgRod::onVisit(const tgModelVisitor& v) const
79 {
80  v.render(*this);
81 
82 }
83 
85 {
86  // Set body to NULL, calls teardown on children
88 
89  // Postcondition
90  // This does not preserve the invariant
91 }
92 
93 bool tgRod::invariant() const
94 {
95  return
96  (m_pRigidBody != NULL) &&
97  (m_mass >= 0.0) &&
98  (m_length >= 0.0);
99 }
Config(double r=0.5, double d=1.0, double f=1.0, double rf=0.0, double res=0.2)
Definition: tgRod.cpp:38
btRigidBody * m_pRigidBody
Definition: tgBaseRigid.h:102
const double rollFriction
Definition: tgRod.h:80
const double density
Definition: tgRod.h:71
const double radius
Definition: tgRod.h:68
virtual void render(const tgRod &rod) const
Contains the definition of interface class tgModelVisitor.
double length() const
Definition: tgRod.h:102
const double m_mass
Definition: tgBaseRigid.h:105
virtual void teardown()
Definition: tgRod.cpp:84
const double friction
Definition: tgRod.h:76
virtual void teardown()
Definition: tgBaseRigid.cpp:65
const double restitution
Definition: tgRod.h:84
Contains the definition of class tgRod.
virtual ~tgRod()
Definition: tgRod.cpp:76
Definition: tgTags.h:44
virtual void onVisit(const tgModelVisitor &v) const
Definition: tgRod.cpp:78