Home > Resources > MBDyn Examples > 16. Toy Car Downhill
MBDyn Examples

16. Toy Car Downhill

Animations





Input File

rolling_car_2d.mbd
# rolling_car_2d.mbd

#-----------------------------------------------------------------------------
# [Data Block]

begin: data;
   problem: initial value;
end: data;

#-----------------------------------------------------------------------------
# [ Block]

begin: initial value;
   initial time:   0.;
   final time:     2.;
   time step:      1.e-4;
   max iterations: 10;
   tolerance:      1.e-7;
end: initial value;

#-----------------------------------------------------------------------------
# [Control Data Block]

begin: control data;
   skip initial joint assembly;
   output frequency: 50;
   structural nodes: 8;
   rigid bodies:     3;
   joints:           11;
   forces:           2;
   gravity;
end: control data;

#-----------------------------------------------------------------------------
# Design Variables
set: real L = 0.1;  # [m]    Wheel Base
set: real M = 0.1;  # [kg]   Mass
set: real D = 0.05; # [m]    Chassis Height
set: real K = 100.; # [N/m]  Spring Rate
set: real C = 1;    # [Ns/m] Shock Absorber

set: real Kc = 5000.; # [N/m]  Contact Stiffness
set: real Ec = 1.2;   # [-]    Contact Stiffness Exponent
set: real Cc = 0.1;   # [Ns/m] Contact Damping
set: real Dc = 0.0001;# [m]    Contact Damping Activation Depth

set: real Delta_Road = 0.0001; #[m] 

#-----------------------------------------------------------------------------
# Intermediate Variables
set: real I = M*L^2./12.; # Moment of Inertia of Chassis

#-----------------------------------------------------------------------------
# Reference Labels
set: integer Ref_RearWheel = 1;

# Node Labels
set: integer NoSta_Ground     = 1;
set: integer NoDyn_Chassis    = 2;
set: integer NoDyn_FrontWheel = 3;
set: integer NoDyn_RearWheel  = 4;
set: integer NoDyn_Road1      = 5;
set: integer NoDyn_Road2      = 6;

set: integer NoDum_FrontWheel = 7;
set: integer NoDum_RearWheel  = 8;

# Body Labels
set: integer Body_Chassis    = 1;
set: integer Body_FrontWheel = 2;
set: integer Body_RearWheel  = 3;

# Joint Labels
set: integer JoClamp_Ground             = 1;
set: integer JoInp_Ground_Chassis       = 2;
set: integer JoRevrot_Ground_Chassis    = 3;
set: integer JoInlin_Chassis_FrontWheel = 4;
set: integer JoPrism_Chassis_FrontWheel = 5;
set: integer JoDfmd_Chassis_FrontWheel  = 6;
set: integer JoInlin_Chassis_RearWheel  = 7;
set: integer JoPrism_Chassis_RearWheel  = 8;
set: integer JoDfmd_Chassis_RearWheel   = 9;
set: integer JoTotp_Road1               = 10;
set: integer JoTotp_Road2               = 11;

# Force Labels
set: integer FoStrin_Normal_FrontWheel_Road1 = 1;
set: integer FoStrin_Normal_RearWheel_Road2  = 2;

#-----------------------------------------------------------------------------
# Scalar Functions
include: "sf_cubstep.sub";
include: "sf_Fun_Road.sub";
   
#-----------------------------------------------------------------------------
# Intermediate Variables
set: real Road1_Height_Ini = model::sf::Fun_Road(L);
set: real Road2_Height_Ini = model::sf::Fun_Road(0.);
set: real Road1_Angle_Ini  = atan((model::sf::Fun_Road(L+Delta_Road)-model::sf::Fun_Road(L))/Delta_Road);
set: real Road2_Angle_Ini  = atan((model::sf::Fun_Road(Delta_Road)-model::sf::Fun_Road(0.))/Delta_Road);

#-----------------------------------------------------------------------------
# References
reference: Ref_RearWheel,
   0., 0., Road2_Height_Ini, # absolute position
   eye,                      # absolute orientation
   null,                     # absolute velocity
   null;                     # absolute angular velocity
      
#-----------------------------------------------------------------------------
# [Nodes Block]

