AGX Dynamics  2.37.3.2
Actuator1DOF.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 
18 #pragma once
19 
20 #include <agx/Constraint.h>
21 #include <agx/DistanceJoint.h>
22 #include <agx/Hinge.h>
23 #include <agx/Prismatic.h>
24 #include <agx/Referenced.h>
25 #include <agxPowerLine/Actuator.h>
31 
32 namespace agx
33 {
34  class RigidBody;
35 }
36 
37 namespace agxPowerLine
38 {
39 
41 
47  {
48  public:
49  virtual bool isValid() const = 0;
50 
58  virtual void transform() = 0;
59 
64  virtual agx::Vec3 getWorldPosition(agx::UInt index) const = 0;
65 
70  {
71  // First body is on index 0.
72  return getWorldPosition(0);
73  }
74 
79  {
80  // Second body is on index 1.
81  return getWorldPosition(1);
82  }
83 
88  virtual agx::Vec3 getWorldDirection(agx::UInt index) const = 0;
89 
94  {
95  // First body is on index 0.
96  return getWorldDirection(0);
97  }
98 
103  {
104  // Second body is on index 1.
105  return getWorldDirection(1);
106  }
107 
112  virtual agx::Vec3 getCmToPosition(agx::UInt index) const = 0;
113 
118  {
119  // First body is at index 1.
120  return getCmToPosition(0);
121  }
122 
127  {
128  return getCmToPosition(1);
129  }
130 
134  virtual agx::Vec3 getSeparation() const = 0;
135 
142  virtual agx::Real getAngle() const = 0;
143 
150  {
151  return {getMinAngle(), getMaxAngle()};
152  }
153 
157  virtual agx::Real getMinAngle() const = 0;
158 
162  virtual agx::Real getMaxAngle() const = 0;
163 
172  virtual bool setConstraint(agx::Constraint* constraint) = 0;
173 
174  virtual const agx::Constraint* getConstraint() const = 0;
175  virtual agx::Constraint* getConstraint() = 0;
176 
177  AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(agxPoerLine::ConstraintGeometry)
178  };
179 
180 
181 
188  {
189  public:
191 
198 
202  virtual bool isValid() const override;
203 
204  virtual void transform() override;
205 
206  virtual agx::Vec3 getWorldPosition(agx::UInt index) const override;
207  virtual agx::Vec3 getWorldDirection(agx::UInt index) const override;
208  virtual agx::Vec3 getCmToPosition(agx::UInt index) const override;
209 
210  virtual agx::Vec3 getSeparation() const override;
211  virtual agx::Real getAngle() const override;
212  virtual agx::RangeReal getAngleRange() const override;
213  virtual agx::Real getMinAngle() const override;
214  virtual agx::Real getMaxAngle() const override;
215 
216  virtual bool setConstraint(agx::Constraint* constraint) override;
217  bool setConstraint(agx::Constraint* constraint, agx::BasicControllerConstraint* controller);
218 
219  virtual const agx::Constraint* getConstraint() const override;
220  virtual agx::Constraint* getConstraint() override;
221 
222  agx::BasicControllerConstraint* getController();
223  const agx::BasicControllerConstraint* getController() const;
224 
226 
227  const agx::ConstraintAngleBasedData& getAngleData() const;
228 
229  private:
230  agx::Constraint* m_constraint;
231  agx::BasicControllerConstraint* m_controller;
232  };
233 
234 
235 
241  {
242  public:
245 
246  virtual bool isValid() const override;
247 
255  virtual bool setConstraint(agx::Constraint* constraint) override;
256 
258 
259  private:
260  // Safe to keep a raw pointer because Actuator1DOF will clear this
261  // pointer from its objectDeleted observer_ptr callback.
262  agx::Constraint1DOF* m_constraint;
263  };
264 
265 
266 
268 
269 
276  {
277  public:
278 
279  Actuator1DOF(agx::Constraint1DOF* constraint1DOF);
280  Actuator1DOF(agx::Constraint* constraint1DOF, ConstraintGeometry* constraintGeometry);
281 
282  // Begin agxPowerLine::Actuator interface.
283  virtual agx::Real calculateRelativeValue() const override;
284  // End PowerLine::Actuator interface.
285 
286  // Begin PowerLine::Unit interface.
287  virtual agxPowerLine::DimensionAndSide getConnectableDimension(
289  agxPowerLine::Side side) override;
290  // End PowerLine::Unit interface.
291 
292 
293  // Begin PowerLine::SubGraph interface.
294  virtual bool preUpdate(agx::Real timeStamp) override;
295  // End PowerLine::SubGraph interface.
296 
297  ConstraintGeometry* getConstraintGeometry();
298  const ConstraintGeometry* getConstraintGeometry() const;
299 
304  void synchronizeDirections();
305 
309  virtual bool store(agxStream::StorageStream& str) const override;
310 
312 
316  virtual bool restore(agxStream::StorageStream& str) override;
317 
319 
321  void store(agxStream::OutputArchive& out) const override;
322  void restore(agxStream::InputArchive& in) override;
323 
324  protected:
325  Actuator1DOF();
326 
327  virtual ~Actuator1DOF();
328 
329  void synchronizeUnits(agx::Constraint* constraint);
330  void replaceActuatorUnit(Unit* oldUnit, Unit* newUnit);
331 
332  void detachActuatorUnitsFromEachOther();
333 
334  virtual agx::Vec3 getDir1() const override;
335  virtual agx::Vec3 getDir2() const override;
336  virtual agx::Vec3 getCmToAnchorPos1() const override;
337  virtual agx::Vec3 getCmToAnchorPos2() const override;
338  virtual agx::Vec3 getSeparation() const override;
339 
340 
341  protected:
346  class ConstraintObserver : public agx::observer_ptr<agx::Constraint>
347  {
348  public:
349  ConstraintObserver(agx::Constraint* actuatedConstraint, Actuator1DOF* owningActuator);
350  virtual void objectDeleted(void*) override;
351 
353  private:
354  Actuator1DOF* m_owningActuator;
355  };
356 
357  friend class ConstraintObserver;
358 
359  protected:
362 
366  agx::ref_ptr<agxPowerLine::ActuatorBodyUnit> m_dummyActuatorBodyUnits[2];
367  };
368 
369 
370 
372  {
373  public:
374  // \todo Not sure what the best type to take here is. Constraint1DOF is
375  // too lenient but Hinge may be too restrictive. How do I spell
376  // "Constraints with a rotational part."? Does that even make sense?
377  // What other types of Constraints would match, more than Hinge and
378  // Cylindrical? Don't forget SlackCylindrical. And SplineJoint while we're
379  // at it.
381 
382 
391  RotationalActuator(agx::Constraint* constraint, agxPowerLine::ConstraintGeometry* constraintGeometry);
392 
396  agx::Bool getUseHighSpeedMode( ) const;
397 
408  void setUseHighSpeedMode( agx::Bool highSpeedMode );
409 
415  agxPowerLine::RotationalUnit* getInputShaft();
416 
417 
418  virtual void setEnable(bool enabled);
419  virtual bool getEnable() const;
420 
421  // Called by the rest of the power line framework.
422  public:
423  virtual bool preUpdate(agx::Real timeStamp) override;
424 
425  virtual void getConnectableDimensionTypes(
427  agxPowerLine::Side side) const override;
428 
429  virtual agx::Real calculateRelativeGradient() const override;
430 
431  virtual agx::Vec3 calculateWorldDirection(
432  Side side,
433  agxPowerLine::PhysicalDimension::Type dimensionType) const override;
434 
435  virtual agx::Vec3 calculateLocalDirection(
436  Side side,
437  int dimensionType) const override;
438 
442  virtual bool store(agxStream::StorageStream& out) const override;
443 
447  virtual bool restore(agxStream::StorageStream& in) override;
448 
450 
452  public:
453  virtual agxPowerLine::DimensionAndSide getConnectableDimension(
455  agxPowerLine::Side side) override;
456 
457 
458  protected:
460 
461  /*
462  There are subclasses of RotationalActuator that want to create their own
463  versions of the input shaft and the internal connector. For example, the
464  hydraulics package contains the ImpellerActuator, which uses a FlowUnit
465  for input.
466 
467  Any subclass that uses the dont_create_input tag when constructing the
468  RotationalActuator base class must implement get- and setEnable.
469 
470  This part of the inheritence tree could use some redesign. There should
471  be one base class, inheriting from Actuator1DOF, that knows about hinges
472  and how to get Jacobians from them, and a collection of subclasses
473  derived of off that that knows about the type of the input and the custom
474  constraint that binds the input PhysicalDimension to the
475  ActuatorBodyUnits.
476 
477  Perhaps we should even move the concept of input unit and internal
478  constraint up a bit more and put it inside Actuator1DOF. In that case we
479  don't have to deal with the oddities of the current setEnable
480  implementation, which is just bad. A base class implementation does the
481  wrong thing for the derived classes.
482 
483  Not sure if the name RotationalActuator should be used for the base class
484  or the subclass that has a RotationalUnit input. The latter is more
485  consistent with the current implementation and a better user-level name
486  (the base class is not user-level), but what should the base class be
487  named?
488  */
489  struct AGXMODEL_EXPORT dont_create_input_t {};
490  static dont_create_input_t dont_create_input;
491  RotationalActuator(agx::Constraint1DOF* constraint, dont_create_input_t);
492  RotationalActuator(agx::Constraint* constraint, ConstraintGeometry* constraintGeometry, dont_create_input_t);
493 
494  virtual ~RotationalActuator();
495 
496  void connectActuatorConnector();
497  void disconnectActuatorConnector();
498  void reconnectActuatorConnector();
500 
501  protected:
502  agxPowerLine::RotationalUnitRef m_inputShaft;
503  agxPowerLine::detail::RotationalActuatorConnectorRef m_actuatorConnector;
504 
505  agx::Bool m_useHighSpeedMode;
506  };
507 
509 
510 
511 
513  {
514  public:
515 
516  TranslationalActuator(agx::Constraint1DOF* constraint); // \todo How only allow translational constraints? Should we?
517  TranslationalActuator(agx::Constraint* constraint, ConstraintGeometry* constraintGeometry);
518 
519  agxPowerLine::TranslationalUnit* getInputRod();
520 
521 
522  // Called by the rest of the power line framework.
523  public:
524  virtual void getConnectableDimensionTypes(
526  agxPowerLine::Side side) const override;
527 
531  virtual agxPowerLine::DimensionAndSide getConnectableDimension(
533  agxPowerLine::Side side) override;
534 
538  virtual agx::Real calculateRelativeGradient() const override;
539 
540  virtual agx::Vec3 calculateWorldDirection(
541  Side side,
542  agxPowerLine::PhysicalDimension::Type dimensionType) const override;
543 
544  virtual agx::Vec3 calculateLocalDirection(Side side, int dimensionType) const override;
545 
549  virtual bool store(agxStream::StorageStream& str) const override;
550 
554  virtual bool restore(agxStream::StorageStream& str) override;
555 
557 
558  protected:
560 
562  static dont_create_input_t dont_create_input;
563 
564  TranslationalActuator(agx::Constraint1DOF* constraint, dont_create_input_t);
566  agx::Constraint* constraint, agxPowerLine::ConstraintGeometry* constraintGeometry, dont_create_input_t);
567 
568  virtual ~TranslationalActuator();
569 
570  void initialize();
571 
572  void connectActuatorConnector();
573 
574  private:
576  agxPowerLine::detail::TranslationalActuatorConnectorRef m_actuatorConnector;
577  };
578 
580 
581 
582 }
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
static dont_create_input_t dont_create_input
Definition: Actuator1DOF.h:562
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...
A rotational unit has one degree of freedom.
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
Observer that not only sets the Constraint pointer to nullptr on object deletion, but also informs th...
Definition: Actuator1DOF.h:346
An Actuator that operates on Constraint1DOF constraints.
Definition: Actuator1DOF.h:275
Pure virtual class.
Definition: Unit.h:72
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
ConstraintGeometry for any type of constraint that has a BasicControllerConstraint along the axis tha...
Definition: Actuator1DOF.h:187
The base class for a constraint.
Definition: Constraint.h:88
agx::Vec3 getWorldPosition2() const
Definition: Actuator1DOF.h:78
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:673
ConstraintGeometry for 1-DOF constraints.
Definition: Actuator1DOF.h:240
agx::ref_ptr< TranslationalActuator > TranslationalActuatorRef
Definition: Actuator1DOF.h:579
Basic data holder class for "angle based" (secondary) constraints.
agxPowerLine contains a collection of connected components that transport power across a system...
Definition: MotorUnit.h:23
virtual agx::RangeReal getAngleRange() const
Get the range of allowed angles.
Definition: Actuator1DOF.h:149
Base class providing referencing counted objects.
Definition: Referenced.h:119
Templated vector class.
Definition: Vector.h:52
uint32_t UInt
Definition: Integer.h:34
Base class for constraint angle based elementary constraints (secondary constraints).
agx::Vec3 getCmToPosition2() const
Definition: Actuator1DOF.h:126
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::Vec3 getCmToPosition1() const
Definition: Actuator1DOF.h:117
ConstraintObserver m_constraintObserver
Definition: Actuator1DOF.h:360
ConstraintGeometryRef m_constraintGeometry
Definition: Actuator1DOF.h:361
Description of how an Actuator is allowed to apply forces and torques on the body or bodies attached ...
Definition: Actuator1DOF.h:46
virtual bool restore(agxStream::StorageStream &str) override
Restores internal data from stream.
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
#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
agx::Vec3 getWorldDirection1() const
Definition: Actuator1DOF.h:93
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
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
virtual bool store(agxStream::StorageStream &str) const override
Stores internal data into stream.
std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > DimensionAndSide
#define AGXMODEL_EXPORT
double Real
Definition: Real.h:42
agx::Vec3 getWorldDirection2() const
Definition: Actuator1DOF.h:102
agx::Vec3 getWorldPosition1() const
Definition: Actuator1DOF.h:69
Real getAngle(const Vec3 &a, const Vec3 &b, const Vec3 &c)
a and b should be orthogonal
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::observer_ptr< Constraint > ConstraintObserver
Definition: Constraint.h:53