AGX Dynamics  2.35.0.1
Action.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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( EmitterAction );
52  AGX_DECLARE_POINTER_TYPES(EventSensorAction);
53 
54 
57 
103  class AGXPHYSICS_EXPORT Action : public agx::Referenced, public agxStream::Serializable
104  {
105  public:
106  /* A bunch of static factory methods. */
107 
109  static SetEnableConstraintAction* setEnableConstraint(agx::Real time, agx::Constraint* constraint, bool enable);
110 
117  static SetComplianceConstraintAction* setCompliance(agx::Real time, agx::Constraint* constraint, agx::Real newCompliance, agx::Int dof);
118  static SetDampingConstraintAction* setDamping(agx::Real time, agx::Constraint* constraint, agx::Real newDamping, agx::Int dof);
119  static SecondaryConstraintAction* enableMotor(agx::Real time, agx::Constraint1DOF* constraint, bool enable);
120  static SecondaryConstraintAction* enableMotor(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, bool enable);
121  static SecondaryConstraintAction* setMotorSpeed(agx::Real time, agx::Constraint1DOF* constraint, agx::Real speed);
122  static SecondaryConstraintAction* setMotorSpeed(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real speed);
123  static SecondaryConstraintAction* setMotorMinForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
124  static SecondaryConstraintAction* setMotorMinForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
125  static SecondaryConstraintAction* setMotorMaxForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
126  static SecondaryConstraintAction* setMotorMaxForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
127  static SecondaryConstraintAction* setMotorCompliance(agx::Real time, agx::Constraint1DOF* constraint, agx::Real compliance);
128  static SecondaryConstraintAction* setMotorCompliance(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real compliance);
129  static SecondaryConstraintAction* setMotorDamping(agx::Real time, agx::Constraint1DOF* constraint, agx::Real damping);
130  static SecondaryConstraintAction* setMotorDamping(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real damping);
131  static SecondaryConstraintAction* enableRange(agx::Real time, agx::Constraint1DOF* constraint, bool enable);
132  static SecondaryConstraintAction* enableRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, bool enable);
133  static SecondaryConstraintAction* setRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real lower, agx::Real upper);
134  static SecondaryConstraintAction* setRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real lower, agx::Real upper);
135  static SecondaryConstraintAction* setRangeMinRange(agx::Real, agx::Constraint1DOF* constraint, agx::Real limit);
136  static SecondaryConstraintAction* setRangeMinRange(agx::Real, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real limit);
137  static SecondaryConstraintAction* setRangeMaxRange(agx::Real, agx::Constraint1DOF* constraint, agx::Real limit);
138  static SecondaryConstraintAction* setRangeMaxRange(agx::Real, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real limit);
139  static SecondaryConstraintAction* setRangeMinForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
140  static SecondaryConstraintAction* setRangeMinForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
141  static SecondaryConstraintAction* setRangeMaxForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
142  static SecondaryConstraintAction* setRangeMaxForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
143  static SecondaryConstraintAction* setRangeCompliance(agx::Real time, agx::Constraint1DOF* constraint, agx::Real compliance);
144  static SecondaryConstraintAction* setRangeCompliance(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real compliance);
145  static SecondaryConstraintAction* setRangeDamping(agx::Real time, agx::Constraint1DOF* constraint, agx::Real damping);
146  static SecondaryConstraintAction* setRangeDamping(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real damping);
147  static SecondaryConstraintAction* enableLock(agx::Real time, agx::Constraint1DOF* constraint, bool enable);
148  static SecondaryConstraintAction* enableLock(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, bool enable);
149  static SecondaryConstraintAction* setLockMinForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
150  static SecondaryConstraintAction* setLockMinForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
151  static SecondaryConstraintAction* setLockMaxForceRange(agx::Real time, agx::Constraint1DOF* constraint, agx::Real force);
152  static SecondaryConstraintAction* setLockMaxForceRange(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real force);
153  static SecondaryConstraintAction* setLockPosition(agx::Real time, agx::Constraint1DOF* constraint, agx::Real position);
154  static SecondaryConstraintAction* setLockPosition(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real position);
155  static SecondaryConstraintAction* setLockCompliance(agx::Real time, agx::Constraint1DOF* constraint, agx::Real compliance);
156  static SecondaryConstraintAction* setLockCompliance(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real compliance);
157  static SecondaryConstraintAction* setLockDamping(agx::Real time, agx::Constraint1DOF* constraint, agx::Real damping);
158  static SecondaryConstraintAction* setLockDamping(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real damping);
159 
160  static SecondaryConstraintAction* setLockPositionToCurrent(agx::Real time, agx::Constraint1DOF* constraint);
161  static SecondaryConstraintAction* setLockPositionToCurrent(agx::Real time, agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof);
162 
163  static BodyAction* setEnableBody(agx::Real time, agx::RigidBody* body, bool enable);
164  static BodyAction* setBodyVelocity(agx::Real time, agx::RigidBody* body, agx::Vec3 velocity);
165 
166  static ParticleEmitterAction* setEnableParticleEmitter( agx::Real time, agx::ParticleEmitter* emitter, bool enable );
167  static ParticleEmitterAction* setParticleEmitterQuantityFlowRate( agx::Real time, agx::ParticleEmitter* emitter, agx::Real flowrate );
168  static EmitterAction* setEnableEmitter( agx::Real time, agx::Emitter* emitter, bool enable );
169  static EmitterAction* setEmitterQuantityFlowRate( agx::Real time, agx::Emitter* emitter, agx::Real flowrate );
170  static EventSensorAction* setEnableEventSensor(agx::Real time, agxControl::EventSensor* sensor, bool enable);
171 
173  agx::Real getTime() const;
174 
181  void trigger(agx::Real currentTime);
182 
184  void trigger();
185 
187  ActionImplementation* getImplementation();
188  const ActionImplementation* getImplementation() const;
189 
190  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::Action );
191 
192 
193  protected:
195  Action();
196 
197 
198  Action(const agx::String& target, const agx::String& operation, ActionImplementation* implementation);
199 
200  const agx::String& getTargetType() const;
201  const agx::String& getOperationType() const;
202 
203  friend class agxControl::Operation;
204 
209  void swapImplementation(Action* other);
210 
211 
212  // Each Action target type, the classes that an Action can manipulate, has a
213  // string ID used during store/restore operations.
214  static const agx::String& getConstraintActionId();
215  static const agx::String& getSecondaryConstraintActionId();
216  static const agx::String& getSetPositionFromCurrentConstraintActionId();
217  static const agx::String& getBodyActionId();
218  static const agx::String& getGeometryActionId();
219  static const agx::String& getVoidActionId();
220  static const agx::String& getParticleEmitterActionId();
221  static const agx::String& getEmitterActionId();
222  static const agx::String& getEventSensorActionId();
223 
224  // Each operation that an Action can perform has a string ID used during store/
225  // restore operations.
226  static const agx::String& getEnableOperationId();
227  static const agx::String& getFlowRateOperationId();
228  static const agx::String& getComplianceOperationId();
229  static const agx::String& getDampingOperationId();
230  static const agx::String& getSpeedOperationId();
231 
232  static const agx::String& getRangeOperationId();
233  static const agx::String& getRangeMinOperationId();
234  static const agx::String& getRangeMaxOperationId();
235 
236  static const agx::String& getForceRangeMinOperationId();
237  static const agx::String& getForceRangeMaxOperationId();
238 
239  static const agx::String& getPositionOperationId();
240  static const agx::String& getVelocityOperationId();
241 
242  static const agx::String& getVoidOperationId();
243 
244  protected:
245  virtual ~Action();
246 
247 
248  protected:
249  ActionImplementationRef m_implementation;
250 
251  private:
252  agx::String m_targetType;
253  agx::String m_operationType;
254  };
255 
256 
261  class AGXPHYSICS_EXPORT ConstraintAction : public agxControl::Action
262  {
263  public:
265  agx::Constraint* getConstraint();
266 
267  public:
269  ConstraintAction() {}
270  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::ConstraintAction );
271 
272  protected:
273  virtual ~ConstraintAction();
274 
275  friend class Action;
276  ConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
277 
278  private:
279  agx::ConstraintRef m_constraint;
280  };
281 
282 
288  class AGXPHYSICS_EXPORT SetComplianceConstraintAction : public agxControl::ConstraintAction
289  {
290  public:
291  agx::Real getCompliance() const;
292  void setCompliance(agx::Real newCompliance);
293  void setCompliance(agx::Real newCompliance, int dof);
294 
295  Callback2ActionImplementation<agx::Real, int>* getTypedImplementation();
296  const Callback2ActionImplementation<agx::Real, int>* getTypedImplementation() const;
297 
298  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetComplianceConstraintAction );
299  SetComplianceConstraintAction() {}
300 
301  protected:
302  virtual ~SetComplianceConstraintAction() {}
303 
304  private:
305  friend class Action;
306  SetComplianceConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
307  };
308 
309 
310 
316  class AGXPHYSICS_EXPORT SetDampingConstraintAction : public agxControl::ConstraintAction
317  {
318  public:
319  agx::Real getDamping() const;
320  void setDamping(agx::Real newDamping);
321  void setDamping(agx::Real newDamping, int dof);
322 
323  Callback2ActionImplementation<agx::Real, int>* getTypedImplementation();
324  const Callback2ActionImplementation<agx::Real, int>* getTypedImplementation() const;
325 
326  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetDampingConstraintAction );
327  SetDampingConstraintAction() {}
328 
329  protected:
330  virtual ~SetDampingConstraintAction() {}
331 
332  private:
333  friend class Action;
334  SetDampingConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
335  };
336 
337 
343  class AGXPHYSICS_EXPORT SetEnableConstraintAction : public agxControl::ConstraintAction
344  {
345  public:
346  bool getEnabling() const;
347  void setEnabling(bool enable);
348 
349  Callback1ActionImplementation<bool>* getTypedImplementation();
350  const Callback1ActionImplementation<bool>* getTypedImplementation() const;
351 
352  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetEnableConstraintAction );
353  SetEnableConstraintAction() {}
354 
355  protected:
356  virtual ~SetEnableConstraintAction();
357 
358  private:
359  friend class Action;
360  SetEnableConstraintAction(agx::Constraint* constraint, const agx::String& operation, ActionImplementation* implementation);
361  };
362 
363 
364 
372  class AGXPHYSICS_EXPORT SecondaryConstraintAction : public agxControl::Action
373  {
374  public:
376  agx::Constraint* getConstraint();
377 
378  public:
380  SecondaryConstraintAction() {}
381  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SecondaryConstraintAction );
382 
383  protected:
384  ~SecondaryConstraintAction();
385 
386  friend class Action;
387  SecondaryConstraintAction(agx::Constraint* constraint, const agx::String& operation, const agx::String& secondaryTarget, ActionImplementation* implementation);
388 
389  // The list of secondary constraint targets that a SecondaryConstraintAction can operate on.
390  static const agx::String& getMotorId();
391  static const agx::String& getMotor1Id();
392  static const agx::String& getMotor2Id();
394  static const agx::String& getMotorId(agx::Constraint2DOF::DOF dof);
395  static const agx::String& getRangeId();
396  static const agx::String& getRange1Id();
397  static const agx::String& getRange2Id();
399  static const agx::String& getRangeId(agx::Constraint2DOF::DOF dof);
400  static const agx::String& getLockId();
401  static const agx::String& getLock1Id();
402  static const agx::String& getLock2Id();
404  static const agx::String& getLockId(agx::Constraint2DOF::DOF dof);
405  static const agx::String& getErrorId();
406 
408  const agx::String& getSecondaryTarget() const;
409 
410  void restoreEnableActionImplementation();
411  void restoreSpeedOperation();
412  void restoreRangeOperation();
413  void restoreRangeMinOperation();
414  void restoreRangeMaxOperation();
415  void restoreForceRangeMinOperation();
416  void restoreForceRangeMaxOperation();
417  void restoreComplianceOperation();
418  void restoreDampingOperation();
419  void restorePositionOperation();
420 
421  protected:
422  agx::ConstraintRef m_constraint;
423 
424  private:
425  agx::String m_secondaryTarget;
426  };
427 
428 
433  class AGXPHYSICS_EXPORT BodyAction : public agxControl::Action
434  {
435  public:
437  agx::RigidBody* getRigidBody();
438 
439  public:
441  BodyAction();
442  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::BodyAction );
443 
444  protected:
445  friend class Action;
446  BodyAction(agx::RigidBody* body, const agx::String& operation, ActionImplementation* implementation);
447 
448  private:
449  agx::RigidBodyRef m_body;
450  };
451 
456  class AGXPHYSICS_EXPORT ParticleEmitterAction : public agxControl::Action
457  {
458  public:
460  agx::ParticleEmitter* getParticleEmitter();
461 
462  public:
464  ParticleEmitterAction();
465  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::ParticleEmitterAction );
466 
467  protected:
468  friend class Action;
469  ParticleEmitterAction(agx::ParticleEmitter* emitter, const agx::String& operation, ActionImplementation* implementation);
470 
471  private:
472  agx::ParticleEmitterRef m_emitter;
473  };
474 
479  class AGXPHYSICS_EXPORT EmitterAction : public agxControl::Action
480  {
481  public:
483  agx::Emitter* getEmitter();
484 
485  public:
487  EmitterAction();
488  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::EmitterAction );
489 
490  protected:
491  friend class Action;
492  EmitterAction( agx::Emitter* emitter, const agx::String& operation, ActionImplementation* implementation );
493 
494  private:
495  agx::EmitterRef m_emitter;
496  };
497 
502  class AGXPHYSICS_EXPORT EventSensorAction : public agxControl::Action
503  {
504  public:
506  EventSensor* getEventSensor();
507 
508  public:
510  EventSensorAction();
511  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::EventSensorAction );
512 
513  protected:
514  friend class Action;
515  EventSensorAction(EventSensor* sensor, const agx::String& operation, ActionImplementation* implementation);
516 
517  private:
518  EventSensor * m_sensor;
519  };
520 
527  class AGXPHYSICS_EXPORT CallbackAction : public agxControl::Action
528  {
529  public:
530  CallbackAction(ActionImplementation* implementation);
531 
532  public:
534  CallbackAction() {}
535  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::CallbackAction );
536  };
537 
538  class AGXPHYSICS_EXPORT SetLockPositionToCurrentConstraintAction : public agxControl::SecondaryConstraintAction
539  {
540  public:
541  CallbackActionImplementation* getTypedImplementation();
542  const CallbackActionImplementation* getTypedImplementation() const;
543 
544  AGXSTREAM_DECLARE_SERIALIZABLE( agxControl::SetLockPositionToCurrentConstraintAction );
545  SetLockPositionToCurrentConstraintAction();
546 
547  void executeAction(agx::Real time);
548  protected:
549  virtual ~SetLockPositionToCurrentConstraintAction();
550 
551  private:
552  friend class Action;
553  SetLockPositionToCurrentConstraintAction(agx::Constraint1DOF* constraint, agx::Real time);
554  SetLockPositionToCurrentConstraintAction(agx::Constraint2DOF* constraint, agx::Constraint2DOF::DOF dof, agx::Real time);
555 
557  };
558 }
559 
560 // Include guard
561 #endif
562 
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
This is a sensor class that can be attached to an geometry in the simulation.
Definition: EventSensor.h:48
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:677
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:762
DOF
Specifies a selected degree of freedom.
Definition: Constraint.h:772
The base class for a constraint.
Definition: Constraint.h:89
Spawns new bodys inside a given volume.
Definition: Emitter.h:45
Spawns new particles inside a given volume given to the Emitter.
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
This namespace contains general operation and action classes which can be used to control a agxSDK::S...
AGXFMI_EXPORT InputVariable_Real * setLockMaxForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setCompliance(agx::Constraint *constraint)
AGXFMI_EXPORT InputVariable_Real * setMotorCompliance(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeCompliance(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeMinRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setMotorMaxForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setMotorSpeed(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setDamping(agx::Constraint *constraint)
AGXFMI_EXPORT InputVariable_Real * setLockMinForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setLockPosition(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeMaxForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setLockCompliance(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeMinForceRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setRangeMaxRange(agx::Constraint1DOF *constraint)
AGXFMI_EXPORT InputVariable_Real * setMotorMinForceRange(agx::Constraint1DOF *constraint)
AGXTERRAIN_EXPORT agx::Real & currentTime()
int32_t Int
Definition: Integer.h:35
double Real
Definition: Real.h:42