Free Electron
ParticleMountSystem.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_ParticleMountSystem_h__
8 #define __tire_ParticleMountSystem_h__
9 
10 #include "solve/solve.h"
11 
12 namespace fe
13 {
14 namespace ext
15 {
16 
17 /// @brief Tire to Particles Connection
19  virtual public Stepper,
20  public Initialize<ParticleMountSystem>
21 {
22  public:
23  struct Mount
24  {
25  WeakRecord m_r_parent;
26  WeakRecord m_r_p0;
27  WeakRecord m_r_p1;
28  WeakRecord m_r_p2;
29  WeakRecord m_r_tire;
30  t_moa_xform m_inv_R;
31  };
33  {
34  }
35  void initialize(void) {}
36 virtual void compile(const t_note_id &a_note_id)
37  {
38  sp<Scope> spScope = m_rg_dataset->scope();
39 
40  if(!spScope.isValid()) { return; }
41 
42  enforce<AsTire,AsTireLive>(m_rg_dataset);
43 
44  m_asPoint.bind(spScope);
45  m_asTireLive.bind(spScope);
46  m_asMount.bind(spScope);
47 
48  AsTire asTire(spScope);
49 
50  RecordDictionary<AsTire> rd_tires(m_rg_dataset);
51 
52  std::vector<Record> mounts;
53  m_asMount.filter(mounts, m_rg_dataset);
54 
55  for(unsigned int i_mount = 0; i_mount < mounts.size(); i_mount++)
56  {
57  Record &r_mount = mounts[i_mount];
58  Mount mount;
59  mount.m_r_parent = r_mount;
60  mount.m_r_p0 = m_asMount.p0(r_mount);
61  mount.m_r_p1 = m_asMount.p1(r_mount);
62  mount.m_r_p2 = m_asMount.p2(r_mount);
63  mount.m_r_tire = rd_tires[m_asMount.tire(r_mount)];
64  if( mount.m_r_p0.isValid() &&
65  mount.m_r_p1.isValid() &&
66  mount.m_r_p2.isValid() &&
67  mount.m_r_tire.isValid() &&
68  m_asPoint.check(mount.m_r_p0) &&
69  m_asPoint.check(mount.m_r_p1) &&
70  m_asPoint.check(mount.m_r_p2) &&
71  m_asTireLive.check(mount.m_r_tire))
72  {
73 
74  t_moa_xform frame;
75  t_moa_xform relative;
76  setIdentity(relative);
77 
78  bool frame_made = makeFrame(frame,
79  m_asPoint.location(mount.m_r_p0),
80  m_asPoint.location(mount.m_r_p1),
81  m_asPoint.location(mount.m_r_p2),
82  relative);
83 
84  invert(mount.m_inv_R, frame);
85 
86  translate(relative, m_asMount.location(r_mount));
87  rotate(relative, m_asMount.inclination(r_mount),
88  e_xAxis);
89 
90 //rotate(relative, 0.44, e_yAxis);
91 //rotate(relative, -0.44, e_zAxis);
92 
93  mount.m_inv_R = relative * mount.m_inv_R;
94 
95  m_mounts.push_back(mount);
96  }
97  }
98 
99  }
100  void step(t_moa_real a_dt)
101  {
102  for(unsigned int i_mount = 0; i_mount < m_mounts.size(); i_mount++)
103  {
104  WeakRecord &r_p0 = m_mounts[i_mount].m_r_p0;
105  WeakRecord &r_p1 = m_mounts[i_mount].m_r_p1;
106  WeakRecord &r_p2 = m_mounts[i_mount].m_r_p2;
107  WeakRecord &r_tire = m_mounts[i_mount].m_r_tire;
108  WeakRecord &r_mount = m_mounts[i_mount].m_r_parent;
109 
110  t_moa_xform frame;
111  t_moa_xform relative;
112  setIdentity(relative);
113  bool frame_made = makeFrame(frame,
114  m_asPoint.location(r_p0),
115  m_asPoint.location(r_p1),
116  m_asPoint.location(r_p2),
117  m_mounts[i_mount].m_inv_R);
118 
119  m_asTireLive.transform(r_tire) = frame;
120  invert(m_asMount.transform_inv(r_mount),
121  m_asTireLive.transform(r_tire));
122 
123  t_moa_v3 tire_space_p0_v = rotateVector<3, t_moa_real>
124  (m_asMount.transform_inv(r_mount),
125  m_asPoint.velocity(r_p0));
126 
127 
128  t_moa_v3 vel = tire_space_p0_v;
129 
130  m_asTireLive.velocity(r_tire) = vel;
131 
132 //TODO: ang vel -- frame ang is purely reflection -- useful ang vel from driveline
133 //TODO: grip point TM
134  }
135  accumulate();
136  }
137  void accumulate(void)
138  {
139  for(unsigned int i_mount = 0; i_mount < m_mounts.size(); i_mount++)
140  {
141  WeakRecord &r_p0 = m_mounts[i_mount].m_r_p0;
142  WeakRecord &r_p1 = m_mounts[i_mount].m_r_p1;
143  WeakRecord &r_p2 = m_mounts[i_mount].m_r_p2;
144  WeakRecord &r_tire = m_mounts[i_mount].m_r_tire;
145 
146  t_moa_xform tire_xform = m_asTireLive.transform(r_tire);
147 
148  t_moa_v3 rig_space_F = rotateVector<3, t_moa_real>
149  (tire_xform, m_asTireLive.force(r_tire));
150  t_moa_v3 rig_space_M = rotateVector<3, t_moa_real>
151  (tire_xform, m_asTireLive.moment(r_tire));
152 
153  t_moa_v3 rig_space_P = tire_xform.translation();
154 
155  applyFMToPoints(rig_space_F, rig_space_M, rig_space_P,
156  m_asPoint, r_p0, r_p1, r_p2);
157  }
158  }
159 
160  std::vector<Mount> m_mounts;
161  AsForcePoint m_asPoint;
162  AsTireLive m_asTireLive;
163  AsParticlesMount m_asMount;
164 };
165 
166 } /* namespace ext */
167 } /* namespace fe */
168 
169 #endif /* __tire_ParticleMountSystem_h__ */
170 
virtual void compile(const t_note_id &a_note_id)
Compile internal structure for dataset.
Definition: ParticleMountSystem.h:36
Tire.
Definition: tireAS.h:36
kernel
Definition: namespace.dox:3
force application point
Definition: shapeAS.h:42
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
Tire to Particles Connection.
Definition: ParticleMountSystem.h:18
void step(t_moa_real a_dt)
Move system forward in time by a timestep.
Definition: ParticleMountSystem.h:100
Run Time Single Contact Tire Model.
Definition: tireAS.h:49
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordSB.h:17