NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgPrismatic.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 
27 #include "tgPrismatic.h"
28 
29 #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h"
30 #include "core/tgBulletUtil.h"
32 
33 // The C++ Standard Library
34 #include <cmath>
35 #include <stdexcept>
36 
42 {
43  throw std::invalid_argument("Failed to provide arguments to tgPrismatic::Config");
44 }
45 
47  double maxLength,
48  double minLength,
49  double maxMotorForce,
50  double maxVelocity
51  ) :
52 m_maxLength(maxLength),
53 m_minLength(minLength),
54 m_maxMotorForce(maxMotorForce),
55 m_maxVelocity(maxVelocity)
56 {
57 }
58 
59 tgPrismatic::tgPrismatic(
60  btSliderConstraint* constraint,
61  const tgTags& tags,
62  tgPrismatic::Config& config) :
63  tgModel(tags),
64  m_slider(constraint),
65  m_config(config)
66 {
67  init();
68 }
69 
70 tgPrismatic::tgPrismatic(
71  btSliderConstraint* constraint,
72  std::string space_separated_tags,
73  tgPrismatic::Config& config) :
74  tgModel(space_separated_tags),
75  m_slider(constraint),
76  m_config(config)
77 {
78  init();
79 }
80 
81 tgPrismatic::~tgPrismatic()
82 {
83  teardown();
84 }
85 
86 void tgPrismatic::init()
87 {
88  m_slider->setLowerLinLimit(m_config.m_minLength);
89  m_slider->setUpperLinLimit(m_config.m_maxLength);
90  m_slider->setPoweredLinMotor(true);
91  m_slider->setMaxLinMotorForce(m_config.m_maxMotorForce);
92 }
93 
95 {
96  assert(m_slider != NULL);
97 
98  //add constraint to world
99  tgWorldBulletPhysicsImpl& bulletWorld =
101  bulletWorld.addConstraint(m_slider);
102 
103  // All the heavy lifting is done by info
104  notifySetup();
105  tgModel::setup(world);
106 }
107 
109 {
110  notifyTeardown();
112 }
113 
114 void tgPrismatic::step(double dt)
115 {
116  if (dt <= 0.0)
117  {
118  throw std::invalid_argument("dt is not positive.");
119  }
120  else
121  {
122  notifyStep(dt);
123  moveMotors(dt);
124  tgModel::step(dt); // Step any children
125  }
126 }
127 
128 void tgPrismatic::moveMotors(double dt)
129 {
130  m_slider->setTargetLinMotorVelocity(m_config.m_maxVelocity/dt);
131 }
virtual void setup(tgWorld &world)
Definition: tgPrismatic.cpp:94
virtual void step(double dt)
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
Contains the definition of class tgPrismatic. A prismatic actuator.
virtual void teardown()
Contains the definition of class tgWorldBulletPhysicsImpl.
virtual void step(double dt)
Definition: tgModel.cpp:84
void addConstraint(btTypedConstraint *pConstaint)
tgWorldImpl & implementation() const
Definition: tgWorld.h:102
Contains the definition of class tgBulletUtil.
void notifyStep(double dt)
Definition: tgTags.h:44