AGX Dynamics  2.37.2.0
WireWinchController.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
21 
22 #include <agxSDK/Assembly.h>
23 #include <agx/Hinge.h>
24 
25 #include <agx/Range.h>
26 
27 // Forward declarations
28 namespace agx
29 {
30  class RigidBody;
31  class Prismatic;
32 }
33 
34 namespace agxWire
35 {
41  class AGXPHYSICS_EXPORT WireWinchController : public WireAttachmentController, public virtual agxStream::Serializable
42  {
43  public:
53  WireWinchController( agx::RigidBody* body, const agx::Vec3& positionInBodyFrame, const agx::Vec3& normalInBodyFrame, agx::Real pulledInLength = agx::Real( 0 ) );
54 
58  agx::Constraint1DOF* get1DOFConstraint();
59  const agx::Constraint1DOF* get1DOFConstraint() const;
60 
64  inline const agx::Vec3& getNormal() const;
65 
69  agx::Vec3 getWorldNormal() const;
70 
77  void setAutoFeed( bool autoFeed );
78 
83  inline bool getAutoFeed() const;
84 
89  void setSpeed( agx::Real speed );
90 
94  inline agx::Real getSpeed() const;
95 
99  virtual agx::Real getCurrentSpeed() const;
100 
107  void setForceRange( agx::RangeReal forceRange );
108 
113  void setForceRange( agx::Real force );
114 
118  inline const agx::RangeReal& getForceRange() const;
119 
123  virtual agx::Real getCurrentForce() const;
124 
133  void setBrakeForceRange( agx::RangeReal brakeForceRange );
134 
139  void setBrakeForceRange( agx::Real brakeForce );
140 
144  inline const agx::RangeReal& getBrakeForceRange() const;
145 
150  virtual agx::Real getCurrentBrakeForce() const;
151 
158  void setPulledInWireLength( agx::Real pulledInLength );
159 
163  virtual agx::Real getPulledInWireLength() const;
164 
168  agxWire::BodyFixedNode* getFixedNode() const;
169 
173  agxWire::StopNode* getStopNode() const;
174 
178  agx::RigidBody* getRigidBody() const;
179 
183  bool getStopNodeInserted() const;
184 
188  agx::Vec3 getLumpNodeReferencePosition() const;
189 
193  agx::Real getStopNodeReferenceDistance( ) const;
194 
199  void setCompliance( agx::Prismatic* prismatic ) const;
200 
207  void setStabilityController( agxWire::WireStabilityController* stabilityController );
208 
212  void setParameterController( agxWire::WireParameterController* parameters );
213 
214  virtual bool getWithinEndRange( ) const;
215 
217 
218 
224  void setEnableForcedBrake(bool enableForcedBrake);
225 
230  bool getEnableForcedBrake() const;
231 
233 
235 
236  protected:
241 
242  virtual ~WireWinchController();
243 
244  friend class WireInitializationController;
245  friend class WireRouteController;
246  friend class Wire;
247 
251  virtual void addNotification( agxSDK::SimulationProxy* /*simulationProxy*/ ) {}
252 
258  virtual void initialize( bool begin, WireParameterController* parameters ) override;
259 
263  virtual void unitialize();
264 
268  virtual bool attach( WireDistanceCompositeConstraint* constraint, WireParameterController* parameters, bool begin );
269 
278  BodyFixedNode* findParametersHoldingNode( bool begin );
279 
284  bool insertStopNode( bool begin );
285 
290  agx::Real configureInitialState();
291 
295  void massUpdate( agx::Real restLengthChange, bool begin );
296 
300  virtual void preCollideUpdate( agx::Bool /*begin*/, agxSDK::SimulationProxy* /* simulationProxy */ ) {}
301 
305  virtual void preUpdate( agx::Bool /*begin*/, agxSDK::SimulationProxy* /* simulationProxy */ ) {}
306 
310  virtual void update( Node* controlledNode, Node* lumpedNode, bool begin ) override;
311 
315  virtual void postUpdate( agx::Bool /*begin*/, agxSDK::SimulationProxy* /* simulationProxy */ ) {}
316 
322  virtual bool owns( const Node* node ) const override
323  {
324  return m_stopNode == node;
325  }
326 
330  virtual Node* getReferenceNode() override { return m_stopNode; }
331 
335  virtual agx::Real getReferenceCurrentLength( bool begin ) const override;
336 
340  agx::Prismatic* createPrismatic( Node* fixedNode, Node* lumpedNode, const agx::Vec3& worldNormal ) const;
341 
351  void updateConstraintSettings( agx::Prismatic* prismatic, agx::Real desiredSpeed, const agx::RangeReal& forceRange, const agx::RangeReal& brakeRange, bool rangeEnable, bool forcedBrake = false ) const;
352 
358  agx::Real resetLumpPosition( agx::Real angle );
359 
366  BodyFixedNode* getNextLumpedNode( BodyFixedNode* from, bool begin );
367 
368  virtual void forcePulledInLength( agx::Real newLength );
369 
370  virtual void incrementPulledInLength( agx::Real dl );
371 
372  protected:
380 
390  };
391 
395 
396  // Inline methods ***********************************************************************************
397 
398  inline const agx::Vec3& WireWinchController::getNormal() const
399  {
400  return m_normal;
401  }
402 
403  inline bool WireWinchController::getAutoFeed() const
404  {
405  return m_autoFeed;
406  }
407 
408  inline agx::Real WireWinchController::getSpeed() const
409  {
410  return m_speed;
411  }
412 
413  inline const agx::RangeReal& WireWinchController::getForceRange() const
414  {
415  return m_forceRange;
416  }
417 
418  inline const agx::RangeReal& WireWinchController::getBrakeForceRange() const
419  {
420  return m_brakeRange;
421  }
422 
423  inline void WireWinchController::setEnableForcedBrake( bool enableForcedBrake )
424  {
425  m_forcedBrake = enableForcedBrake;
426  }
427 
428  inline bool WireWinchController::getEnableForcedBrake() const
429  {
430  return m_forcedBrake;
431  }
432 
433  // **************************************************************************************************
434 
436  {
437  public:
439  {
440  set( 0, 0, 0 );
441  }
442 
444  {
445  set( v.x(), v.y(), v.z() );
446  }
447 
449  {
450  *this = c;
451  }
452 
454  {
455  _v[ 0 ] = c._v[ 0 ];
456  _v[ 1 ] = c._v[ 1 ];
457  _v[ 2 ] = c._v[ 2 ];
458 
459  return *this;
460  }
461 
462  agx::Real r() const { return _v[ 0 ]; }
463  agx::Real phi() const { return _v[ 1 ]; }
464  agx::Real y() const { return _v[ 2 ]; }
465 
466  agx::Real& r() { return _v[ 0 ]; }
467  agx::Real& phi() { return _v[ 1 ]; }
468  agx::Real& y() { return _v[ 2 ]; }
469 
470  agx::Real x() const { return _v[ 0 ] * std::cos( convertAngle( _v[ 1 ] ) ); }
471  agx::Real z() const { return _v[ 0 ] * std::sin( convertAngle( _v[ 1 ] ) ); }
472 
473  operator agx::Vec3 () const { return agx::Vec3( x(), y(), z() ); }
474 
475  void clampAngle()
476  {
477  if ( _v[ 1 ] < 0 )
478  _v[ 1 ] += 2 * agx::PI;
479  else if ( _v[ 1 ] > 2 * agx::PI )
480  _v[ 1 ] -= 2 * agx::PI;
481  }
482 
483  protected:
484  void set( agx::Real x, agx::Real y, agx::Real z )
485  {
486  // Rho or radius.
487  _v[ 0 ] = std::sqrt( x * x + z * z );
488  agx::Real angle = std::atan2( z, x );
489  _v[ 1 ] = angle < 0 ? 2 * agx::PI + angle : angle;
490  _v[ 2 ] = y;
491  }
492 
494  {
495  agxAssert( !(full < 0) );
496  return full > agx::PI ? full - 2 * agx::PI : full;
497  }
498 
499  agx::Real _v[3];
500  };
501 
503  {
504  WireSimpleDrumControlPoint() : coordinate(), restLength( 0 ), currentLength( 0 ) {}
505  WireSimpleDrumControlPoint( const agx::Vec3& position, agx::Real rest, agx::Real current )
506  : coordinate( position ), restLength( rest ), currentLength( current ) {}
508  {
509  *this = p;
510  }
512  {
513  coordinate = p.coordinate;
514  restLength = p.restLength;
515  currentLength = p.currentLength;
516 
517  return *this;
518  }
519 
520  void store( agxStream::OutputArchive& out ) const;
521  void restore( agxStream::InputArchive& in );
522 
523  CylindricalCoordinateRPY coordinate; // Cylindrical coordinate system (r, phi, y), to fit with cylinder shape axis.
526  };
527 
529 
531  {
532  public:
533  WireSimpleDrumController( agx::Real radius, agx::Real length, size_t maxNumActiveContactNodes = 5, bool upsideDown = false );
534 
541  bool attach( agx::RigidBody* rb, agx::Frame* attachmentFrame );
542 
543  virtual agx::Real getCurrentSpeed() const override;
544  virtual agx::Real getCurrentForce() const override;
545  virtual agx::Real getCurrentBrakeForce() const override;
546  const WireSimpleDrumControlPointList& getControlPoints() const { return m_controlPoints; }
547  agx::RigidBody* getRigidBody() const { return m_rb; }
548  agxCollide::Geometry* getGeometry() const { return m_geometry; }
549  agx::Hinge* getHinge() const { return m_hinge; }
550  using WireWinchController::getConstraint;
551 
552 
554 
555  protected:
558 
559  virtual void initialize( bool begin, WireParameterController* parameters ) override;
560  void initializeControlPoints( WireSimpleDrumControlPointList& controlPoints ) const;
561  virtual void update( Node* controlledNode, Node* lumpedNode, bool begin ) override;
562 
563  void updateHinge( agx::Hinge* h ) const;
564 
565  size_t getNumContacts( bool begin, WireDistanceCompositeConstraint* wire, NodeIterator& lastContact, NodeIterator& firstLumpIter ) const;
566  void createControlPoints( NodeConstIterator from, NodeConstIterator to, size_t numNodes, agx::Real& restLength, agx::Real& currentLength );
567  ContactNode* rollOut( agx::Real& dRestLength, agx::Real& dCurrentLength );
568  void rollIn( bool begin, NodeIterator from, size_t numContacts, agx::Real& dRestLength, agx::Real& dCurrentLength );
569  bool changeBodyFixedToContactNode( BodyFixedNode* bfn );
570  void rebind( const Node* to );
571  bool removeContactNodes( NodeIterator from, NodeIterator to );
572 
573  agx::Real getControlPointRadius() const;
574 
575  private:
576  using WireWinchController::attach;
577 
578  protected:
579  friend class WireSimpleDrumRenderer;
580 
585  WireSimpleDrumControlPointList m_controlPoints;
586  };
587 
589 
590 
592  class WireSimpleDrumRenderer : public ConstraintRenderer
593  {
594  public:
595  WireSimpleDrumRenderer( WireSimpleDrumController* drum )
596  : m_drum( drum ) {}
597 
598  virtual void render( agxRender::RenderManager *mgr, float scale );
599 
600  private:
601  void createCylinder( agxRender::RenderManager *mgr , const agx::Vec3& p1, const agx::Vec3& p2, float radius );
602 
603  private:
605  };
607 
608 }
609 
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
agx::observer_ptr< BodyFixedNode > m_lumpedNode
CylindricalCoordinateRPY(const agx::Vec3 &v)
virtual void postUpdate(agx::Bool, agxSDK::SimulationProxy *)
Post update call from the wire.
const Real PI
Definition: Math.h:63
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
WireParameterController * m_parameters
AGXFMI_EXPORT InputVariable_Real * setCompliance(agx::Constraint *constraint)
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
agx::Real convertAngle(agx::Real full) const
bool Bool
Definition: Integer.h:48
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:60
agx::Vector< WireWinchControllerRef > WireWinchControllerRefVector
agx::RigidBody * getRigidBody() const
agx::ref_ptr< WireWinchController > WireWinchControllerRef
#define AGXPHYSICS_EXPORT
const WireSimpleDrumControlPointList & getControlPoints() const
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:673
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc...
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::List< WireSimpleDrumControlPoint > WireSimpleDrumControlPointList
The body fixed node is attached to a body at a given offset.
Interface and placeholder of controllers/helpers for wires.
Definition: Wire.h:61
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
WireSimpleDrumControlPointList m_controlPoints
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
virtual void preCollideUpdate(agx::Bool, agxSDK::SimulationProxy *)
Pre-collide update call from the wire.
WireSimpleDrumControlPoint(const agx::Vec3 &position, agx::Real rest, agx::Real current)
Class to hold specific parameters for the wire - this makes the wires highly configurable.
agx::Vector< agx::observer_ptr< WireWinchController > > WireWinchControllerObsVector
Stop node, wire end node used by winches.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
virtual bool owns(const Node *node) const override
For the wire to know if node belongs to this attachment.
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition: Hinge.h:103
#define agxAssert(expr)
Definition: debug.h:143
agx::ref_ptr< WireSimpleDrumController > WireSimpleDrumControllerRef
A prismatic joint keeps a fixed relative orientation between the attached bodies but allows them to s...
Definition: Prismatic.h:67
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
agx::observer_ptr< BodyFixedNode > m_parametersHoldingNode
To access and change rest/current length.
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
WireSimpleDrumControlPoint(const WireSimpleDrumControlPoint &p)
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agxCollide::Geometry * getGeometry() const
Contact node class is a node that, currently, is defined to live on an edge on a geometry (agxCollide...
agx::observer_ptr< WireStabilityController > m_stabilityController
If by the initialization controller, this winch can merge segments and change mass of the lumps via t...
virtual Node * getReferenceNode() override
Class defining a node that is part of a wire.
Definition: agxWire/Node.h:511
Interface class used by internal objects running in parallel.
Winch class for handling in and out hauling of wires.
double Real
Definition: Real.h:42
virtual void addNotification(agxSDK::SimulationProxy *)
Called from Wire::addNotification.
virtual void preUpdate(agx::Bool, agxSDK::SimulationProxy *)
Pre update call from the wire.
CylindricalCoordinateRPY(const CylindricalCoordinateRPY &c)
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:66