30#include "TrackJoint.h"
31#include "TrackJointLimits.h"
34#include "trax/Location.h"
43 class TrackJointFeeder{
45 dclspc TrackJointFeeder(
Real engine_meters_per_unit,
Real engine_kilograms_per_unit )
noexcept;
51 bool dclspc Rail( std::shared_ptr<const Track> pTrack,
const TrackLocation& tl,
bool doPulse =
true );
53 bool dclspc Rail(
const Location& location,
bool doPulse =
true );
55 void dclspc DeRail(
bool doPulse =
true );
57 bool dclspc IsRailed() const noexcept;
59 bool dclspc IsMovableBodySleeping() const noexcept;
61 void dclspc WakeUp() noexcept;
63 void dclspc SetVelocity(
Velocity velocity );
65 Velocity dclspc GetVelocity() const noexcept;
67 dclspc const
Location& GetLocation() const noexcept;
71 virtual
void SetMotorForceLimits(
Force min,
Force max ) noexcept = 0;
73 virtual
void SetMotorTarget(
Velocity ) noexcept = 0;
75 virtual
Velocity GetMotorTarget() noexcept = 0;
145 inline
Real EngineMetersPerUnit() const noexcept{
146 return m_EngineMetersPerUnit;
148 inline Real EngineKilogramsPerUnit() const noexcept{
149 return m_EngineKilogramsPerUnit;
152 virtual void TurnAnchor()
const = 0;
153 virtual void TrackBodyChange( std::shared_ptr<const Body> pToBody ) = 0;
154 virtual void SetTimeStep(
Time dt ) = 0;
155 virtual void UpdateBodies()
const = 0;
156 virtual bool SetValues(
const TrackData<Real>& trackData ) = 0;
157 virtual bool DoIsMovableBodySleeping() const noexcept = 0;
158 virtual
void DoWakeUp() const = 0;
159 virtual
void DoRail() = 0;
160 virtual
void DoDerail() = 0;
165 Real m_EngineMetersPerUnit;
166 Real m_EngineKilogramsPerUnit;
170 bool m_bRolling = false;
177 spat::VectorBundle<Length,One> wF;
178 m_Location.Transition( wF );
180 return (AP - wF.
P) * wF.
T;
183 std::shared_ptr<Event> m_pEvent;
184 std::shared_ptr<SignalTarget> m_pSignalTarget;
186 Jack_Imp m_JackOnRail {
"JackOnRail" };
187 Jack_Imp m_JackOnDerail {
"JackOnDerail" };
188 Jack_Imp m_JackOnRollingStart {
"JackOnRollingStart" };
189 Jack_Imp m_JackOnRollingStop {
"JackOnRollingStop" };
190 Jack_Imp m_JackOnStartTilting {
"JackOnStartTilting" };
191 Jack_Imp m_JackOnStopTilting {
"JackOnStopTilting" };
192 Jack_Imp m_JackOnTrackTransition{
"JackOnTrackTransition" };
198 class TrackJointFeederMotorModel :
public TrackJointFeeder{
200 TrackJointFeederMotorModel(
Real engine_meters_per_unit,
Real engine_kilograms_per_unit );
266 Force dclspc MaxThrust() const noexcept;
355 Force MaxPossibleWheelThrust() const noexcept;
356 Force MaxWheelThrust() const noexcept;
357 Force MaxWheelBraking() const noexcept;
358 Force MaxWheelFriction() const noexcept;
359 Real Characteristic(
Velocity velocity ) const noexcept;
361 void UpdateMotorValues() noexcept;
363 bool CalculateMotorAction() noexcept;
364 bool CalculateBrakeAction() noexcept;
368 Jack_Imp m_JackOnMotorActive{
"JackOnMotorActive" };
369 Jack_Imp m_JackOnMotorInactive{
"JackOnMotorInactive" };
370 Jack_Imp m_JackOnBrakeActive{
"JackOnBrakeActive" };
371 Jack_Imp m_JackOnBrakeInactive{
"JackOnBrakeInactive" };
378 template<
typename Valtype,
class Base>
379 class TrackJointFeeder_Imp :
public Base{
381 TrackJointFeeder_Imp() =
delete;
382 TrackJointFeeder_Imp(
TrackJoint<Valtype>& rTrackJoint, Valtype engine_meters_per_unit, Valtype engine_kilograms_per_unit )
noexcept;
383 ~TrackJointFeeder_Imp();
387 void SetMotorForceLimits(
Force min,
Force max )
noexcept override;
389 void SetMotorTarget(
Velocity )
noexcept override;
391 Velocity GetMotorTarget()
noexcept override;
399 void TurnAnchor()
const override;
400 void TrackBodyChange( std::shared_ptr<const Body> pToBody )
override;
401 void SetTimeStep(
Time dt )
override;
402 void UpdateBodies()
const override;
404 bool DoIsMovableBodySleeping()
const noexcept override;
405 void DoWakeUp()
const override;
406 void DoRail()
override;
407 void DoDerail()
override;
413template<
typename Valtype,
class Base>
414inline TrackJointFeeder_Imp<Valtype,Base>::TrackJointFeeder_Imp(
416 Valtype engine_meters_per_unit,
417 Valtype engine_kilograms_per_unit ) noexcept
418 : Base { engine_meters_per_unit, engine_kilograms_per_unit },
419 m_TrackJoint{ rTrackJoint }
423template<
typename Valtype,
class Base>
424inline trax::TrackJointFeeder_Imp<Valtype, Base>::~TrackJointFeeder_Imp()
426 m_TrackJoint.release();
429template<
typename Valtype,
class Base>
430inline void TrackJointFeeder_Imp<Valtype, Base>::SetLimits(
const TrackJointLimits& wfl )
432 m_TrackJoint.NormalForceLimits(
433 _N(wfl.NormalForceLimitMin) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit(),
434 _N(wfl.NormalForceLimitMax) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit() );
435 m_TrackJoint.BinormalForceLimits(
436 _N(wfl.BinormalForceLimitMin) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit(),
437 _N(wfl.BinormalForceLimitMax) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit() );
438 m_TrackJoint.NormalTorqueLimit(
439 _Nm(wfl.NormalTorqueLimit) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit() / Base::EngineMetersPerUnit() );
440 m_TrackJoint.TorqueLimit(
441 _Nm(wfl.TorqueLimit) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit() / Base::EngineMetersPerUnit() );
442 m_TrackJoint.ThresholdP(
_m(wfl.ThresholdPosition) / Base::EngineMetersPerUnit() );
443 m_TrackJoint.ThresholdT( wfl.ThresholdTangent );
444 m_TrackJoint.ThresholdN( wfl.ThresholdNormal );
445 m_TrackJoint.ThresholdB( wfl.ThresholdBinormal );
446 m_TrackJoint.ErrorReductionParameter( wfl.ErrorReduction );
449template<
typename Valtype,
class Base>
450inline void TrackJointFeeder_Imp<Valtype,Base>::SetMotorForceLimits(
Force min,
Force max )
noexcept{
452 const Force temp = min;
457 m_TrackJoint.MotorForceLimits(
458 _N(min) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit(),
459 _N(max) / Base::EngineKilogramsPerUnit() / Base::EngineMetersPerUnit() );
462template<
typename Valtype,
class Base>
463inline void TrackJointFeeder_Imp<Valtype,Base>::SetMotorTarget(
Velocity vTarget )
noexcept{
464 m_TrackJoint.MotorTarget( (Base::GetLocation().Orient() ==
Orientation::Value::para ? +1.0f : -1.0f) *
_mIs(vTarget) / Base::EngineMetersPerUnit() );
467template<
typename Valtype,
class Base>
468inline Velocity TrackJointFeeder_Imp<Valtype,Base>::GetMotorTarget() noexcept
470 return _mIs( (Base::GetLocation().Orient() ==
Orientation::Value::para ? +1.0f : -1.0f) * Base::EngineMetersPerUnit() * m_TrackJoint.MotorTarget() );
473template<
typename Valtype,
class Base>
477 {
_m(Base::EngineMetersPerUnit() * m_TrackJoint.GlobalAnchor().P.x),
478 _m(Base::EngineMetersPerUnit() * m_TrackJoint.GlobalAnchor().P.y),
479 _m(Base::EngineMetersPerUnit() * m_TrackJoint.GlobalAnchor().P.z) },
486template<
typename Valtype,
class Base>
490 {
_m(Base::EngineMetersPerUnit() * m_TrackJoint.Anchor().P.x),
491 _m(Base::EngineMetersPerUnit() * m_TrackJoint.Anchor().P.y),
492 _m(Base::EngineMetersPerUnit() * m_TrackJoint.Anchor().P.z) },
499template<
typename Valtype,
class Base>
502 m_TrackJoint.Anchor( {
503 {
_m(frame.P.x) / Base::EngineMetersPerUnit(),
504 _m(frame.P.y) / Base::EngineMetersPerUnit(),
505 _m(frame.P.z) / Base::EngineMetersPerUnit() },
512template<
typename Valtype,
class Base>
513void TrackJointFeeder_Imp<Valtype,Base>::TurnAnchor()
const
516 m_TrackJoint.Anchor( { A.
P, -A.
T, -A.
N, A.
B } );
517 m_TrackJoint.MotorTarget( -m_TrackJoint.MotorTarget() );
518 m_TrackJoint.MotorForceLimits( -m_TrackJoint.MotorForceMax(), -m_TrackJoint.MotorForceMin() );
521template<
typename Valtype,
class Base>
522inline void TrackJointFeeder_Imp<Valtype,Base>::TrackBodyChange( std::shared_ptr<const Body> pToBody ){
523 m_TrackJoint.UpdateTrackBody( pToBody );
526template<
typename Valtype,
class Base>
527void TrackJointFeeder_Imp<Valtype,Base>::SetTimeStep(
Time dt ){
528 m_TrackJoint.SetTimeStep( dt );
531template<
typename Valtype,
class Base>
532inline void TrackJointFeeder_Imp<Valtype,Base>::UpdateBodies()
const{
533 m_TrackJoint.UpdateBodies();
536template<
typename Valtype,
class Base>
537bool TrackJointFeeder_Imp<Valtype,Base>::SetValues(
const TrackData<Real>& trackData ){
538 return m_TrackJoint.SetValues( trackData );
541template<
typename Valtype,
class Base>
542inline bool TrackJointFeeder_Imp<Valtype,Base>::DoIsMovableBodySleeping() const noexcept{
543 return m_TrackJoint.IsMovableBodySleeping();
546template<
typename Valtype,
class Base>
547void TrackJointFeeder_Imp<Valtype,Base>::DoWakeUp()
const{
548 return m_TrackJoint.WakeUp();
551template<
typename Valtype,
class Base>
552inline void TrackJointFeeder_Imp<Valtype, Base>::DoRail()
554 m_TrackJoint.SetDerailed(
false );
557template<
typename Valtype,
class Base>
558inline void TrackJointFeeder_Imp<Valtype,Base>::DoDerail()
560 m_TrackJoint.SetDerailed(
true );
A Location specifies a position on a track system by referencing a track and a TrackLocation on it.
Definition Location.h:110
dclspc Jack & JackOnRollingStop() noexcept
Gets a Jack that pulses its Plug if the WheelFrame stops to roll.
dclspc Jack & JackOnDerail() noexcept
Gets a Jack that pulses its Plug if the WheelFrame derails.
bool virtual dclspc Update(Time dt)
Simulation update method, to be called, after a simulation step is finished.
virtual spat::Frame< Length, One > Anchor() const noexcept=0
Gets the anchor in local coordinates.
dclspc Jack & JackOnTrackTransition() noexcept
Gets a Jack that pulses its Plug if the WheelFrame passes the connection between two tracks.
dclspc Jack & JackOnStartTilting() noexcept
Gets a Jack that pulses its Plug if the WheelFrame starts tilting.
dclspc Jack & JackOnRail() noexcept
Gets a Jack that pulses its Plug if the WheelFrame gets railed on a track.
dclspc std::shared_ptr< SignalTarget > AttachSignal(std::shared_ptr< SignalTarget > pSignalTarget) noexcept
Attaches the signal target to this TrackJointFeeder.
dclspc Jack & JackOnRollingStart() noexcept
Gets a Jack that pulses its Plug if the WheelFrame starts to roll.
dclspc Jack & JackOnStopTilting() noexcept
Gets a Jack that pulses its Plug if the WheelFrame starts tilting.
virtual spat::Frame< Length, One > GlobalAnchor() const =0
Gets the anchor in global coordinates.
dclspc std::shared_ptr< Event > AttachEvent(std::shared_ptr< Event > pEvent) noexcept
Attaches the sensor event to this TrackJointFeeder.
void dclspc DetachAllWheelsets() noexcept
Removes all the Wheelsets.
Force dclspc MaxBrake() const noexcept
Gets the maximal available braking. This value is determined by the properties of the Wheelsets attac...
void dclspc ThrustAbsolute(Force thrust) noexcept
Sets the thrust as absolute force values. If the value exceeds MaxThrust() it get clipped.
void dclspc SetTractionForceCharacteristic(std::shared_ptr< const struct TractionForceCharacteristic > pCharacteristic)
applies a TractionForceCharacteristic to the thrust calculations.
std::shared_ptr< const TractionForceCharacteristic > dclspc GetTractionForceCharacteristic() const noexcept
void dclspc BrakeAbsolute(Force brake) noexcept
Sets the brake as absolute force value. If the value exceeds MaxBrake() it gets clipped.
void dclspc TargetVelocity(Velocity vTarget) noexcept
Sets the target velocity to aim for by using the supplied Thrust() and Brake() settings.
void dclspc Thrust(One byfactor) noexcept
Sets the fraction of the maximum thrust to apply in order to reach the target velocity specified by T...
Power dclspc MaximumPowerOutput() const noexcept
Velocity dclspc TargetVelocity() const noexcept
Gets the target velocity set for this RailRunner.
void dclspc Brake(One byfactor) noexcept
Sets the fraction of the maximum braking to apply in order to reach a zero velocity.
Velocity dclspc MaximumVelocity() const noexcept
dclspc Jack & JackOnBrakeInactive() noexcept
Gets a Jack that pulses its Plug if the Feeder's brake gets deactivated.
dclspc Jack & JackOnMotorActive() noexcept
Gets a Jack that pulses its Plug if the Feeder's motor gets activated in order to reach the target ve...
int dclspc Attach(const Wheelset &ws)
Attaches a Wheelset to this WheelFrame.
Power dclspc CurrentPowerOutput() const noexcept
dclspc Jack & JackOnMotorInactive() noexcept
Gets a Jack that pulses its Plug if the Feeder's motor gets deactivated.
int dclspc CntWheelsets() const
Gets the number of Wheelsets attached directly to this WheelFrame.
bool dclspc Update(Time dt) override
Simulation update method, to be called, after a simulation step is finished.
dclspc const Wheelset & GetWheelset(int idx) const
Gets the Wheelset denoted by idx.
dclspc Jack & JackOnBrakeActive() noexcept
Gets a Jack that pulses its Plug if the Feeder's brake gets activated in order to reach the target ve...
Physics engine agnostic part of track joint logic.
Definition TrackJoint.h:45
Value< Dimension< 1, 0, -1 > > Velocity
Velocity.
Definition DimensionedValues.h:331
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
Value< Dimension< 0, 0, 1 > > Time
Time.
Definition DimensionedValues.h:329
constexpr Real _m(Length l) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1210
constexpr Real _N(Force f) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1551
Value< Dimension< 1, 1, -2 > > Force
Force.
Definition DimensionedValues.h:333
float Real
Underlying floating point type to be used with the dim library.
Definition DimensionedValues.h:190
Value< Dimension< 2, 1, -3 > > Power
Power.
Definition DimensionedValues.h:339
constexpr Real _mIs(Velocity v) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1395
constexpr Real _Nm(Torque t) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1655
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
Frame< Valtype, ValtypeT > & spatial_cast(Frame< Valtype2, ValtypeT2 > &from) noexcept
Cast to Frame with different underlying value types.
Definition Frame.h:1062
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Vector< ValtypeT > B
Binormal axis or z-axis.
Definition Frame.h:56
Position< Valtype > P
Point in 3D space.
Definition Frame.h:53
Vector< ValtypeT > N
Normal axis or y-axis.
Definition Frame.h:55
Vector< ValtypeT > T
Tangential axis or x-axis.
Definition Frame.h:54
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Position< Valtype > P
Base space postion.
Definition VectorBundle.h:43
Vector< ValtypeT > T
Tangent vector or x-axis.
Definition VectorBundle.h:44
A jack a plug can get connected with.
Definition Jack.h:83
@ para
Denoting the aligned, parallel orientation.
Definition Orientation.h:43
@ anti
Denoting the non parallel or opposite orientation.
Definition Orientation.h:42
Target for signal notification.
Definition Signal.h:407
Full geometrical data at a point on a track.
Definition TrackData.h:36
The maximum forces and spatial deviations of a WheelFrame used by physics calculations.
Definition TrackJointLimits.h:38
A TrackLocation ist a location on a single track.
Definition TrackLocation.h:43
Function that defines the characteristic behaviour of a motor to change its maximum available trackti...
Definition TractionForceCharacteristic.h:59
Describing data of a wheelset.
Definition Wheelset.h:40