AGX Dynamics  2.37.3.2
Engine.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 #pragma once
18 
19 #include <agxDriveTrain/Shaft.h>
22 
23 namespace agxDriveTrain
24 {
26 
31  {
32  public:
39 
43  virtual agx::Real getCurrentPowerTimeIntegral() const override;
44 
48  void setMinTorque(agx::Real minTorque);
49 
50  agx::Real getMinTorque() const;
51 
55  virtual agx::Real variableLookupFunction( ) const override;
56 
60  virtual agx::Real resultScalerFunction() const override;
61 
65  virtual bool store(agxStream::StorageStream& str) const override;
66 
70  virtual bool restore(agxStream::StorageStream& str) override;
71 
73 
74  protected:
76  virtual ~EnginePowerGenerator();
78  };
79 
80 
81 
83 
88  {
89  public:
93  Engine();
94 
98  agxPowerLine::PowerGenerator* getPowerGenerator() const;
99 
103  void setPowerGenerator(agxPowerLine::PowerGenerator* generator);
104 
108  agx::Real getRPM() const;
109 
114  void setThrottle(agx::Real throttle);
115 
119  virtual agx::Real getThrottle() const;
120 
124  void setIdleRPM(agx::Real idleRPM);
125 
129  agx::Real getIdleRPM() const;
130 
131  public:
135  virtual bool preUpdate(agx::Real timeStep) override;
136 
140  virtual bool store(agxStream::StorageStream& str) const override;
141 
145  virtual bool restore(agxStream::StorageStream& str) override;
146 
148 
149  protected:
150  virtual ~Engine();
151 
152  protected:
156  };
157 
158 
159 
160  class PidControlledEngine;
161 
170  {
171  public:
175  explicit ThrottleCalculator( PidControlledEngine* engine );
176 
181  virtual agx::Real calculateThrottle() = 0;
182 
186  void setEngine( PidControlledEngine* engine );
187 
191  PidControlledEngine* getEngine();
192  const PidControlledEngine* getEngine() const;
193 
197  virtual bool store( agxStream::StorageStream& str ) const;
198 
202  virtual bool restore( agxStream::StorageStream& str );
203 
204  void store( agxStream::OutputArchive& out ) const override;
205 
206  void restore( agxStream::InputArchive& in ) override;
207 
209 
211 
212  protected:
213  virtual ~ThrottleCalculator( );
215  };
216 
218 
219 
220 
245  {
246  public:
259  PidControlledEngine* engine, agx::Real targetRpm,
260  agx::Real pGain, agx::Real dGain, agx::Real iGain,
261  agx::Real iRange);
262 
263  agx::Real getTargetRpm() const;
264  void setTargetRpm(agx::Real targetRpm);
265 
266  agx::Real getLastThrottle() const;
267 
268 
269  // Methods called other classes in the DriveTrain framework.
270  public:
271  virtual agx::Real calculateThrottle() override;
272 
276  virtual bool store(agxStream::StorageStream& str) const override;
277 
281  virtual bool restore(agxStream::StorageStream& str) override;
282 
284 
285  protected:
286  RpmController();
287  virtual ~RpmController();
288 
289  private:
290  agx::Real m_targetRpm;
291 
292  agx::Real m_pGain;
293  agx::Real m_dGain;
294  agx::Real m_iGain;
295  agx::Real m_iRange;
296 
297  agx::Real m_iState;
298  agx::Real m_lastRpmDiff;
299  agx::Real m_lastThrottle; // \todo Should this be in ThrottleCalculator? If so, how should it be updated?
300  };
301 
302 
304 
305 
306 
321  {
322  public:
327 
331  void ignition( bool ignition );
332 
336  void shutdown( bool shutdown );
337 
341  bool isRunning( ) const;
342 
346  agx::Real getRPM( ) const;
347 
351  agx::Real getLoadTorque( ) const;
352 
356  void setRPMTorqueTable( const agx::RealPairVector& rpm_torques );
357 
361  void setRPMPowerTable( const agx::RealPairVector& rpm_power );
362 
366  agx::Real getTorqueAtRPM( agx::Real rpm ) const;
367 
372  void setExtraLoad( agx::Real torque );
373 
374  agx::Real getExtraLoad( ) const;
375 
380  void setThrottleCalculator( ThrottleCalculator* controller );
381 
385  const ThrottleCalculator* getThrottleCalculator() const;
386  ThrottleCalculator* getThrottleCalculator();
387 
391  agx::Real getTorque( ) const;
392 
393  public:
397  virtual bool preUpdate( agx::Real timeStamp ) override;
398 
402  virtual bool store( agxStream::StorageStream& str ) const override;
403 
407  virtual bool restore( agxStream::StorageStream& str ) override;
408 
410 
411  protected:
412  virtual ~PidControlledEngine( );
413  bool m_isOn;
415  ThrottleCalculatorRef m_pidController;
416  };
417 
419 
420 
425  {
426  public:
431 
440  agx::Real getCurrentTorque();
441 
445  agx::Real getTargetVelocity();
446 
450  agx::RangeReal getTorqueRange();
451 
457  void setTargetVelocity(agx::Real velocity);
458 
463  void setTargetRpm(agx::Real rpm);
464 
473  void setTorqueRange(agx::RangeReal range);
474 
478  const agxDriveTrain::VelocityConstraint* getConstraint() const;
479 
483  agxDriveTrain::VelocityConstraint* getConstraint();
484 
488  virtual bool addNotification(agxSDK::Simulation* simulation) override;
489 
492  virtual bool removeNotification(agxUtil::ConstraintHolder* constraintHolder, agxSDK::Simulation* simulation) override;
493 
497  virtual bool store(agxStream::StorageStream& str) const override;
498 
502  virtual bool postStore(agxStream::StorageStream& str) const override;
503 
507  virtual bool restore(agxStream::StorageStream& str) override;
508 
512  virtual bool postRestore(agxStream::StorageStream& str) override;
513 
516 
517  protected:
518  virtual ~FixedVelocityEngine();
519 
521  };
522 
524 }
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
ThrottleCalculatorRef m_pidController
Definition: Engine.h:415
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
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...
agx::ref_ptr< ThrottleCalculator > ThrottleCalculatorRef
Definition: Engine.h:217
A constraint holding a single VelocityConstraintImplementation.
Inherit from the ThrottleCalculator and implement the calculateThrottle() function to control the tor...
Definition: Engine.h:169
An engine that tries to hold a fixed velocity.
Definition: Engine.h:424
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
A Shaft is the most basic PowerLine Unit.
Definition: Shaft.h:34
Power generator that adds torque to the engine according to a lookup table.
Definition: Engine.h:30
A library of agxPowerLine components designed to model the various parts of a vehicle drive train...
agx::ref_ptr< FixedVelocityEngine > FixedVelocityEngineRef
Definition: Engine.h:523
ThrottleCalculator that strives to keep the engine at some given RPM.
Definition: Engine.h:244
Base class providing referencing counted objects.
Definition: Referenced.h:119
agx::Real m_throttle
Definition: Engine.h:154
Templated vector class.
Definition: Vector.h:52
The rotational has one rotational degree of freedom.
agx::ref_ptr< PidControlledEngine > PidControlledEngineRef
Definition: Engine.h:418
agx::Real m_idleRPM
Definition: Engine.h:155
PidControlledEngine * m_engine
Definition: Engine.h:214
agx::ref_ptr< RpmController > RpmControllerRef
Definition: Engine.h:303
Implementation of a combustion engine.
Definition: Engine.h:320
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
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
agxDriveTrain::VelocityConstraintRef m_velocityConstraint
Definition: Engine.h:520
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#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
#define AGXMODEL_EXPORT
double Real
Definition: Real.h:42
A torque generator adds torque to the body of a rotational dimension.
An engine that is driven by an EnginePowerGenerator.
Definition: Engine.h:87
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
Will generate power by adding a load to a physical dimension.
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agxPowerLine::PowerGeneratorRef m_generator
Definition: Engine.h:153