Program Listing for File SubhingeForceLimits.cc#
↰ Return to documentation for file (doxygen_docs/GeneralKModels/SubhingeForceLimits.cc)
#include"Karana/GeneralKModels/SubhingeForceLimits.h"
#include"Karana/KCore/Allocator.h"
namespaceKarana::Models{
namespacekd=Karana::Dynamics;
SubhingeForceLimits::SubhingeForceLimits(std::string_viewname,
constkc::ks_ptr<kd::StatePropagator>&sp,
constkc::ks_ptr<kd::PhysicalSubhinge>&sh)
:KModel<SubhingeForceLimits,SubhingeForceLimitsParams>(name,sp)
,_sh(sh){
params=std::allocate_shared<SubhingeForceLimitsParams>(
kc::Allocator<SubhingeForceLimitsParams>{},std::format("{}_params",name));
};
kc::ks_ptr<SubhingeForceLimits>
SubhingeForceLimits::create(std::string_viewname,
constkc::ks_ptr<kd::StatePropagator>&sp,
constkc::ks_ptr<kd::PhysicalSubhinge>&sh){
kc::ks_ptr<SubhingeForceLimits>sfl=std::allocate_shared<SubhingeForceLimits>(
kc::Allocator<SubhingeForceLimits>{},name,sp,sh);
sp->registerModel(sfl);
returnsfl;
}
voidSubhingeForceLimits::preDeriv(constkm::Ktime&,constkm::Vec&){
km::VecT=_sh->getT();
for(Eigen::Indexk=0;k<T.size();k++){
T[k]=std::clamp(T[k],params->lower_limits[k],params->upper_limits[k]);
}
_sh->setT(T);
}
SubhingeForceLimitsParams::SubhingeForceLimitsParams(std::string_viewname)
:KModelParams(name){
lower_limits.resize(1);
km::uninitialize(lower_limits);
upper_limits.resize(1);
km::uninitialize(upper_limits);
}
boolSubhingeForceLimitsParams::isFinalized()const{
boolflag=true;
if(notkm::isInitialized(lower_limits)){
kc::warn("Parameterlower_limitsisuninitialized.");
flag=false;
}
if(notkm::isInitialized(upper_limits)){
kc::warn("Parameterupper_limitsisuninitialized.");
flag=false;
}
if(lower_limits.size()!=upper_limits.size()){
kc::warn("Thesizesofupper_limitsandlower_limitsdon'tmatch.");
flag=false;
}
returnflag;
}
boolSubhingeForceLimits::isFinalized()const{
boolflag=true;
if(_sh->nQ()!=size_t(params->lower_limits.size())){
kc::warn("Thesubhingesize{}isnotequaltothesizeofthelimits{}.",
_sh->nQ(),
params->lower_limits.size());
flag=false;
}
returnflag;
};
//DestructorincludedforMacOSbuilds.Musthaveakey-functionout-of-linetoavoiddulpicate
//symbols.
SubhingeForceLimits::~SubhingeForceLimits(){};
}//namespaceKarana::Models