PWMControl

class PWMControl(powertrain: Powertrain)

Bases: MotorControlBase

PWMControl object.

Attributes

ruleslist

The list of the pwm rules to be applied.

Methods

add_rule()

It adds a rule to rules list.

apply_rules()

It applies all the rules in order to get a valid pwm value to set to the powertrain’s motor.

Raises

TypeError
  • If powertrain is not an instance of Powertrain,

  • if the first element in powertrain is not an instance of MotorBase,

  • if an element of powertrain is not an instance of RotatingObject.

ValueError

If powertrain.elements is an empty tuple.

See Also

DCMotor.pwm

add_rule(rule: RuleBase) None

It adds a rule to rules list.

Parameters

ruleRuleBase

Rule to be added to rules list.

Raises

TypeError

If rule is not an instance of RuleBase.

See Also

rules module

apply_rules() None

It applies all the rules in order to get a valid pwm value to set to the powertrain’s motor.

It loops over listed rules and applies all of them:

  • if a single rule returns a valid pwm, then this value is set as powertrain’s motor pwm,

  • if more than a single rule returns a valid pwm, then it raises a ValueError, since multiple rules are valid at the same time and it is not possible to identify which pwm value to use,

  • if no rule returns a valid pwm, then it sets powertrain’s motor pwm to 1.

Before settings the pwm, its value is saturated in order to be within -1 and 1.

Raises

ValueError

If two different rules are applicable at the same time. Only a single applicable rule is allowed to a specific simulation time.

property rules: list

List of the pwm rules to be applied.

Returns

list

The list of the pwm rules to be applied.

See Also

rules module