1 #ifndef OPENSIM_CONSTRAINT_H_ 2 #define OPENSIM_CONSTRAINT_H_ 3 /* -------------------------------------------------------------------------- * 4 * OpenSim: Constraint.h * 5 * -------------------------------------------------------------------------- * 6 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * 7 * See http://opensim.stanford.edu and the NOTICE file for more information. * 8 * OpenSim is developed at Stanford University and supported by the US * 9 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * 10 * through the Warrior Web program. * 11 * * 12 * Copyright (c) 2005-2017 Stanford University and the Authors * 13 * Author(s): Frank C. Anderson, Ajay Seth * 14 * * 15 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 16 * not use this file except in compliance with the License. You may obtain a * 17 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 18 * * 19 * Unless required by applicable law or agreed to in writing, software * 20 * distributed under the License is distributed on an "AS IS" BASIS, * 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 * See the License for the specific language governing permissions and * 23 * limitations under the License. * 24 * -------------------------------------------------------------------------- */ 25 26 // INCLUDE 27 #include <OpenSim/Simulation/Model/ModelComponent.h> 28 29 namespace OpenSim { 30 31 class ScaleSet; 32 33 //============================================================================= 34 //============================================================================= 35 /** 36 * A parent class for implementing a Simbody Constraint. 37 * Specific constraints should be derived from this class. 38 * 39 * @author Frank C. Anderson 40 * @author Ajay Seth 41 * @version 1.0 42 */ 43 class OSIMSIMULATION_API Constraint : public ModelComponent { 44 OpenSim_DECLARE_ABSTRACT_OBJECT(Constraint, ModelComponent); 45 46 //============================================================================= 47 // PROPERTY 48 //============================================================================= 49 public: 50 /* Note: 'isEnforced' replaced 'isDisabled' as of OpenSim 4.0 */ 51 OpenSim_DECLARE_PROPERTY(isEnforced, bool, 52 "Flag indicating whether the constraint is enforced or not." 53 "Enforced means that the constraint is active in subsequent " 54 "dynamics realizations. NOTE: Prior to OpenSim 4.0, this behavior " 55 "was controlled by the 'isDisabled' property, where 'true' meant " 56 "the constraint was not being enforced. Thus, if 'isDisabled' is" 57 "'true', then 'isEnforced' is false." ); 58 59 //============================================================================= 60 // METHODS 61 //============================================================================= 62 //-------------------------------------------------------------------------- 63 // CONSTRUCTION 64 //------------------------------------------------------------------------- 65 Constraint(); 66 virtual ~Constraint(); 67 68 virtual void updateFromConstraint(SimTK::State& s, 69 const Constraint &aConstraint); 70 71 /** 72 * Determine whether or not this Constraint is being enforced. */ 73 virtual bool isEnforced(const SimTK::State& s) const; 74 75 /** 76 * Set whether or not this Constraint is enforced. 77 * The realization Stage is dropped to Instance whenever the 'isEnforced' 78 * flag is changed, but setting the same value has no effect. */ 79 virtual bool setIsEnforced(SimTK::State& s, bool isEnforced); 80 81 virtual void 82 calcConstraintForces(const SimTK::State& s, 83 SimTK::Vector_<SimTK::SpatialVec>& bodyForcesInAncestor, 84 SimTK::Vector& mobilityForces) const; 85 86 /** 87 * Methods to query the Constraint forces (defaults to the Lagrange 88 * multipliers) applied to the MultibodySystem. The names of the quantities 89 * (column labels) are returned by this first method, getRecordLabels() */ 90 virtual Array<std::string> getRecordLabels() const; 91 /** 92 * Given a SimTK::State, extract all the values necessary to report 93 * constraint forces (e.g. multipliers). Subclasses can override to report 94 * the location, frame, etc.. of force application. This method is used in 95 * conjunction with getRecordLabels() and must return an Array of equal 96 * size. */ 97 virtual Array<double> getRecordValues(const SimTK::State& state) const; 98 99 /** 100 * This method specifies the interface that a constraint must implement 101 * in order to be used by the Induced Accelerations Analysis 102 */ setContactPointForInducedAccelerations(const SimTK::State & s,SimTK::Vec3 point)103 virtual void setContactPointForInducedAccelerations(const SimTK::State &s, 104 SimTK::Vec3 point){ 105 throw Exception("This constraint does not implement " 106 "setContactPointForInducedAccelerations"); 107 } 108 109 protected: 110 // ModelComponent interface. 111 void extendConnectToModel(Model& aModel) override; 112 void extendInitStateFromProperties(SimTK::State& state) const override; 113 void extendSetPropertiesFromState(const SimTK::State& state) override; 114 115 /** Helper method to assign the underlying SimTK::Constraint index */ assignConstraintIndex(SimTK::ConstraintIndex ix)116 void assignConstraintIndex(SimTK::ConstraintIndex ix) const { 117 const_cast<Self*>(this)->_index = ix; 118 } 119 120 void updateFromXMLNode(SimTK::Xml::Element& node, 121 int versionNumber) override; 122 123 private: 124 void setNull(); 125 void constructProperties(); 126 127 /** ID for the constraint in Simbody. */ 128 SimTK::ResetOnCopy<SimTK::ConstraintIndex> _index; 129 130 friend class SimbodyEngine; 131 132 //============================================================================= 133 }; // END of class Constraint 134 //============================================================================= 135 //============================================================================= 136 137 } // end of namespace OpenSim 138 139 #endif // OPENSIM_CONSTRAINT_H_ 140 141 142