1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 // Authors: Alessandro Tasora 13 // ============================================================================= 14 15 #ifndef CHLINKMOTORROTATION_H 16 #define CHLINKMOTORROTATION_H 17 18 #include "chrono/physics/ChLinkMotor.h" 19 20 namespace chrono { 21 22 /// Base class for all rotational "motor" constraints between 23 /// two frames on two bodies. Motors of this type assume that 24 /// the spindle is directed along Z direction of the master frame. 25 /// Look for children classes for specialized behaviors, 26 /// for example chrono::ChLinkMotorRotationAngle 27 28 class ChApi ChLinkMotorRotation : public ChLinkMotor { 29 public: 30 /// Type of guide constraint 31 enum class SpindleConstraint { FREE, REVOLUTE, CYLINDRICAL, OLDHAM }; 32 33 ChLinkMotorRotation(); 34 ChLinkMotorRotation(const ChLinkMotorRotation& other); 35 virtual ~ChLinkMotorRotation(); 36 37 /// Sets which movements (of frame 1 respect to frame 2) are constrained. 38 /// By default, acts as bearing, like a revolute joint. 39 /// Note that the Z direction is the motorized one, and is never affected by 40 /// this option. 41 void SetSpindleConstraint(const SpindleConstraint mconstraint); 42 43 /// Sets which movements (of frame 1 respect to frame 2) are constrained. 44 /// By default, acts as bearing, like a revolute joint. 45 /// Note that the Z direction is the motorized one, and is never affected by 46 /// this option. 47 void SetSpindleConstraint(bool mc_x, bool mc_y, bool mc_z, bool mc_rx, bool mc_ry); 48 49 /// Get the current actuator rotation [rad], including error etc. 50 /// This rotation keeps track of multiple turns, so it is not limited in periodic -PI..+PI, 51 /// and rotation accumulates indefinitely. Use GetMotorRotTurns() and GetMotorRotPeriodic() otherwise. GetMotorRot()52 virtual double GetMotorRot() const { return mrot; } 53 54 /// In case of multi-turns, gets the current actuator number of (integer) rotations, GetMotorRotTurns()55 virtual int GetMotorRotTurns() const { return int(mrot / CH_C_2PI); } 56 57 /// In case of multi-turns, gets the current actuator rotation angle [rad], in periodic -PI..+PI. GetMotorRotPeriodic()58 virtual double GetMotorRotPeriodic() const { return fmod(mrot, CH_C_2PI); } 59 60 /// Get the current actuator speed [rad/s], including error etc. GetMotorRot_dt()61 virtual double GetMotorRot_dt() const { return mrot_dt; } 62 63 /// Get the current actuator acceleration [rad/s^2], including error etc. GetMotorRot_dtdt()64 virtual double GetMotorRot_dtdt() const { return mrot_dtdt; } 65 66 /// Get the current actuator reaction torque [Nm] 67 virtual double GetMotorTorque() const = 0; 68 69 void Update(double mytime, bool update_assets) override; 70 71 /// Method to allow serialization of transient data to archives. 72 virtual void ArchiveOUT(ChArchiveOut& marchive) override; 73 74 /// Method to allow deserialization of transient data from archives. 75 virtual void ArchiveIN(ChArchiveIn& marchive) override; 76 77 protected: 78 // aux data for optimization 79 double mrot; 80 double mrot_dt; 81 double mrot_dtdt; 82 }; 83 84 CH_CLASS_VERSION(ChLinkMotorRotation, 0) 85 86 } // end namespace chrono 87 88 #endif 89