AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Action.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
20 
21 #ifndef AGXCONTROL_ACTION_H
22 #define AGXCONTROL_ACTION_H
23 
24 #include <agx/config.h>
25 
26 #include <agx/Constraint.h>
27 #include <agx/RigidBody.h>
28 #include <agx/ParticleEmitter.h>
29 #include <agx/Referenced.h>
30 #include <agxStream/Serializable.h>
31 
33 
34 
35 namespace agxControl
36 {
37  class EventSensor;
38 
39  class Operation;
40 
41  // These are the subclasses of Action that can be returned by the factory methods.
42  AGX_DECLARE_POINTER_TYPES(ConstraintAction);
43  AGX_DECLARE_POINTER_TYPES(SetEnableConstraintAction);
44  AGX_DECLARE_POINTER_TYPES(SetComplianceConstraintAction);
45  AGX_DECLARE_POINTER_TYPES(SetDampingConstraintAction);
46  AGX_DECLARE_POINTER_TYPES(SetLockPositionToCurrentConstraintAction);
47 
48  AGX_DECLARE_POINTER_TYPES(SecondaryConstraintAction);
49  AGX_DECLARE_POINTER_TYPES(BodyAction);
50  AGX_DECLARE_POINTER_TYPES(ParticleEmitterAction);
51  AGX_DECLARE_POINTER_TYPES(EventSensorAction);
52 
53 
56 
102  class AGXPHYSICS_EXPORT Action : public agx::Referenced, public agxStream::Serializable
103  {
104  public:
105  /* A bunch of static factory methods. */
106 
108  static SetEnableConstraintAction* setEnableConstraint(agx::Real time, agx::Constraint* constraint, bool enable);
109 
116  static SetComplianceConstraintAction* setCompliance(agx::Real time, agx::Constraint* constraint, agx::Real newCompliance, agx::Int dof);
117  static SetDampingConstraintAction* setDamping(agx::Real time, agx::Constraint* constraint, agx::Real newDamping, agx::Int dof);
118  static SecondaryConstraintAction* enableMotor(agx::Real time, agx::Constraint1DOF* constraint, bool enable);
119  static SecondaryConstraintAction* enableMotor(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, bool enable);
120  static SecondaryConstraintAction* setMotorSpeed(agx::Real time, agx::Constraint1DOF* constraint, agx::Real speed);
121  static SecondaryConstraintAction* setMotorSpeed(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real speed);
122  static SecondaryConstraintAction* setMotorMinForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
123  static SecondaryConstraintAction* setMotorMinForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
124  static SecondaryConstraintAction* setMotorMaxForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
125  static SecondaryConstraintAction* setMotorMaxForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
126  static SecondaryConstraintAction* setMotorCompliance(agx::Real time, agx::Constraint1DOF* constraint, agx::Real compliance);
127  static SecondaryConstraintAction* setMotorCompliance(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real compliance);
128  static SecondaryConstraintAction* setMotorDamping(agx::Real time, agx::Constraint1DOF* constraint, agx::Real damping);
129  static SecondaryConstraintAction* setMotorDamping(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real damping);
130  static SecondaryConstraintAction* enableRange(agx::Real time, agx::Constraint1DOF* constraint, bool enable);
131  static SecondaryConstraintAction* enableRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, bool enable);
132  static SecondaryConstraintAction* setRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real lower, agx::Real upper);
133  static SecondaryConstraintAction* setRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real lower, agx::Real upper);
134  static SecondaryConstraintAction* setRangeMinRange(agx::Real, agx::Constraint1DOF* constraint, agx::Real limit);
135  static SecondaryConstraintAction* setRangeMinRange(agx::Real, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real limit);
136  static SecondaryConstraintAction* setRangeMaxRange(agx::Real, agx::Constraint1DOF* constraint, agx::Real limit);
137  static SecondaryConstraintAction* setRangeMaxRange(agx::Real, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real limit);
138  static SecondaryConstraintAction* setRangeMinForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
139  static SecondaryConstraintAction* setRangeMinForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
140  static SecondaryConstraintAction* setRangeMaxForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
141  static SecondaryConstraintAction* setRangeMaxForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
142  static SecondaryConstraintAction* setRangeCompliance(agx::Real time, agx::Constraint1DOF* constraint, agx::Real compliance);
143  static SecondaryConstraintAction* setRangeCompliance(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real compliance);
144  static SecondaryConstraintAction* setRangeDamping(agx::Real time, agx::Constraint1DOF* constraint, agx::Real damping);
145  static SecondaryConstraintAction* setRangeDamping(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real damping);
146  static SecondaryConstraintAction* enableLock(agx::Real time, agx::Constraint1DOF* constraint, bool enable);
147  static SecondaryConstraintAction* enableLock(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, bool enable);
148  static SecondaryConstraintAction* setLockMinForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
149  static SecondaryConstraintAction* setLockMinForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
150  static SecondaryConstraintAction* setLockMaxForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
151  static SecondaryConstraintAction* setLockMaxForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
152  static SecondaryConstraintAction* setLockPosition(agx::Real time, agx::Constraint1DOF* constraint, agx::Real position);
153  static SecondaryConstraintAction* setLockPosition(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real position);
154  static SecondaryConstraintAction* setLockCompliance(agx::Real time, agx::Constraint1DOF* constraint, agx::Real compliance);
155  static SecondaryConstraintAction* setLockCompliance(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real compliance);
156  static SecondaryConstraintAction* setLockDamping(agx::Real time, agx::Constraint1DOF* constraint, agx::Real damping);
157  static SecondaryConstraintAction* setLockDamping(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real damping);
158 
159  static SecondaryConstraintAction* setLockPositionToCurrent(agx::Real time, agx::Constraint1DOF* constraint);
160  static SecondaryConstraintAction* setLockPositionToCurrent(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof);
161 
162  static BodyAction* setEnableBody(agx::Real time, agx::RigidBody* body, bool enable);
163  static BodyAction* setBodyVelocity(agx::Real time, agx::RigidBody* body, agx::Vec3 velocity);
164 
165  static ParticleEmitterAction* setEnableParticleEmitter(agx::Real time, agx::ParticleEmitter* emitter, bool enable);
166  static ParticleEmitterAction* setParticleEmitterQuantityFlowRate(agx::Real time, agx::ParticleEmitter* emitter, agx::Real flowrate);
167  static EventSensorAction* setEnableEventSensor(agx::Real time, agxControl::EventSensor* sensor, bool enable);
168 
170  agx::Real getTime() const;
171 
178  void trigger(agx::Real currentTime);
179 
181  void trigger();
182 
184  ActionImplementation* getImplementation();
185  const ActionImplementation* getImplementation() const;
186 
187  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::Action );
188 
189 
190  protected:
192  Action();
193 
194 
195  Action(const agx::String& target, const agx::String& operation, ActionImplementation* implementation);
196 
197  const agx::String& getTargetType() const;
198  const agx::String& getOperationType() const;
199 
200  friend class agxControl::Operation;
201 
206  void swapImplementation(Action* other);
207 
208 
209  // Each Action target type, the classes that an Action can manipulate, has a
210  // string ID used during store/restore operations.
211  static const agx::String& getConstraintActionId();
212  static const agx::String& getSecondaryConstraintActionId();
213  static const agx::String& getSetPositionFromCurrentConstraintActionId();
214  static const agx::String& getBodyActionId();
215  static const agx::String& getGeometryActionId();
216  static const agx::String& getVoidActionId();
217  static const agx::String& getParticleEmitterActionId();
218  static const agx::String& getEventSensorActionId();
219 
220  // Each operation that an Action can perform has a string ID used during store/
221  // restore operations.
222  static const agx::String& getEnableOperationId();
223  static const agx::String& getFlowRateOperationId();
224  static const agx::String& getComplianceOperationId();
225  static const agx::String& getDampingOperationId();
226  static const agx::String& getSpeedOperationId();
227 
228  static const agx::String& getRangeOperationId();
229  static const agx::String& getRangeMinOperationId();
230  static const agx::String& getRangeMaxOperationId();
231 
232  static const agx::String& getForceRangeMinOperationId();
233  static const agx::String& getForceRangeMaxOperationId();
234 
235  static const agx::String& getPositionOperationId();
236  static const agx::String& getVelocityOperationId();
237 
238  static const agx::String& getVoidOperationId();
239 
240  protected:
241  virtual ~Action();
242 
243 
244  protected:
245  ActionImplementationRef m_implementation;
246 
247  private:
248  agx::String m_targetType;
249  agx::String m_operationType;
250  };
251 
252 
257  class AGXPHYSICS_EXPORT ConstraintAction : public agxControl::Action
258  {
259  public:
261  agx::Constraint* getConstraint();
262 
263  public:
265  ConstraintAction() {}
266  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::ConstraintAction );
267 
268  protected:
269  virtual ~ConstraintAction();
270 
271  friend class Action;
272  ConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
273 
274  private:
275  agx::ConstraintRef m_constraint;
276  };
277 
278 
284  class AGXPHYSICS_EXPORT SetComplianceConstraintAction : public agxControl::ConstraintAction
285  {
286  public:
287  agx::Real getCompliance() const;
288  void setCompliance(agx::Real newCompliance);
289  void setCompliance(agx::Real newCompliance, int dof);
290 
291  Callback2ActionImplementation<agx::Real, int>* getTypedImplementation();
292  const Callback2ActionImplementation<agx::Real, int>* getTypedImplementation() const;
293 
294  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetComplianceConstraintAction );
295  SetComplianceConstraintAction() {}
296 
297  protected:
298  virtual ~SetComplianceConstraintAction() {}
299 
300  private:
301  friend class Action;
302  SetComplianceConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
303  };
304 
305 
306 
312  class AGXPHYSICS_EXPORT SetDampingConstraintAction : public agxControl::ConstraintAction
313  {
314  public:
315  agx::Real getDamping() const;
316  void setDamping(agx::Real newDamping);
317  void setDamping(agx::Real newDamping, int dof);
318 
319  Callback2ActionImplementation<agx::Real, int>* getTypedImplementation();
320  const Callback2ActionImplementation<agx::Real, int>* getTypedImplementation() const;
321 
322  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetDampingConstraintAction );
323  SetDampingConstraintAction() {}
324 
325  protected:
326  virtual ~SetDampingConstraintAction() {}
327 
328  private:
329  friend class Action;
330  SetDampingConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
331  };
332 
333 
339  class AGXPHYSICS_EXPORT SetEnableConstraintAction : public agxControl::ConstraintAction
340  {
341  public:
342  bool getEnabling() const;
343  void setEnabling(bool enable);
344 
345  Callback1ActionImplementation<bool>* getTypedImplementation();
346  const Callback1ActionImplementation<bool>* getTypedImplementation() const;
347 
348  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetEnableConstraintAction );
349  SetEnableConstraintAction() {}
350 
351  protected:
352  virtual ~SetEnableConstraintAction();
353 
354  private:
355  friend class Action;
356  SetEnableConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
357  };
358 
359 
360 
368  class AGXPHYSICS_EXPORT SecondaryConstraintAction : public agxControl::Action
369  {
370  public:
372  agx::Constraint* getConstraint();
373 
374  public:
376  SecondaryConstraintAction() {}
377  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SecondaryConstraintAction );
378 
379  protected:
380  ~SecondaryConstraintAction();
381 
382  friend class Action;
383  SecondaryConstraintAction(agx::Constraint* constraint, const agx::String& operation, const agx::String& secondaryTarget, ActionImplementation* implementation);
384 
385  // The list of secondary constraint targets that a SecondaryConstraintAction can operate on.
386  static const agx::String& getMotorId();
387  static const agx::String& getMotor1Id();
388  static const agx::String& getMotor2Id();
390  static const agx::String& getMotorId(agx::Constraint2DOF::DOF dof);
391  static const agx::String& getRangeId();
392  static const agx::String& getRange1Id();
393  static const agx::String& getRange2Id();
395  static const agx::String& getRangeId(agx::Constraint2DOF::DOF dof);
396  static const agx::String& getLockId();
397  static const agx::String& getLock1Id();
398  static const agx::String& getLock2Id();
400  static const agx::String& getLockId(agx::Constraint2DOF::DOF dof);
401  static const agx::String& getErrorId();
402 
404  const agx::String& getSecondaryTarget() const;
405 
406  void restoreEnableActionImplementation();
407  void restoreSpeedOperation();
408  void restoreRangeOperation();
409  void restoreRangeMinOperation();
410  void restoreRangeMaxOperation();
411  void restoreForceRangeMinOperation();
412  void restoreForceRangeMaxOperation();
413  void restoreComplianceOperation();
414  void restoreDampingOperation();
415  void restorePositionOperation();
416 
417  protected:
418  agx::ConstraintRef m_constraint;
419 
420  private:
421  agx::String m_secondaryTarget;
422  };
423 
424 
429  class AGXPHYSICS_EXPORT BodyAction : public agxControl::Action
430  {
431  public:
433  agx::RigidBody* getRigidBody();
434 
435  public:
437  BodyAction();
438  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::BodyAction );
439 
440  protected:
441  friend class Action;
442  BodyAction(agx::RigidBody* body, const agx::String& operation, ActionImplementation* implementation);
443 
444  private:
445  agx::RigidBodyRef m_body;
446  };
447 
452  class AGXPHYSICS_EXPORT ParticleEmitterAction : public agxControl::Action
453  {
454  public:
456  agx::ParticleEmitter* getParticleEmitter();
457 
458  public:
460  ParticleEmitterAction();
461  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::ParticleEmitterAction );
462 
463  protected:
464  friend class Action;
465  ParticleEmitterAction(agx::ParticleEmitter* emitter, const agx::String& operation, ActionImplementation* implementation);
466 
467  private:
468  agx::ParticleEmitterRef m_emitter;
469  };
470 
475  class AGXPHYSICS_EXPORT EventSensorAction : public agxControl::Action
476  {
477  public:
479  EventSensor* getEventSensor();
480 
481  public:
483  EventSensorAction();
484  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::EventSensorAction );
485 
486  protected:
487  friend class Action;
488  EventSensorAction(EventSensor* sensor, const agx::String& operation, ActionImplementation* implementation);
489 
490  private:
491  EventSensor * m_sensor;
492  };
493 
500  class AGXPHYSICS_EXPORT CallbackAction : public agxControl::Action
501  {
502  public:
503  CallbackAction(ActionImplementation* implementation);
504 
505  public:
507  CallbackAction() {}
508  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::CallbackAction );
509  };
510 
511  class AGXPHYSICS_EXPORT SetLockPositionToCurrentConstraintAction : public agxControl::SecondaryConstraintAction
512  {
513  public:
514  CallbackActionImplementation* getTypedImplementation();
515  const CallbackActionImplementation* getTypedImplementation() const;
516 
517  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetLockPositionToCurrentConstraintAction );
518  SetLockPositionToCurrentConstraintAction();
519 
520  void executeAction(agx::Real time);
521  protected:
522  virtual ~SetLockPositionToCurrentConstraintAction();
523 
524  private:
525  friend class Action;
526  SetLockPositionToCurrentConstraintAction(agx::Constraint1DOF* constraint, agx::Real time);
527  SetLockPositionToCurrentConstraintAction(agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real time);
528 
530  };
531 }
532 
533 // Include guard
534 #endif
535 
AGXFMI_EXPORT InputVariable_Real * setMotorMaxForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setLockMinForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setCompliance(agx::Constraint *constraint)
AGXFMI_EXPORT InputVariable_Real * setLockPosition(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeCompliance(agx::Constraint1DOF *constraint)
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:759
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:86
int32_t Int
Definition: Integer.h:35
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:674
AGXFMI_EXPORT InputVariable_Real * setRangeMinRange(agx::Constraint1DOF *constraint)
This is a sensor class that can be attached to an geometry in the simulation.
Definition: EventSensor.h:47
AGXFMI_EXPORT InputVariable_Real * setMotorCompliance(agx::Constraint1DOF *constraint)
Base class providing referencing counted objects.
Definition: Referenced.h:113
DOF
Specifies a selected degree of freedom.
Definition: Constraint.h:769
AGXFMI_EXPORT InputVariable_Real * setRangeMaxForceRange(agx::Constraint1DOF *constraint)
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
AGXFMI_EXPORT InputVariable_Real * setMotorSpeed(agx::Constraint1DOF *constraint)
AGXTERRAIN_EXPORT agx::Real & currentTime()
AGXFMI_EXPORT InputVariable_Real * setLockCompliance(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeMinForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setDamping(agx::Constraint *constraint)
#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:206
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Spawns new particles inside a given volume.
AGX_DECLARE_VECTOR_TYPES(EventSensor)
double Real
Definition: Real.h:42
AGXFMI_EXPORT InputVariable_Real * setRangeMaxRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setLockMaxForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setMotorMinForceRange(agx::Constraint1DOF *constraint)