begin: nodes;

   #-----------------------------------------------------------------------------
   # Nodes
   structural: NoSta_Ground, static,
      null, # absolute position
      eye,  # absolute orientation
      null, # absolute velocity
      null; # absolute angular velocity
      
   structural: NoDyn_Chassis, dynamic,
      reference, Ref_RearWheel, L/2., 0., D,          # absolute position
      reference, Ref_RearWheel, euler, pi/2., 0., 0., # absolute orientation
      reference, Ref_RearWheel, null,                 # absolute velocity
      reference, Ref_RearWheel, null;                 # absolute angular velocity
      
   structural: NoDyn_FrontWheel, dynamic,
      reference, Ref_RearWheel, L, 0., 0., # absolute position
      reference, Ref_RearWheel, eye,       # absolute orientation
      reference, Ref_RearWheel, null,      # absolute velocity
      reference, Ref_RearWheel, null;      # absolute angular velocity
      
   structural: NoDyn_RearWheel, dynamic,
      reference, Ref_RearWheel, null, # absolute position
      reference, Ref_RearWheel, eye,  # absolute orientation
      reference, Ref_RearWheel, null, # absolute velocity
      reference, Ref_RearWheel, null; # absolute angular velocity
      
   structural: NoDyn_Road1, dynamic,
      L, 0., Road1_Height_Ini,         # absolute position
      euler, 0., -Road1_Angle_Ini, 0., # absolute orientation
      null,                            # absolute velocity
      null;                            # absolute angular velocity
      
   structural: NoDyn_Road2, dynamic,
      0., 0., Road2_Height_Ini,        # absolute position
      euler, 0., -Road2_Angle_Ini, 0., # absolute orientation
      null,                            # absolute velocity
      null;                            # absolute angular velocity
      
   structural: NoDum_FrontWheel, dummy, NoDyn_FrontWheel,
      relative frame, NoDyn_Road1;
      
   structural: NoDum_RearWheel, dummy, NoDyn_RearWheel,
      relative frame, NoDyn_Road2;
   
end: nodes;
   
#-----------------------------------------------------------------------------
# Plugin Variables
set: [node, DX1, NoDyn_FrontWheel, structural, string="X[1]"];
set: [node, DX2, NoDyn_RearWheel, structural, string="X[1]"];

set: [node, DZ1_Dum, NoDum_FrontWheel, structural, string="X[3]"];
set: [node, DZ2_Dum, NoDum_RearWheel, structural, string="X[3]"];

set: [node, VZ1_Dum, NoDum_FrontWheel, structural, string="XP[3]"];
set: [node, VZ2_Dum, NoDum_RearWheel, structural, string="XP[3]"];

#-----------------------------------------------------------------------------
# [Elements Block]

