Marine systems simulation
Winch.h
1#pragma once
2
3#include "SupergridCable.h"
4#include <Eigen/StdVector>
5#include "InitializerTools3DCurve.h"
6#include <fstream>
7#ifdef CORIBO_BOOST
8#include <boost/container/map.hpp>
9#else
10//#include <unordered_set>
11//#include <unordered_map>
12#include <map>
13#endif
14
15#ifdef FH_VISUALIZATION
16#include "sfh/ogre/C3DArrow.h"
17#endif
18
19namespace CoRiBoDynamics {
20
21namespace Structures {
22
23class SupergridWinchCable;
24
34class Winch {
35public:
36 Winch(double drum_length, double drum_diameter, double flange_diameter, double flange_thickness, double beta/*, bool right_handed = true*/);
37 virtual ~Winch();
43
48 void SetWinchRotation(double theta, double omega);
49 double GetWinchTheta(){return m_theta;}
50 double GetWinchOmega(){return m_omega;}
51
52 Quat GetStandardizedOrientationNED();
53
58 void SetStates(const vec3& P, const Quat& Q, const vec3& V, const vec3& W);
59
60 JointConstraint::ExternalRigidCoupling* WinchCoupling(DiscreteElement* connection_element);
61
62
63
64#ifdef FH_VISUALIZATION
65 void RenderInit(Ogre::Root* const ogreRoot);
66 void RenderUpdate(const double T, const double* const X);
67#endif
68
69
71 DiscreteElement* element;
72 Quat Q;
73 vec3 P;
75 double accumulated_volume;
76 double accumulated_weight;
77 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
78 };
79
80 /*
81 Add this element to the winch
82 */
83 void PushElement(AttachedElement& attached_element);
84 void PushElement(DiscreteElement* element, const vec3& P, const Quat& Q);
85 void PushElement(DiscreteElement* element, const double* X);
86
87 /*
88 Remove the top element from the winch
89 */
90 void PopElement(ObjectFactoryStack<DiscreteElement::TempStates>& temp_states_buffer);
91
92 vec3 P(){return m_P;}
93 Quat Q(){return m_Q;}
94 vec3 V(){return m_V;}
95 vec3 W(){return m_W;}
96 Quat baseQ(){return m_base_Q;}
97
101 const std::vector<AttachedElement,Eigen::aligned_allocator<AttachedElement> > GetAttachedCableElements(){return m_attached_elements;}
102
103 /*
104 Returns a vector-of-vectors of collition candidates.
105 The outer vector corresponds element-by-element to the argument vector, and each inner vector is a set of candidates for more accurate contact detection
106 */
107 std::vector<std::vector<CollisionManager::ExternalObject*> > GetAttachedGeometry(const std::vector<CollisionManager::InternalObject*>& InternalObjects);
108 std::vector<CollisionManager::ExternalObject*> CollisionCandidates(GeometryTools::AABB aabb);
109
110 double DrumVirtualRadius(){return m_virtual_radius;}
111 double DrumRadius(){return 0.5*m_drum_diameter;}
112 double DrumDiameter(){return m_drum_diameter;}
113 double DrumLength(){return m_drum_length;}
114 double FlangeRadius(){return 0.5*m_flange_diameter;}
115 double FlangeDiameter(){return m_flange_diameter;}
116
117 void SetLineStructure(SupergridWinchCable* line_structure);
118
119 virtual void XmlInfo(TiXmlElement& xml_node);
120
121 double GetRetractedLength();
122
123 void WriteAttachedGeometryDataToFile(std::string filename);
124
125 /*
126 Utility class for reading a file of initial conditions.
127 */
129 public:
130 explicit InitialStatesLoader(std::string filename);
131 std::vector<AttachedElement,Eigen::aligned_allocator<AttachedElement>>::iterator GetIterator();
132 std::vector<AttachedElement,Eigen::aligned_allocator<AttachedElement>>::iterator GetEnd();
133 private:
134 std::vector<AttachedElement,Eigen::aligned_allocator<AttachedElement>> m_elements;
135 };
136 void LoadAttachedGeometryDataFromFile(InitialStatesLoader states, std::vector<DiscreteElement*>& super_elements, size_t& super_ix, size_t& sub_ix, const vec3& target_point);
137 static void WinchInitFileInfo(std::string filename, std::vector<double>& angle, std::vector<double>& retracted_length);
138
139 GeometryTools::AABB GetWinchAABB();
140
142 public:
143 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
144 SpoolingDevice(vec3 relative_position, double radius, double length, double beta);
145 vec3 GetPassThroughPoint();
146 void UpdateStates(vec3& winch_P, Quat& winch_base_Q, vec3& winch_V, vec3& winch_W);
147 CollisionManager::ExternalObject* GetContactGeometry();
148 vec3 RelativePosition(){return m_relative_position;}
149
150#ifdef FH_VISUALIZATION
151 virtual void RenderInit(Ogre::Root* const ogreRoot);
152 virtual void RenderUpdate(const double T, const double* const X);
153 Ogre::SceneNode* m_node;
154#endif
155
156 protected:
157 vec3 m_relative_position;
158 double m_state_data[13];
160 };
161
162 void SetSpoolingDevice(vec3 relative_position, double rail_radius);
163
164 SpoolingDevice* GetSpoolingDevice(){return m_spooling_device;}
165 CollisionManager::ExternalObject* GetSpoolingDeviceContactGeometry();
166
167
168 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
169protected:
170 void UpdateWinchDrumGeometry();
171
173 public:
175
176 void Setup(Winch* winch);
177
178 void InsertElement(GeometryTools::AABB aabb, int ix);
179 void RemoveElement(GeometryTools::AABB aabb, int ix);
180 void GetContactCandidates(GeometryTools::AABB aabb, DataStructures::RadixSparseSet& accumulated_candidates);
181
182 protected:
183 double m_lxy;
184 double m_lz;
185 int m_nxy;
186 int m_nz;
187
189 public:
190 int GetNext();
191
192 uint8_t ix;
193 uint8_t iy;
194 uint8_t iz;
195 uint8_t lo_ix;
196 uint8_t lo_iy;
197 uint8_t lo_iz;
198 uint8_t hi_ix;
199 uint8_t hi_iy;
200 uint8_t hi_iz;
201 uint8_t nx;
202 uint8_t ny;
203 uint8_t nz;
204 };
205
206 std::vector<std::vector<unsigned short>> m_data;
207
208 Dim3Index CreateIndex(GeometryTools::AABB aabb);
209 };
210 SpatialPartition m_spatial_partition;
211
212 struct StateData{
213 double P[3];
214 double Q[4];
215 double V[3];
216 double W[3];
217 StateData(){
218 V3ptr(vec3::Zero(),P);
219 Qptr(dblQ(0),Q);
220 V3ptr(vec3::Zero(),V);
221 V3ptr(vec3::Zero(),W);
222 }
223 };
224
225 SupergridWinchCable* m_line_structure;
226
227 double m_beta;
228 public:
231 StateData data;
232 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
233 };
234 protected:
235 ObjectFactoryStack<ObjectAndStates> m_attached_geometry;
236#ifdef CORIBO_BOOST
237 boost::container::map<int,ObjectAndStates*> m_accumulated_candidates;
238#else
239 std::map<int,ObjectAndStates*> m_accumulated_candidates;
240#endif
241 std::vector<AttachedElement,Eigen::aligned_allocator<AttachedElement>> m_attached_elements;
242
243
244 std::vector<CollisionManager::ExternalObject*> m_winch_geometry;
248
249 CollisionManager::ExternalObject m_block_pin_upper;
250 CollisionManager::ExternalObject m_block_pin_lower;
251
252 double m_drum_length;
253 double m_drum_diameter;
254 double m_flange_diameter;
255 double m_flange_thickness;
256 double m_virtual_radius;
257
258 double m_nominal_cable_radius;
259
260 double m_base_Q_array[4];
261 double m_block_upper_V_array[3];
262 double m_block_lower_V_array[3];
263 double m_block_upper_P_array[3];
264 double m_block_lower_P_array[3];
265
266 double m_winch_Q_array[4];
267 double m_flange1_V_array[3];
268 double m_flange2_V_array[3];
269 double m_flange1_P_array[3];
270 double m_flange2_P_array[3];
271
272 double m_theta;
273 double m_omega;
274 Quat m_base_Q;
275 vec3 m_base_W;
276
277 vec3 m_P;
278 Quat m_Q;
279 vec3 m_V;
280 vec3 m_W;
281
283 vec3 m_winch_base_flange_connection;
284 vec3 m_winch_base_connection_vector;
286
287 SpoolingDevice *m_spooling_device;
288
289
290#ifdef FH_VISUALIZATION
291 Ogre::SceneNode* m_winch_node;
292 Ogre::SceneNode* m_virtual_drum_node;
293 std::vector<Ogre::SceneNode*> m_element_nodes;
294 Ogre::SceneNode* m_base_node;
295#endif
296};
297
298
299
306public:
307 TowingBlock(ISimObjectCreator* creator, std::string state_prefix, double block_width, double block_diameter, double flange_diameter, double flange_thickness, double pivot_arm_length, double beta);
308
313
318 void SetStates(const vec3& P, const Quat& Q, const vec3& V, const vec3& W);
319
320
321 const std::vector<CollisionManager::ExternalObject*> GetTowingBlockGeometry();
322
323#ifdef FH_VISUALIZATION
324 void RenderInit(Ogre::Root* const ogreRoot);
325 void RenderUpdate(const double T, const double* const X);
326#endif
327
328 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
329
330 vec3 P(){return m_P;}
331 Quat Q(){return m_Q;}
332 vec3 V(){return m_V;}
333 vec3 W(){return m_W;}
334
335 Quat GetStandardizedOrientationNED();
336
338
339 double GetBlockRadius(){return 0.5*m_block_diameter;}
340
341 vec3 PassThroughPoint();
342 vec3 TopPoint();
343 vec3 InletPoint();
344 vec3 OutletPoint();
345
346 virtual void XmlInfo(TiXmlElement& xml_node);
347
348 void Flagging_OdeFcn(const double T, const double * const X, double * const XDot);
349
350 vec3 PivotArm();
354 double PivotAngle();
355
356 void SetFlaggingResponseCoefficient(double c){m_flagging_response_coefficient = c;}
357
358protected:
359 struct StateData{
360 double P[3];
361 double Q[4];
362 double V[3];
363 double W[3];
364 };
365
366 SupergridWinchCable* m_line_structure;
367 double m_beta;
368
369 std::vector<CollisionManager::ExternalObject*> m_block_geometry;
370 CollisionManager::ExternalObject m_block_capsule;
373 CollisionManager::ExternalObject m_flange_cover_capsule;
374
375 double m_block_width;
376 double m_block_diameter;
377 double m_flange_diameter;
378 double m_flange_thickness;
379 double m_pivot_arm_length;
380
381 double m_pivot_arm_angle;
382 int m_pivot_angle_ix;
383
384 vec3 m_block_base_flange_connection;
385 vec3 m_block_base_cover_connection;
386
387 vec3 m_P;
388 Quat m_Q;
389 vec3 m_V;
390 vec3 m_W;
391
392
393
395 StateData m_flange1_states;
396 StateData m_flange2_states;
397 StateData m_flange_cover_states;
398
399 double m_flagging_response_coefficient;
400
401#ifdef FH_VISUALIZATION
402 Ogre::SceneNode* m_block_node;
403#endif
404};
405
406}
407}
Definition: CollisionManager.h:135
Definition: DataStructures.h:27
Definition: ObjectFactoryStack.h:22
Definition: SupergridLineStructure.h:73
Definition: SupergridWinchCable.h:27
Quat BlockOrientation()
block center position
void SetLineStructure(SupergridWinchCable *line_structure)
Returns orientation in a standardized Forward-Starboard-Down oriented coordinate system in a Roll/Pit...
Quat m_Q
pivot position
Definition: Winch.h:388
vec3 m_W
pivot velocity
Definition: Winch.h:390
vec3 NeutralPivotArm()
vector from pivot to block center
double PivotAngle()
block orientation
vec3 m_V
pivot orientation
Definition: Winch.h:389
vec3 BlockPosition()
vector from pivot to neutral angle block center
void SetStates(const vec3 &P, const Quat &Q, const vec3 &V, const vec3 &W)
StateData m_block_states
pivot angular velocity
Definition: Winch.h:394
Definition: Winch.h:34
vec3 m_V
center orientation
Definition: Winch.h:279
void SetWinchRotation(double theta, double omega)
Quat m_base_Q
winch rotation speed
Definition: Winch.h:274
vec3 m_P
winch base rotation speed
Definition: Winch.h:277
vec3 m_base_W
winch base orientation
Definition: Winch.h:275
vec3 m_W
center velocity
Definition: Winch.h:280
vec3 m_winch_base_pin_connection
center angular velocity
Definition: Winch.h:282
std::vector< CollisionManager::ExternalObject * > m_winch_geometry
relative position and orientation of attached cable elements
Definition: Winch.h:244
Quat m_Q
center position
Definition: Winch.h:278
const std::vector< AttachedElement, Eigen::aligned_allocator< AttachedElement > > GetAttachedCableElements()
Definition: Winch.h:101
void SetStates(const vec3 &P, const Quat &Q, const vec3 &V, const vec3 &W)
Returns orientation in a standardized Forward-Starboard-Down oriented coordinate system in a Roll/Pit...
double m_omega
winch rotation
Definition: Winch.h:273
Definition: CollisionManager.h:6
void V3ptr(const vec3 &V, double *ptr)
writes the vector to ptr
Quat dblQ(double d)
writes the quaternion from ptr in w,x,y,z order
void Qptr(const Quat &Q, double *ptr)
returns the (d,d,d,d) quaternion
Definition: GeometryTools.h:88
double accumulated_length
position relative to winch coordinate system
Definition: Winch.h:74
vec3 P
orientation relative to winch coordinate system
Definition: Winch.h:73