|
| 1 | +classdef IntegratorDynRel < mystica.intgr.Integrator |
| 2 | + %INTEGRATOR Summary of this class goes here |
| 3 | + % Detailed explanation goes here |
| 4 | + |
| 5 | + properties (SetAccess=protected,GetAccess=public) |
| 6 | + motorsCurrent %input |
| 7 | + mBodyPosVel_0 %x |
| 8 | + mBodyVelAcc_0 %dxdt = f(input,x) |
| 9 | + end |
| 10 | + properties (SetAccess=immutable,GetAccess=public) |
| 11 | + dt |
| 12 | + end |
| 13 | + |
| 14 | + methods |
| 15 | + function obj = IntegratorDynRel(input) |
| 16 | + arguments |
| 17 | + input.stgsIntegrator struct; |
| 18 | + input.dt |
| 19 | + end |
| 20 | + obj@mystica.intgr.Integrator(... |
| 21 | + 'dxdt' ,[],... |
| 22 | + 'xi' ,[],... |
| 23 | + 'ti' ,-input.dt,... |
| 24 | + 'tf' ,0,... |
| 25 | + 'stgsIntegrator',input.stgsIntegrator); |
| 26 | + obj.dt = input.dt; |
| 27 | + end |
| 28 | + |
| 29 | + function xf = integrate(obj,input) |
| 30 | + arguments |
| 31 | + obj |
| 32 | + input.motorsCurrent |
| 33 | + input.stateDynMBody |
| 34 | + input.model |
| 35 | + end |
| 36 | + |
| 37 | + obj.ti = obj.ti + obj.dt; |
| 38 | + obj.tf = obj.tf + obj.dt; |
| 39 | + |
| 40 | + obj.motorsCurrent = input.motorsCurrent; |
| 41 | + obj.mBodyPosVel_0 = input.stateDynMBody.mBodyPosVel_0; |
| 42 | + |
| 43 | + switch obj.solverOpts.name |
| 44 | + case {'rk','cvodes'} |
| 45 | + x = casadi.MX.sym('x',input.model.constants.mBodyPosVel,1); |
| 46 | + if obj.dxdtOpts.assumeConstant |
| 47 | + dxdt = casadi.Function('dxdt',{x},{input.stateDynMBody.csdFn.mBodyVelAcc_0(obj.mBodyPosVel_0,obj.motorsCurrent)}); |
| 48 | + else |
| 49 | + dxdt = casadi.Function('dxdt',{x},{input.stateDynMBody.csdFn.mBodyVelAcc_0(x,obj.motorsCurrent)}); |
| 50 | + end |
| 51 | + case {'ode45','ode23','ode113','ode78','ode89','ode15s','ode23s','ode23t','ode23tb','ode15i',... %https://it.mathworks.com/help/matlab/math/choose-an-ode-solver.html |
| 52 | + 'mystica.intgr.ode1','mystica.intgr.ode2','mystica.intgr.ode4'} |
| 53 | + if obj.dxdtOpts.assumeConstant |
| 54 | + obj.mBodyVelAcc_0 = input.stateDynMBody.get_mBodyVelAcc0_from_motorsCurrent(... |
| 55 | + 'motorsCurrent',obj.motorsCurrent,... |
| 56 | + 'kBaum',obj.dxdtParam.baumgarteIntegralCoefficient,... |
| 57 | + 'model',input.model,... |
| 58 | + 'kFeedbackJcV',obj.dxdtParam.feedbackJacobianConstraintsV,... |
| 59 | + 'solverTechnique',obj.dxdtOpts.solverTechnique); |
| 60 | + dxdt = @(t,x) obj.mBodyVelAcc_0; |
| 61 | + else |
| 62 | + dxdt = @(t,x) input.stateDynMBody.get_mBodyVelAcc0_from_motorsCurrent(... |
| 63 | + 'motorsCurrent',obj.motorsCurrent,... |
| 64 | + 'kBaum',obj.dxdtParam.baumgarteIntegralCoefficient,... |
| 65 | + 'model',input.model,... |
| 66 | + 'kFeedbackJcV',obj.dxdtParam.feedbackJacobianConstraintsV,... |
| 67 | + 'mBodyPosVel_0_warningOnlyIfNecessary',x,... |
| 68 | + 'solverTechnique',obj.dxdtOpts.solverTechnique,... |
| 69 | + 't',t); |
| 70 | + end |
| 71 | + otherwise |
| 72 | + error('not valid solver') |
| 73 | + end |
| 74 | + xf = obj.integrate@mystica.intgr.Integrator('dxdt',dxdt,'xi',obj.mBodyPosVel_0,'ti',obj.ti,'tf',obj.tf); |
| 75 | + |
| 76 | + if obj.dxdtOpts.assumeConstant == 0 |
| 77 | + % because the stateDynMBody (handle class) is updated inside the method get_mBodyVelAcc0_from_motorsCurrent |
| 78 | + input.stateDynMBody.setMBodyPosVel( 'model',input.model,'mBodyPosVel_0' ,obj.mBodyPosVel_0) |
| 79 | + end |
| 80 | + |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | +end |
0 commit comments