begin: elements;

   #-----------------------------------------------------------------------------
   # Bodies

   body: Body_Chassis, NoDyn_Chassis,
      M,               # mass
      null,            # relative center of mass
      diag, 1., 1., I; # inertia matrix
      
   body: Body_FrontWheel, NoDyn_FrontWheel,
      1.e-6,                     # mass
      null,                      # relative center of mass
      diag, 1.e-9, 1.e-9, 1.e-9; # inertia matrix
    
   body: Body_RearWheel, NoDyn_RearWheel,
      1.e-6,                     # mass
      null,                      # relative center of mass
      diag, 1.e-9, 1.e-9, 1.e-9; # inertia matrix
      
   #-----------------------------------------------------------------------------
   # Joints 
   joint: JoClamp_Ground,
      clamp,
         NoSta_Ground,
            position, node,
            orientation, node;

   joint: JoInp_Ground_Chassis,
      in plane,
         NoSta_Ground,
            null,       # relative plane position
            0., 1., 0., # relative normal direction
         NoDyn_Chassis;

   joint: JoRevrot_Ground_Chassis,
      revolute rotation,
         NoSta_Ground,
            hinge,
               euler, pi/2., 0, 0., # relative orientation matrix
         NoDyn_Chassis;
         
   joint: JoInlin_Chassis_FrontWheel, 
      in line,
         NoDyn_Chassis,
            reference, Ref_RearWheel, L, 0., D, # relative line position
            reference, Ref_RearWheel, eye,      # relative line orientation
         NoDyn_FrontWheel;

   joint: JoPrism_Chassis_FrontWheel,
      prismatic,
         NoDyn_Chassis,
            hinge, reference, global, eye, # relative orientation matrix
         NoDyn_FrontWheel;
         
   joint: JoDfmd_Chassis_FrontWheel,
      deformable displacement joint,
         NoDyn_Chassis,
            reference, Ref_RearWheel, L, 0., D,   # relative offset
            hinge, reference, Ref_RearWheel, eye, # relative orientation matrix
         NoDyn_FrontWheel, 
            null,                               # relative offset
         linear viscoelastic isotropic,
            K,    # stiffness
            C,    # viscosity coefficient
         prestrain, single, 0., 0., -1, const, D;
         
   joint: JoInlin_Chassis_RearWheel, 
      in line,
         NoDyn_Chassis,
            reference, Ref_RearWheel, 0., 0., D, # relative line position
            reference, Ref_RearWheel, eye,       # relative line orientation
         NoDyn_RearWheel;

   joint: JoPrism_Chassis_RearWheel,
      prismatic,
         NoDyn_Chassis,
            hinge, reference, global, eye, # relative orientation matrix
         NoDyn_RearWheel;
         
   joint: JoDfmd_Chassis_RearWheel,
      deformable displacement joint,
         NoDyn_Chassis,
            reference, Ref_RearWheel, 0., 0., D,  # relative offset
            hinge, reference, Ref_RearWheel, eye, # relative orientation matrix
         NoDyn_RearWheel, 
            null,                                # relative offset
         linear viscoelastic isotropic,
            K,    # stiffness
            C,    # viscosity coefficient
         prestrain, single, 0., 0., -1, const, D;

   joint: JoTotp_Road1,
      total pin joint,
         NoDyn_Road1,
            position, null, # relative offset
            position, null, # absolute position
         position constraint,
            active, active, active,
            component,
               string, "DX1",
               null,
               string, "model::sf::Fun_Road(DX1)",
         orientation constraint,
            active, active, active,
            single, 0., 1., 0,
               string, "-atan((model::sf::Fun_Road(DX1+Delta_Road)\
                                 -model::sf::Fun_Road(DX1))/Delta_Road)";
               
   joint: JoTotp_Road2,
      total pin joint,
         NoDyn_Road2,
            position, null, # relative offset
            position, null, # absolute position
         position constraint,
            active, active, active,
            component,
               string, "DX2",
               const, 0.,
               string, "model::sf::Fun_Road(DX2)",
         orientation constraint,
            active, active, active,
            single, 0., 1., 0,
               string, "-atan((model::sf::Fun_Road(DX2+Delta_Road)\
                                -model::sf::Fun_Road(DX2))/Delta_Road)";
         
   #-----------------------------------------------------------------------------
   # Forces      
   force: FoStrin_Normal_FrontWheel_Road1,
      follower internal,
         NoDyn_Road1,
            position, null, # relative arm
         NoDyn_FrontWheel,
            position, null, # relative arm
         single, 0., 0., -1.,
            string, "max(0,Kc*sign(0-DZ1_Dum)*abs(0-DZ1_Dum)^Ec\
                           -Cc*VZ1_Dum*model::sf::cubstep((0-DZ1_Dum)/Dc))"; # force value
                           
   force: FoStrin_Normal_RearWheel_Road2,
      follower internal,
         NoDyn_Road2,
            position, null, # relative arm
         NoDyn_RearWheel,
            position, null, # relative arm
         single, 0., 0., -1.,
            string, "max(0,Kc*sign(0-DZ2_Dum)*abs(0-DZ2_Dum)^Ec\
                           -Cc*VZ2_Dum*model::sf::cubstep((0-DZ2_Dum)/Dc))"; # force value
                                
   #-----------------------------------------------------------------------------
   # Gravity 
   gravity: 0., 0., -1., const, 9.81;

end: elements;

Subfiles

sf_cubstep.sub
# sf_cubstep.sub

scalar function: "cubstep",
   cubicspline, do not extrapolate,
      -0.03, 0.00,
      -0.02, 0.00,
      -0.01, 0.00,
       0.00, 0.00,
       1.00, 1.00,
       1.01, 1.00,
       1.02, 1.00,
       1.03, 1.00;

sf_Fun_Road.sub
# sf_Fun_Road.sub

