1 #ifndef OPENSIM_PATH_ACTUATOR_H_
2 #define OPENSIM_PATH_ACTUATOR_H_
3 /* -------------------------------------------------------------------------- *
4  *                          OpenSim:  PathActuator.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): 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 "Actuator.h"
27 #include "GeometryPath.h"
28 
29 //=============================================================================
30 //=============================================================================
31 
32 namespace OpenSim {
33 
34 class Coordinate;
35 class ForceSet;
36 class Model;
37 
38 /**
39  * This is the base class for actuators that apply controllable tension along
40  * a geometry path. %PathActuator has no states; the control is simply the
41  * tension to be applied along a geometry path (i.e. tensionable rope).
42  *
43  * @author Ajay Seth
44  */
45 class OSIMSIMULATION_API PathActuator : public ScalarActuator {
46     OpenSim_DECLARE_CONCRETE_OBJECT(PathActuator, ScalarActuator);
47 public:
48 //=============================================================================
49 // PROPERTIES
50 //=============================================================================
51     OpenSim_DECLARE_UNNAMED_PROPERTY(GeometryPath,
52         "The set of points defining the path of the actuator.");
53     OpenSim_DECLARE_PROPERTY(optimal_force, double,
54         "The maximum force this actuator can produce.");
55 
56     OpenSim_DECLARE_OUTPUT(tension, double, computeActuation,
57                            SimTK::Stage::Acceleration);
58 
59 //=============================================================================
60 // PUBLIC METHODS
61 //=============================================================================
62     PathActuator();
63 
64     // default destructor, copy constructor, copy assignment
65 
66     //--------------------------------------------------------------------------
67     // GET AND SET
68     //--------------------------------------------------------------------------
69     // Path
updGeometryPath()70     GeometryPath& updGeometryPath() { return upd_GeometryPath(); }
getGeometryPath()71     const GeometryPath& getGeometryPath() const
72     {   return get_GeometryPath(); }
hasGeometryPath()73     bool hasGeometryPath() const override { return true;};
74 
75     // OPTIMAL FORCE
76     void setOptimalForce(double aOptimalForce);
77     double getOptimalForce() const override;
78 
79     // Length and Speed of actuator
80     virtual double getLength(const SimTK::State& s) const;
81     virtual double getLengtheningSpeed(const SimTK::State& s) const;
82 
83     // Power: Since lengthening is positive and tension always shortens, positive power
84     // is when muscle is shortening under tension.
getPower(const SimTK::State & s)85     double getPower(const SimTK::State& s) const override
86     {   return -getActuation(s)*getSpeed(s); }
87 
88 
89     // STRESS
90     double getStress( const SimTK::State& s ) const override;
91 
92     // Convenience method to add PathPoints
93      /** Note that this function does not maintain the State and so should be used only
94         before a valid State is created */
95     void addNewPathPoint(const std::string& proposedName,
96                          const PhysicalFrame& aBody,
97                          const SimTK::Vec3& aPositionOnBody);
98 
99     //--------------------------------------------------------------------------
100     // APPLICATION
101     //--------------------------------------------------------------------------
102     virtual void computeForce( const SimTK::State& state,
103                                SimTK::Vector_<SimTK::SpatialVec>& bodyForces,
104                                SimTK::Vector& mobilityForces) const override;
105 
106     //--------------------------------------------------------------------------
107     // COMPUTATIONS
108     //--------------------------------------------------------------------------
109     double computeActuation( const SimTK::State& s) const override;
110     virtual double computeMomentArm( const SimTK::State& s, Coordinate& aCoord) const;
111 
112 protected:
113     /** Override this method if you would like to calculate a color for use when
114     the %PathActuator's path is displayed in the visualizer. You do not have
115     to invoke the base class ("Super") method, just replace it completely. This
116     method will be invoked during realizeDynamics() so the supplied \a state has
117     already been realized through Stage::Velocity and you can access time,
118     position, and velocity dependent quantities. You must \e not attempt to
119     realize the passed-in \a state any further since we are already in the
120     middle of realizing here. Return SimTK::Vec3(SimTK::NaN) if you want to
121     leave the color unchanged (that's what the base class implementation does).
122 
123     @param[in] state
124         A SimTK::State already realized through Stage::Velocity. Do not
125         attempt to realize it any further.
126     @returns
127         The desired color for the path as an RGB vector with each
128         component ranging from 0 to 1, or NaN to indicate that the color
129         should not be changed. **/
130     virtual SimTK::Vec3 computePathColor(const SimTK::State& state) const;
131 
132     /** Extension of parent class method; derived classes may extend further. **/
133     void extendRealizeDynamics(const SimTK::State& state) const override;
134 
135 private:
136     void setNull();
137     void constructProperties();
138 
139 //=============================================================================
140 };  // END of class PathActuator
141 
142 }; //namespace
143 //=============================================================================
144 //=============================================================================
145 
146 #endif // OPENSIM_PATH_ACTUATOR_H_
147 
148 
149