AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
SensorOperations.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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#ifndef AGXCONTROL_SENSOROPERATIONS_H
18#define AGXCONTROL_SENSOROPERATIONS_H
19
20#include <fstream>
21#include <agx/Date.h>
22#include <agx/String.h>
23#include <agxData/Track.h>
27#include <agx/Journal.h>
28#include <agxRender/Color.h>
29
30/*
31This file defines some example sensor operations
32*/
33namespace agxControl
34{
37 {
38 public:
39 RemoveRigidBody(const agx::Name& name = agx::Name(), bool onlyRemoveEmittedBodies = false);
40
42
44
45 protected:
47
48 protected:
50 };
51
54 {
55 public:
57
59 agxSDK::Simulation* /*simulation*/,
60 agx::Physics::ParticleGeometryContactInstance contact,
61 agx::Physics::ParticleData& particleData,
62 agx::Physics::GeometryData& /*geometryData*/,
63 agxControl::EventSensor* /*sensor*/) override;
64
66
67 protected:
69
70 };
71
74 {
75 public:
77
78
79 virtual void triggerEvent(const agx::TimeStamp& /*t*/, agxSDK::Simulation * /*simulation*/, agxCollide::GeometryContact * /*cd*/, agxControl::EventSensor* /*sensor*/) override
80 {
81 // Tag this operation as executed
82 m_isExecuted = true;
83 }
84
85 virtual void triggerParticleEvent(const agx::TimeStamp& /*t*/,
86 agxSDK::Simulation* /*simulation*/,
87 agx::Physics::ParticleGeometryContactInstance /*contact*/,
88 agx::Physics::ParticleData& /*particleData*/,
89 agx::Physics::GeometryData& /*geometryData*/,
90 agxControl::EventSensor* /*sensor*/) override
91 {
92 m_isExecuted = true;
93 }
94
96
97 public:
98 bool isExecuted() { return m_isExecuted; }
99
100 void setIsExecuted(bool executed) { m_isExecuted = executed; }
101
102 protected:
104
105 protected:
106 virtual ~TagOperation();
107
108 };
109
112 {
113 private:
114
115 static agx::HashSet<agx::UInt32> s_coloredParticles;
116 static agx::TimeStamp s_lastTimeStep;
117
118 public:
119 ColorParticles(const agx::Name& name = agx::Name(), const agx::Vec3& color = agx::Vec3(0.5, 0.5, 0.5), bool mixColors = false);
120
122 agxSDK::Simulation* simulation,
123 agx::Physics::ParticleGeometryContactInstance contact,
124 agx::Physics::ParticleData& particleData,
125 agx::Physics::GeometryData& geometryData,
126 agxControl::EventSensor* sensor) override;
127
128 bool getEnableMixColors(){ return m_mixColors; }
129 void setEnableMixColors(bool mixColors){ m_mixColors = mixColors; }
130
132
133 public:
134 agx::Vec3& getColor(){ return m_color; }
135
136 protected:
139
140 protected:
142
143 };
144
147 {
148 public:
149
151 ParticleContactDumper(const agx::Name& name, const agx::Name& filepath, agx::UInt32 samplingStride = 1, bool exportOnce = false);
152
153 void createFileName(const agx::Name& filePath);
154
155 // This function appends a date stamp at the end of the filename
157
159 agxSDK::Simulation* /*simulation*/,
160 agx::Physics::ParticleGeometryContactInstance contact,
161 agx::Physics::ParticleData& particleData,
162 agx::Physics::GeometryData& /*geometryData*/,
163 agxControl::EventSensor* /*sensor*/) override;
164
165 agx::Name& getFilePath(){ return m_filepath; }
166
167 virtual void update(const agx::TimeStamp& t) override;
168
169 void postContactHandling(agxSDK::Simulation* simulation, EventSensor* sensor) override;
170
172
173 protected:
175 std::ofstream m_outStream;
183
184 protected:
186
187 };
188
189 // Switches the material of the particle in the supplied contact
191 {
192 public:
193
195 ReplaceParticleMaterialOperation(const agx::Name& name, const agx::Name& materialName);
196
198 agxSDK::Simulation* simulation,
199 agx::Physics::ParticleGeometryContactInstance contact,
200 agx::Physics::ParticleData& particleData,
201 agx::Physics::GeometryData& geometryData,
202 agxControl::EventSensor* sensor) override;
203
205 agxSDK::Simulation * simulation,
207 agxControl::EventSensor* sensor ) override;
208
210
211 void setMaterialName(const agx::String& material);
212 agx::Name getMaterialName();
213
215 // Variables
217 protected:
219
220 protected:
222
223 };
224
229
234
235
240 {
242 friend class RemoveParticles;
243 public:
244
247 {
249 UNFREEZE_PARTICLES
250 };
251
252 MakeParticleKinematicOperation(const agx::Name& name = agx::Name(), ParticleFreezeMode mode = FREEZE_PARTILCES);
253
255 agxSDK::Simulation* simulation,
256 agx::Physics::ParticleGeometryContactInstance contact,
257 agx::Physics::ParticleData& particleData,
258 agx::Physics::GeometryData& geometryData,
259 agxControl::EventSensor* sensor) override;
260
261 void triggerEvent( const agx::TimeStamp& /*t*/,
262 agxSDK::Simulation * simulation,
264 agxControl::EventSensor * sensor ) override;
265
267
268 protected:
270
272 // Variables
275 };
276
298
299
305 {
307 friend class RemoveParticles;
308 public:
309
311 agx::Real sleepSpeedThreshold = 1.0,
312 bool colorOnSleep = false,
313 agx::Vec4f sleepColor = agxRender::Color::Yellow() );
314
315 virtual void triggerParticleEvent( const agx::TimeStamp& t,
316 agxSDK::Simulation* simulation,
317 agx::Physics::ParticleGeometryContactInstance contact,
318 agx::Physics::ParticleData& particleData,
319 agx::Physics::GeometryData& geometryData,
320 agxControl::EventSensor* sensor ) override;
321
323
324 protected:
326
328 // Variables
333 };
334
339 {
340 public:
341
343 SetVelocityOperation(const agx::Name& name, const agx::Vec3& velocity, const agx::Vec3& angularVelocity, bool setInLocalFrame = false);
344
346 agxSDK::Simulation* simulation,
347 agx::Physics::ParticleGeometryContactInstance contact,
348 agx::Physics::ParticleData& particleData,
349 agx::Physics::GeometryData& geometryData,
350 agxControl::EventSensor* sensor) override;
351
352 virtual void triggerEvent(const agx::TimeStamp& t,
353 agxSDK::Simulation * simulation,
355 agxControl::EventSensor* sensor) override;
356
357 void setVelocity(const agx::Vec3& velocity);
358 const agx::Vec3& getVelocity() const;
359
360 void setAngularVelocity(const agx::Vec3& angularVelocity);
361 const agx::Vec3& getAngularVelocity() const;
362
364
365 protected:
367
369 // Variables
371 protected:
376 };
377
379 {
380 m_velocity = velocity;
381 }
382
387
389 {
390 m_angularVelocity = angularVelocity;
391 }
392
397
402 {
403 public:
404
406
408 agxSDK::Simulation* simulation,
409 agx::Physics::ParticleGeometryContactInstance contact,
410 agx::Physics::ParticleData& particleData,
411 agx::Physics::GeometryData& geometryData,
412 agxControl::EventSensor* sensor) override;
413
414 virtual void triggerEvent(const agx::TimeStamp& t,
415 agxSDK::Simulation * simulation,
417 agxControl::EventSensor* sensor) override;
418
419 virtual void update(const agx::TimeStamp& t) override;
420
421 agx::Physics::ParticlePtrVector getParticlesInContact() const;
422
424
425 protected:
427
428 protected:
430 };
431
433
438 {
439 public:
440
441 typedef std::pair<agx::TimeStamp, agx::Index> TimeParticleIdPair;
443
445 EventSensor * target,
446 agx::Real teleportTimeDilation = 0,
447 bool cloneTeleportation = false,
448 agx::Frame * sourceoffset = nullptr,
449 agx::Frame * targetoffset = nullptr);
450
451 void addNotification(EventSensor * sensor) override;
452
454 agxSDK::Simulation * simulation,
456 agxControl::EventSensor* sensor) override;
457
459 agxSDK::Simulation* /*simulation*/,
460 agx::Physics::ParticleGeometryContactInstance contact,
461 agx::Physics::ParticleData& particleData,
462 agx::Physics::GeometryData& /*geometryData*/,
463 agxControl::EventSensor* sensor) override;
464
465 void postContactHandling(agxSDK::Simulation *simulation, EventSensor * sensor) override;
466
468
469 protected:
471 void init();
472
474
476 // Variables
478 protected:
487 };
488}
489
490#endif
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
A contact between two geometries.
Definition Contacts.h:271
This operation changes the color of the particles given in the contact.
void setEnableMixColors(bool mixColors)
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
ColorParticles(const agx::Name &name=agx::Name(), const agx::Vec3 &color=agx::Vec3(0.5, 0.5, 0.5), bool mixColors=false)
This is a sensor class that can be attached to an geometry in the simulation.
Definition EventSensor.h:48
This operation applies a "kinematic state" to particles that collide with the sensor.
void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing contact information.
MakeParticleKinematicOperation(const agx::Name &name=agx::Name(), ParticleFreezeMode mode=FREEZE_PARTILCES)
ParticleFreezeMode
Enum describing what mode the operation should be in. If it should freeze or unfreeze particles.
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
This operation dumps particle contact information to a file.
virtual void update(const agx::TimeStamp &t) override
Used to update the sensor operation each time step, if they have time dependent components.
ParticleContactDumper(const agx::Name &name, const agx::Name &filepath, agx::UInt32 samplingStride=1, bool exportOnce=false)
void postContactHandling(agxSDK::Simulation *simulation, EventSensor *sensor) override
Post function that will be triggered for the event after all the contacts have handled in the operati...
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &, agxControl::EventSensor *) override
Triggers the sensor event by passing particle contact information.
agx::HashTable< agx::Index, agx::Bool > m_handledParticleIds
void createFileName(const agx::Name &filePath)
ParticleContactDumper(const agx::Name &name=agx::Name())
This operation applies a kinematic "sleep state" to particles inside the sensor that are under a spec...
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
ParticleKinematicSleepOperation(const agx::Name &name=agx::Name(), agx::Real sleepSpeedThreshold=1.0, bool colorOnSleep=false, agx::Vec4f sleepColor=agxRender::Color::Yellow())
This operations removes all the particles in the contact supplied by the sensor.
void triggerParticleEvent(const agx::TimeStamp &, agxSDK::Simulation *, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &, agxControl::EventSensor *) override
Triggers the sensor event by passing particle contact information.
RemoveParticles(const agx::Name &name=agx::Name())
This operation removes the rigid body given by the geometry in the contact supplied by the sensor.
void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing contact information.
RemoveRigidBody(const agx::Name &name=agx::Name(), bool onlyRemoveEmittedBodies=false)
ReplaceParticleMaterialOperation(const agx::Name &name=agx::Name())
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
ReplaceParticleMaterialOperation(const agx::Name &name, const agx::Name &materialName)
void triggerEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing contact information.
void setMaterialName(const agx::String &material)
This operation resets accumulated impact energy to a set value for particles inside the sensor if the...
void postContactHandling(agxSDK::Simulation *simulation, EventSensor *sensor) override
Post function that will be triggered for the event after all the contacts have handled in the operati...
ResetParticleContactEnergyOperation(const agx::Name &name=agx::Name(), agx::Real resetEnergy=0)
A specific type of sensor event that triggers a change in the simulation when activated by a contact.
This sensor operation class sets a speed to the object that collides with the sensor,...
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
const agx::Vec3 & getAngularVelocity() const
virtual void triggerEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing contact information.
SetVelocityOperation(const agx::Name &name, const agx::Vec3 &velocity, const agx::Vec3 &angularVelocity, bool setInLocalFrame=false)
void setAngularVelocity(const agx::Vec3 &angularVelocity)
const agx::Vec3 & getVelocity() const
SetVelocityOperation(const agx::Name &name=agx::Name())
void setVelocity(const agx::Vec3 &velocity)
This sensor operation class store particle id's of particles that are in contact with the sensor.
virtual void triggerEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing contact information.
StoreParticlesOperation(const agx::Name &name=agx::Name())
agx::Physics::ParticlePtrVector getParticlesInContact() const
agx::Physics::ParticlePtrVector m_particlesInContact
virtual void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &geometryData, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
virtual void update(const agx::TimeStamp &t) override
Used to update the sensor operation each time step, if they have time dependent components.
This operation can be used to know when a sensor has been activated by a contact.
TagOperation(const agx::Name &name=agx::Name())
virtual void triggerEvent(const agx::TimeStamp &, agxSDK::Simulation *, agxCollide::GeometryContact *, agxControl::EventSensor *) override
Triggers the sensor event by passing contact information.
void setIsExecuted(bool executed)
virtual void triggerParticleEvent(const agx::TimeStamp &, agxSDK::Simulation *, agx::Physics::ParticleGeometryContactInstance, agx::Physics::ParticleData &, agx::Physics::GeometryData &, agxControl::EventSensor *) override
Triggers the sensor event by passing particle contact information.
This sensor operation can teleport contacting particles to a target sensor geometry with arbitrary ti...
void triggerParticleEvent(const agx::TimeStamp &t, agxSDK::Simulation *, agx::Physics::ParticleGeometryContactInstance contact, agx::Physics::ParticleData &particleData, agx::Physics::GeometryData &, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing particle contact information.
void teleportParticles(const agx::TimeStamp &t, agxControl::EventSensor *sensor, agx::Physics::GranularBodySystem *system)
agx::HashSet< agx::UInt32 > m_previousContactingParticleIds
std::pair< agx::TimeStamp, agx::Index > TimeParticleIdPair
TeleportToSensorOperation(const agx::Name &name=agx::Name())
void postContactHandling(agxSDK::Simulation *simulation, EventSensor *sensor) override
Post function that will be triggered for the event after all the contacts have handled in the operati...
agx::List< TimeParticleIdPair > ParticleTeleportQueue
TeleportToSensorOperation(const agx::Name &name, EventSensor *target, agx::Real teleportTimeDilation=0, bool cloneTeleportation=false, agx::Frame *sourceoffset=nullptr, agx::Frame *targetoffset=nullptr)
agxControl::EventSensor * m_targetSensor
void addNotification(EventSensor *sensor) override
Function will be executed when the sensor that the operations is added to is added to a simulation.
agxData::EntityStorageRef m_particleTeleportStorage
void triggerEvent(const agx::TimeStamp &t, agxSDK::Simulation *simulation, agxCollide::GeometryContact *cd, agxControl::EventSensor *sensor) override
Triggers the sensor event by passing contact information.
static agxRender::Color Yellow()
Definition Color.h:193
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
The object defining a frame of reference and providing transformations operations.
Definition agx/Frame.h:68
Inheritance with partial specialization due to bug with ref_ptr containers.
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Definition Name.h:33
A class holding 4 dimensional vectors and providing basic arithmetic.
#define CALLABLE
Definition macros.h:72
#define AGX_FORCE_INLINE
Definition macros.h:58
This namespace contains general operation and action classes which can be used to control a agxSDK::S...
uint32_t UInt32
Definition Integer.h:32
double Real
Definition Real.h:42
agx::Real TimeStamp
Definition TimeStamp.h:26