scalar function: "Fun_Road",
   cubicspline, do not extrapolate,
      0.000000, 0.050000, 
      0.010000, 0.049726, 
      0.020000, 0.048907, 
      0.030000, 0.047553, 
      0.040000, 0.045677, 
      0.050000, 0.043301, 
      0.060000, 0.040451, 
      0.070000, 0.037157, 
      0.080000, 0.033457, 
      0.090000, 0.029389, 
      0.100000, 0.025000, 
      0.110000, 0.020337, 
      0.120000, 0.015451, 
      0.130000, 0.010396, 
      0.140000, 0.005226, 
      0.150000, -0.000000, 
      0.160000, -0.005226, 
      0.170000, -0.010396, 
      0.180000, -0.015451, 
      0.190000, -0.020337, 
      0.200000, -0.025000, 
      0.210000, -0.029389, 
      0.220000, -0.033457, 
      0.230000, -0.037157, 
      0.240000, -0.040451, 
      0.250000, -0.043301, 
      0.260000, -0.045677, 
      0.270000, -0.047553, 
      0.280000, -0.048907, 
      0.290000, -0.049726, 
      0.300000, -0.050000, 
      0.310000, -0.050274, 
      0.320000, -0.051093, 
      0.330000, -0.052447, 
      0.340000, -0.054323, 
      0.350000, -0.056699, 
      0.360000, -0.059549, 
      0.370000, -0.062843, 
      0.380000, -0.066543, 
      0.390000, -0.070611, 
      0.400000, -0.075000, 
      0.410000, -0.079663, 
      0.420000, -0.084549, 
      0.430000, -0.089604, 
      0.440000, -0.094774, 
      0.450000, -0.100000, 
      0.460000, -0.105226, 
      0.470000, -0.110396, 
      0.480000, -0.115451, 
      0.490000, -0.120337, 
      0.500000, -0.125000, 
      0.510000, -0.129389, 
      0.520000, -0.133457, 
      0.530000, -0.137157, 
      0.540000, -0.140451, 
      0.550000, -0.143301, 
      0.560000, -0.145677, 
      0.570000, -0.147553, 
      0.580000, -0.148907, 
      0.590000, -0.149726, 
      0.600000, -0.150000, 
      0.610000, -0.149726, 
      0.620000, -0.148907, 
      0.630000, -0.147553, 
      0.640000, -0.145677, 
      0.650000, -0.143301, 
      0.660000, -0.140451, 
      0.670000, -0.137157, 
      0.680000, -0.133457, 
      0.690000, -0.129389, 
      0.700000, -0.125000, 
      0.710000, -0.120337, 
      0.720000, -0.115451, 
      0.730000, -0.110396, 
      0.740000, -0.105226, 
      0.750000, -0.100000, 
      0.760000, -0.094774, 
      0.770000, -0.089604, 
      0.780000, -0.084549, 
      0.790000, -0.079663, 
      0.800000, -0.075000, 
      0.810000, -0.070611, 
      0.820000, -0.066543, 
      0.830000, -0.062843, 
      0.840000, -0.059549, 
      0.850000, -0.056699, 
      0.860000, -0.054323, 
      0.870000, -0.052447, 
      0.880000, -0.051093, 
      0.890000, -0.050274, 
      0.900000, -0.050000, 
      0.910000, -0.050274, 
      0.920000, -0.051093, 
      0.930000, -0.052447, 
      0.940000, -0.054323, 
      0.950000, -0.056699, 
      0.960000, -0.059549, 
      0.970000, -0.062843, 
      0.980000, -0.066543, 
      0.990000, -0.070611, 
      1.000000, -0.075000, 
      1.010000, -0.079663, 
      1.020000, -0.084549, 
      1.030000, -0.089604, 
      1.040000, -0.094774, 
      1.050000, -0.100000, 
      1.060000, -0.105226, 
      1.070000, -0.110396, 
      1.080000, -0.115451, 
      1.090000, -0.120337, 
      1.100000, -0.125000, 
      1.110000, -0.129389, 
      1.120000, -0.133457, 
      1.130000, -0.137157, 
      1.140000, -0.140451, 
      1.150000, -0.143301, 
      1.160000, -0.145677, 
      1.170000, -0.147553, 
      1.180000, -0.148907, 
      1.190000, -0.149726, 
      1.200000, -0.150000, 
      1.210000, -0.149726, 
      1.220000, -0.148907, 
      1.230000, -0.147553, 
      1.240000, -0.145677, 
      1.250000, -0.143301, 
      1.260000, -0.140451, 
      1.270000, -0.137157, 
      1.280000, -0.133457, 
      1.290000, -0.129389, 
      1.300000, -0.125000, 
      1.310000, -0.120337, 
      1.320000, -0.115451, 
      1.330000, -0.110396, 
      1.340000, -0.105226, 
      1.350000, -0.100000, 
      1.360000, -0.094774, 
      1.370000, -0.089604, 
      1.380000, -0.084549, 
      1.390000, -0.079663, 
      1.400000, -0.075000, 
      1.410000, -0.070611, 
      1.420000, -0.066543, 
      1.430000, -0.062843, 
      1.440000, -0.059549, 
      1.450000, -0.056699, 
      1.460000, -0.054323, 
      1.470000, -0.052447, 
      1.480000, -0.051093, 
      1.490000, -0.050274, 
      1.500000, -0.050000;
Sponsor Link