apply¶
- StartProportionalToAngularPosition.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}\]