rules¶
- class ConstantPWM(timer: Timer, powertrain: Powertrain, target_pwm_value: float | int)
Bases:
RuleBaseConstantPWMobject.It can be used to make a gradual start of the
powertrain’s motion, in order to avoid a peak in thepowertrain’s DC motor absorbed electric current.It checks whether the
timeris active and, if so, it sets thepwmofpowertrainmotor to the constanttarget_pwm_value.Methods¶
apply()It checks if
timeris active and, if so, it returns thepwmto apply to thepowertrainmotor, equal totarget_pwm_value.
Raises
TypeErrorIf
timeris not an instance ofTimer,if
powertrainis not an instance ofPowertrain,
ValueErrorIf
target_pwm_valueis not within-1and1.
See Also
- class ReachAngularPosition(encoder: AbsoluteRotaryEncoder, powertrain: Powertrain, target_angular_position: AngularPosition, braking_angle: Angle)
Bases:
RuleBaseReachAngularPositionobject.It can be used to make the
encoder’stargetreach atarget_angular_positionwithin abraking_angle.Methods¶
apply()It computes the
pwmto apply to thepowertrain’s motor in order to reach atarget_angular_positionby thetargetrotating object of theencoder, within a specificbraking_angle.
Raises
TypeErrorIf
encoderis not an instance ofAbsoluteRotaryEncoder,if
powertrainis not an instance ofPowertrain,if the first element in
powertrainis not an instance ofMotorBase,if an element of
powertrainis not an instance ofRotatingObject,if
target_angular_positionis not an instance ofAngularPosition,if
braking_angleis not an instance ofAngle.
ValueErrorIf
powertrain.elementsis an emptytuple.
See Also
- apply() None | float | int
It computes the
pwmto apply to thepowertrain’s DC motor in order to reach atarget_angular_positionby thetargetrotating object of theencoder, within a specificbraking_angle.Returns¶
Notes
The braking angle is the angle within which the motor’s
pwmis controlled in order to brake and reach thetarget_angular_position.The rule is applied only if the difference between
target_angular_positionand theencoder’s targetangular_positionis lower than or equal to thebraking_angle.The lower the
braking_anglethe higher the deceleration of the system, thus the higher the vibrations produced.First of all, the rule computes the
powertrain’s static error according to the following formula:\[\theta_{err} \left( T_l \right) = \frac{T_l}{T_{max}} \, \frac{\theta_b}{\eta_t}\]where:
\(\theta_{err}\) is the
powertrainstatic error,\(T_l\) is the load torque on the
powertrainDC motor (DCMotor.load_torque),\(T_{max}\) is the maximum torque developed by the
powertrainDC motor (DCMotor.maximum_torque),\(\theta_b\) is the
braking_angleparameter,\(\eta_t\) is the
powertrainoverall efficiency, computed as:
\[\eta_t = \prod_{i = 1}^N \eta_i\]where:
\(\eta_i\) is the mechanical mating efficiency of the mating between two gears (
SpurGear.master_gear_efficiencyorHelicalGear.master_gear_efficiencyorWormGear.master_gear_efficiencyorWormWheel.master_gear_efficiency),\(N\) is the total number of gear matings in the
powertrain.
Then it checks the applicability condition, defined as:
\[\theta \ge \theta_s = \theta_t - \theta_b + \theta_{err}\]where:
\(\theta\) is the
encoder’stargetangular_position,\(\theta_s\) is the braking starting angle,
\(\theta_t\) is the
target_angular_positionparameter.
If the applicability condition is not met, then it returns
None, otherwise it computes thepwmas:\[D \left( \theta \right) = 1 - \frac{\theta - \theta_s}{\theta_b}\]where \(D\) is the supply voltage PWM duty cycle
pwmto apply to the DC motor in order to reach thetarget_angular_positionby theencoder’stargetrotating object.
- class StartLimitCurrent(encoder: AbsoluteRotaryEncoder, tachometer: Tachometer, motor: DCMotor, target_angular_position: AngularPosition, limit_electric_current: Current)
Bases:
RuleBaseStartLimitCurrentobject.It can be used to make a gradual start of the powertrain’s motion and limit the
motorabsorbed electric current to be lower than or equal to alimit_electric_currentvalue. It computes apwmto apply to themotorup until theencoder’starget’sangular_positionequalstarget_angular_position.For an optimal
pwmmanagement, it is suggested to set themotoras thetachometer’starget.Methods¶
apply()It computes the
pwmto apply to themotorin order to limit its absorbed electric current to be lower or equal tolimit_electric_current, until theencoder’stargetrotating object’sangular_positionequals thetarget_angular_position.
Raises
TypeErrorIf
encoderis not an instance ofAbsoluteRotaryEncoder,If
tachometeris not an instance ofTachometer,If
motoris not an instance ofDCMotor,if
target_angular_positionis not an instance ofAngularPosition,if
limit_electric_currentis not an instance ofCurrent.
ValueErrorIf the
motorcannot computeelectric_currentproperty (DCMotor.electric_current),if
limit_electric_currentis negative or null.
See Also
- apply() None | float | int
It computes the
pwmto apply to themotorin order to limit its absorbed electric current to be lower or equal tolimit_electric_current, until theencoder’stargetrotating object’sangular_positionequals thetarget_angular_position.Returns¶
floatorintorNonePWM value to apply to the
motorin order to limit its absorbed electric current to be lower or equal tolimit_electric_current
Notes
It checks the applicability condition, defined as:
\[\theta \le \theta_t\]where:
\(\theta\) is the
encoder’stargetangular_position,\(\theta_t\) is the
target_angular_position.
If the applicability condition is not met, then it returns
None, otherwise it computes thepwmas:\[D \left( \dot{\theta} \right) = \frac{1}{2} \, \left( \frac{\dot{\theta}}{\dot{\theta}_0} + \frac{i_{lim}}{i_{max}} + \sqrt{ \left( \frac{\dot{\theta}}{\dot{\theta}_0} \right)^2 + \left( \frac{i_{lim}}{i_{max}} \right)^2 + 2 \frac{\dot{\theta}}{\dot{\theta}_0} \frac{i_{lim} - 2 i_0}{i_{max}} } \right)\]where:
\(\dot{\theta}\) is the
tachometer’starget’s angular speed,\(\dot{\theta}_0\) is the
motorno load angular speed (DCMotor.no_load_speed),\(i_{lim}\) is the
limit_electric_currentparameter,\(i_{max}\) is the
motormaximum electric current (DCMotor.maximum_electric_current),\(i_0\) is the
motorno load electric current (DCMotor.no_load_electric_current).
- class StartProportionalToAngularPosition(encoder: AbsoluteRotaryEncoder, powertrain: Powertrain, target_angular_position: AngularPosition, pwm_min_multiplier: float | int, pwm_min: float | None = None)
Bases:
RuleBaseStartProportionalToAngularPositionobject.It can be used to make a gradual start of the
powertrain’s motion, in order to avoid a peak in thepowertrain’s DC motor absorbed electric current.It computes a
pwmto apply to thepowertrain’s DC motor which increases linearly with theencoder’stargetrotating object’sangular_position. The computedpwmstarts from a minimum value, based onpowertrain’s elements properties andpwm_min_multiplieror solely onpwm_minparameter. The computedpwmincreases up to1when theencoder’starget’sangular_positionequalstarget_angular_position.Methods¶
apply()It computes the
pwmto apply to thepowertrainmotor, proportional to theencoder’stargetangular_positionuntil it reaches thetarget_angular_position.
Raises
TypeErrorIf
encoderis not an instance ofAbsoluteRotaryEncoder,if
powertrainis not an instance ofPowertrain,if the first element in
powertrainis not an instance ofMotorBase,if an element of
powertrainis not an instance ofRotatingObject,if
target_angular_positionis not an instance ofAngularPosition,
- ValueError
If
powertrain.elementsis an emptytuple,if the
powertrainmotor cannot computeelectric_currentproperty (DCMotor.electric_current),if
pwm_min_multiplieris less than or equal to1,if
pwm_minis defined and it is negative or null.
See Also
- apply() None | float | int
It computes the
pwmto apply to thepowertrainmotor, proportional to theencoder’stargetangular_positionuntil it reaches thetarget_angular_position.Returns¶
floatorintorNonePWM value to apply to the motor, proportional to the
encoder’stargetangular_position.
Notes
The
powertrain’s motor has a minimumpwmwhich, as is, cannot be used to control the motor, since at this value the motor will remain still. So, in order to properly control the motor motion, it is required to apply apwmgreater than the minimumpwm, therefore the motor minimumpwmis multiplied bypwm_min_multiplierto get a startingpwmto be applied to the motor.If the motor’s minimum
pwmis null, then it is useless to multiply this value bypwm_min_multiplierin order to get a startingpwm; therefore, only in this case,pwm_minis directly used as startingpwm.First of all, the rule computes a candidate minimum applicable
pwmas:\[D_{min}^c \left( T_l \right) = \frac{1}{\eta_t} \, \frac{T_l}{T_{max}} \, \frac{i_{max} - i_0}{i_{max}} + \frac{i_0}{i_{max}}\]where:
\(D_{min}^c\) is the candidate minimum applicable
pwm,\(T_l\) is the load torque on the
powertrainDCMotor.load_torque,\(T_{max}\) is the maximum torque developed by the
powertrainDC motor (DCMotor.maximum_torque),\(i_{max}\) is the maximum electric current absorbed by the
powertrainDC motor (DCMotor.maximum_electric_current),\(i_0\) is the no load electric current absorbed by the
powertrainDC motor (DCMotor.no_load_electric_current),\(\eta_t\) is the
powertrainoverall efficiency, computed as:
\[\eta_t = \prod_{i = 1}^N \eta_i\]where:
\(\eta_i\) is the mechanical mating efficiency of the mating between two gears (
SpurGear.master_gear_efficiencyorHelicalGear.master_gear_efficiencyorWormGear.master_gear_efficiencyorWormWheel.master_gear_efficiency),\(N\) is the total number of gear matings in the
powertrain.
If both the load torque on the
powertrainDC motor \(T_l\) and the motor no load electric current \(i_0\) are null, then also the computed candidate minimum applicablepwm\(D_{min}^c\) is null. Only in this case, the computed candidate minimum applicablepwmis discarded and it is taken into account thepwm_minparameter, which must have been set (don’t used otherwise):\[D_{min} = D_{min}^p\]where:
\(D_{min}\) is the minimum applicable
pwm,\(D_{min}^p\) is the
pwm_minparameter.
Otherwise, the candidate \(D_{min}\) is multiplied by the
pwm_min_multiplierparameter.\[D_{min} = D_{min}^c \, g\]where \(g\) is the
pwm_min_multiplierparameter.Then it checks the applicability condition, defined as:
\[\theta \le \theta_t\]where:
\(\theta\) is the
encoder’stargetangular_position,\(\theta_t\) is the
target_angular_position.
If the applicability condition is not met, then it returns
None, otherwise it computes thepwmas:\[D \left( \theta \right) = \left( 1 - D_{min} \right) \frac{\theta}{\theta_t} + D_{min}\]