Free Electron
GroundCollisionSystem.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __tire_GroundCollisionSystem_h__
8 #define __tire_GroundCollisionSystem_h__
9 
10 #include "solve/solve.h"
11 
12 namespace fe
13 {
14 namespace ext
15 {
16 
17 /// MOA Toy/Test Ground Collision System -- M*N: Ground and Tires
19  virtual public Stepper,
20  public Initialize<GroundCollisionSystem>
21 {
22  public:
24  {
25  }
26  void initialize(void) {}
27 virtual void compile(const t_note_id &a_note_id)
28  {
29  rg_all = m_rg_dataset;
30  m_asGround.bind(rg_all->scope());
31  m_asTireLive.bind(rg_all->scope());
32  m_asGround.filter(m_grounds, rg_all);
33  m_asTireLive.filter(m_tires, rg_all);
34  }
35  void step(t_moa_real a_dt)
36  {
37  if(!rg_all->scope().isValid()) { return; }
38 
39  for(unsigned int i_ground = 0;i_ground< m_grounds.size();i_ground++)
40  {
41  Record &r_ground = m_grounds[i_ground];
42 
43  for(unsigned int i_tire = 0; i_tire < m_tires.size(); i_tire++)
44  {
45  Record &r_tire = m_tires[i_tire];
46 
47  if(determinant(m_asTireLive.transform(r_tire)) == 0.0)
48  {
49  continue;
50  }
51  SpatialTransform inv_tire_transform;
52  invert(inv_tire_transform, m_asTireLive.transform(r_tire));
53 
54  // contact point directly above ground
55  t_moa_v3 contact_point =
56  m_asTireLive.transform(r_tire).translation();
57  contact_point[2] = m_asGround.height(r_ground);
58 
59  t_moa_v3 contact_point_tire =
60  transformVector<3, t_moa_real>(inv_tire_transform,
61  contact_point);
62 
63  t_moa_v3 Lt = m_asTireLive.transform(r_tire).translation();
64  m_asTireLive.contact_radius(r_tire) =
65  Lt[2] - m_asGround.height(r_ground);
66 
67  // ground_N_tire -- normal in tire space
68  SpatialVector ground_N_tire =
69  rotateVector<3, t_moa_real>
70  (inv_tire_transform, SpatialVector(0,0,1));
71 
72  SpatialVector result;
73  // result -- rotation vector for tilting away from upright
74  cross3(result,ground_N_tire,SpatialVector(0,0,1));
75 
76  t_moa_real m = result[0];
77 
78  // protect the asin() from floating point slightly out
79  if(m > 1.0) { m = 1.0; }
80  if(m < -1.0) { m = -1.0; }
81 
82  m_asTireLive.inclination(r_tire) = asin(m);
83 
84 #if 0
85  m = result[1];
86 
87  // protect the asin() from floating point slightly out
88  if(m > 1.0) { m = 1.0; }
89  if(m < -1.0) { m = -1.0; }
90 
91  m_asTireLive.pitch(r_tire) = asin(m);
92 #endif
93  }
94  }
95  }
96  private:
97  sp<RecordGroup> rg_all;
98  AsGround m_asGround;
99  AsTireLive m_asTireLive;
100  std::vector<Record> m_grounds;
101  std::vector<Record> m_tires;
102 };
103 
104 } /* namespace ext */
105 } /* namespace fe */
106 
107 #endif /* __tire_GroundCollisionSystem_h__ */
108 
kernel
Definition: namespace.dox:3
Ground.
Definition: tireAS.h:147
Matrix< 4, 4, T > & invert(Matrix< 4, 4, T > &a_inverted, const Matrix< 4, 4, T > &a_matrix)
4x4 full matrix inversion
Definition: Matrix.h:1033
Time Stepping System.
Definition: Stepper.h:15
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Run Time Single Contact Tire Model.
Definition: tireAS.h:49
virtual void compile(const t_note_id &a_note_id)
Compile internal structure for dataset.
Definition: GroundCollisionSystem.h:27
MOA Toy/Test Ground Collision System – M*N: Ground and Tires.
Definition: GroundCollisionSystem.h:18
Reference to an instance of a Layout.
Definition: RecordSB.h:35
void step(t_moa_real a_dt)
Move system forward in time by a timestep.
Definition: GroundCollisionSystem.h:35