AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
WireWinchController.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
28namespace agx
29{
30 class RigidBody;
31 class Prismatic;
32}
33
34namespace 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
60
64 inline const agx::Vec3& getNormal() const;
65
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
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
151
158 void setPulledInWireLength( agx::Real pulledInLength );
159
164
169
174
179
184
189
194
199 void setCompliance( agx::Prismatic* prismatic ) const;
200
207 void setStabilityController( agxWire::WireStabilityController* stabilityController );
208
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
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
279
284 bool insertStopNode( bool begin );
285
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
359
367
368 virtual void forcePulledInLength( agx::Real newLength );
369
371
372 protected:
380
390 };
391
395
396 // Inline methods ***********************************************************************************
397
399 {
400 return m_normal;
401 }
402
404 {
405 return m_autoFeed;
406 }
407
409 {
410 return m_speed;
411 }
412
414 {
415 return m_forceRange;
416 }
417
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
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:
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
500 };
501
503 {
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 {
516
517 return *this;
518 }
519
520 void store( agxStream::OutputArchive& out ) const;
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;
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 );
570 void rebind( const Node* to );
572
574
575 private:
576 using WireWinchController::attach;
577
578 protected:
579 friend class WireSimpleDrumRenderer;
580
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
#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
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc.
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:70
Interface class used by internal objects running in parallel.
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
The body fixed node is attached to a body at a given offset.
Contact node class is a node that, currently, is defined to live on an edge on a geometry (agxCollide...
agx::Real convertAngle(agx::Real full) const
void set(agx::Real x, agx::Real y, agx::Real z)
CylindricalCoordinateRPY(const CylindricalCoordinateRPY &c)
CylindricalCoordinateRPY & operator=(const CylindricalCoordinateRPY &c)
CylindricalCoordinateRPY(const agx::Vec3 &v)
Class defining a node that is part of a wire.
Definition: agxWire/Node.h:512
Stop node, wire end node used by winches.
Class to hold specific parameters for the wire - this makes the wires highly configurable.
virtual void update(Node *controlledNode, Node *lumpedNode, bool begin) override
Called when it's time to update the constraint and reset the position of the lump.
void initializeControlPoints(WireSimpleDrumControlPointList &controlPoints) const
virtual void initialize(bool begin, WireParameterController *parameters) override
Initializes this winch (inserts the stop node and move the lump for example).
agx::Real getControlPointRadius() const
virtual agx::Real getCurrentSpeed() const override
bool changeBodyFixedToContactNode(BodyFixedNode *bfn)
WireSimpleDrumController(agx::Real radius, agx::Real length, size_t maxNumActiveContactNodes=5, bool upsideDown=false)
WireSimpleDrumControlPointList m_controlPoints
void createControlPoints(NodeConstIterator from, NodeConstIterator to, size_t numNodes, agx::Real &restLength, agx::Real &currentLength)
virtual agx::Real getCurrentForce() const override
virtual agx::Real getCurrentBrakeForce() const override
const WireSimpleDrumControlPointList & getControlPoints() const
bool attach(agx::RigidBody *rb, agx::Frame *attachmentFrame)
Attach this simple drum to a rigid body using an attachment frame.
bool removeContactNodes(NodeIterator from, NodeIterator to)
void rollIn(bool begin, NodeIterator from, size_t numContacts, agx::Real &dRestLength, agx::Real &dCurrentLength)
void updateHinge(agx::Hinge *h) const
ContactNode * rollOut(agx::Real &dRestLength, agx::Real &dCurrentLength)
agx::RigidBody * getRigidBody() const
size_t getNumContacts(bool begin, WireDistanceCompositeConstraint *wire, NodeIterator &lastContact, NodeIterator &firstLumpIter) const
agxCollide::Geometry * getGeometry() const
Winch class for handling in and out hauling of wires.
virtual bool getWithinEndRange() const
void setStabilityController(agxWire::WireStabilityController *stabilityController)
Associate a stability controller to this winch.
bool insertStopNode(bool begin)
Inserts the stop wire node in the wire.
void setSpeed(agx::Real speed)
Set winch motor speed.
WireParameterController * m_parameters
virtual bool owns(const Node *node) const override
For the wire to know if node belongs to this attachment.
void massUpdate(agx::Real restLengthChange, bool begin)
Updates mass for lumped nodes where the rest length is changed by restLengthChange.
WireWinchController(agx::RigidBody *body, const agx::Vec3 &positionInBodyFrame, const agx::Vec3 &normalInBodyFrame, agx::Real pulledInLength=agx::Real(0))
Construct this winch given position, normal and body this winch is attached to.
const agx::Vec3 & getNormal() const
virtual agx::Real getCurrentForce() const
void setForceRange(agx::RangeReal forceRange)
Set the desired winch force where range::lower is the force in which this winch may haul in wire,...
agxWire::BodyFixedNode * getFixedNode() const
virtual void unitialize()
Forgets about all wire parameters and clears the constraint.
agx::Vec3 getWorldNormal() const
agx::Prismatic * createPrismatic(Node *fixedNode, Node *lumpedNode, const agx::Vec3 &worldNormal) const
Creates a prismatic constraint given the fixed-, lumped node and a normal.
agx::observer_ptr< BodyFixedNode > m_parametersHoldingNode
To access and change rest/current length.
virtual agx::Real getCurrentBrakeForce() const
virtual agx::Real getCurrentSpeed() const
const agx::RangeReal & getForceRange() const
agx::observer_ptr< WireStabilityController > m_stabilityController
If by the initialization controller, this winch can merge segments and change mass of the lumps via t...
agx::RigidBody * getRigidBody() const
void setCompliance(agx::Prismatic *prismatic) const
Sets the default compliance for the prismatic constraint.
agx::Real resetLumpPosition(agx::Real angle)
Resets the lump position to reference.
virtual void initialize(bool begin, WireParameterController *parameters) override
Initializes this winch (inserts the stop node and move the lump for example).
agx::Real getStopNodeReferenceDistance() const
virtual void forcePulledInLength(agx::Real newLength)
void setBrakeForceRange(agx::RangeReal brakeForceRange)
Set the desired brake force range where range::lower is the force in which this winch brake can hold ...
virtual void incrementPulledInLength(agx::Real dl)
virtual void preCollideUpdate(agx::Bool, agxSDK::SimulationProxy *)
Pre-collide update call from the wire.
virtual bool attach(WireDistanceCompositeConstraint *constraint, WireParameterController *parameters, bool begin)
Create new nodes for new wire.
void updateConstraintSettings(agx::Prismatic *prismatic, agx::Real desiredSpeed, const agx::RangeReal &forceRange, const agx::RangeReal &brakeRange, bool rangeEnable, bool forcedBrake=false) const
Updates motor, lock and range parameters.
const agx::Constraint1DOF * get1DOFConstraint() const
virtual agx::Real getPulledInWireLength() const
void setForceRange(agx::Real force)
Same as setForceRange( agx::RangeReal forceRange ) but this method will set range as [-force,...
void setPulledInWireLength(agx::Real pulledInLength)
Set the pulled in length for this winch.
agxWire::StopNode * getStopNode() const
virtual void update(Node *controlledNode, Node *lumpedNode, bool begin) override
Called when it's time to update the constraint and reset the position of the lump.
agx::observer_ptr< BodyFixedNode > m_lumpedNode
void setParameterController(agxWire::WireParameterController *parameters)
Associate a parameter controller to this winch.
virtual agx::Real getReferenceCurrentLength(bool begin) const override
agx::Real configureInitialState()
This method will set the position of the lumped node given the stop node and pulled in length.
virtual void preUpdate(agx::Bool, agxSDK::SimulationProxy *)
Pre update call from the wire.
void setAutoFeed(bool autoFeed)
Set auto feed to this winch.
virtual Node * getReferenceNode() override
const agx::RangeReal & getBrakeForceRange() const
BodyFixedNode * getNextLumpedNode(BodyFixedNode *from, bool begin)
Finds the next (or previous) lumped node given a lumped node and the direction of the search.
void setBrakeForceRange(agx::Real brakeForce)
Same as setBrakeForceRange( agx::RangeReal brakeForceRange ) but this method will set range as [-brak...
agx::Vec3 getLumpNodeReferencePosition() const
virtual void postUpdate(agx::Bool, agxSDK::SimulationProxy *)
Post update call from the wire.
agx::Constraint1DOF * get1DOFConstraint()
Get pointer to Constraint1DOF.
BodyFixedNode * findParametersHoldingNode(bool begin)
Search the wire, given begin true of false, for the parameters holding node.
Interface and placeholder of controllers/helpers for wires.
Definition: Wire.h:62
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:710
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
The hinge constraint between two rigid bodies or one rigid body and the world.
Definition: Hinge.h:104
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:49
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:61
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
agx::Vector< agx::observer_ptr< WireWinchController > > WireWinchControllerObsVector
NodeContainer::const_iterator NodeConstIterator
Definition: agxWire/Node.h:57
agx::ref_ptr< WireSimpleDrumController > WireSimpleDrumControllerRef
agx::List< WireSimpleDrumControlPoint > WireSimpleDrumControlPointList
agx::ref_ptr< WireWinchController > WireWinchControllerRef
agx::Vector< WireWinchControllerRef > WireWinchControllerRefVector
NodeContainer::iterator NodeIterator
Definition: agxWire/Node.h:54
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
bool Bool
Definition: Integer.h:40
static constexpr Real PI
Definition: Math.h:63
double Real
Definition: Real.h:41
WireSimpleDrumControlPoint & operator=(const WireSimpleDrumControlPoint &p)
void restore(agxStream::InputArchive &in)
void store(agxStream::OutputArchive &out) const
WireSimpleDrumControlPoint(const agx::Vec3 &position, agx::Real rest, agx::Real current)
WireSimpleDrumControlPoint(const WireSimpleDrumControlPoint &p)