utils¶
- class StopCondition(sensor: SensorBase, threshold: UnitBase, operator: OperatorBase)¶
Bases:
objectStopConditionobject.Attributes¶
sensorSensorBaseThe sensor to be monitored to check if the stop condition is valid.
thresholdUnitBaseThe threshold value that triggers the stop condition.
operatorOperatorBaseThe comparison operator to use to check if the stop condition is valid.
Methods¶
check_condition()It applies the comparison
operatorto thesensorvalue and thethresholdvalue to check if the stop condition is valid.
- check_condition() bool¶
It applies the comparison
operatorto thesensorvalue and thethresholdvalue to check if the stop condition is valid.If the stop condition is valid, then the
Solverstops the computation even if it is not completed to the final simulation time.Returns¶
boolWhether stop condition is valid.
- equal_to = <gearpy.utils.stop_condition.operator.EqualTo object>¶
- greater_than = <gearpy.utils.stop_condition.operator.GreaterThan object>¶
- greater_than_or_equal_to = <gearpy.utils.stop_condition.operator.GreaterThanOrEqualTo object>¶
- less_than = <gearpy.utils.stop_condition.operator.LessThan object>¶
- less_than_or_equal_to = <gearpy.utils.stop_condition.operator.LessThanOrEqualTo object>¶
- property operator: OperatorBase¶
The comparison operator to use to check if the stop condition is valid.
The available operators are:
StopCondition.greater_thanto check if thesensorvalue is greater than thethresholdvalue,StopCondition.greater_than_or_equal_toto check if thesensorvalue is greater than or equal to thethresholdvalue,StopCondition.equal_toto check if thesensorvalue is equal to thethresholdvalue,StopCondition.less_thanto check if thesensorvalue is less than thethresholdvalue,StopCondition.less_than_or_equal_toto check if thesensorvalue is less than or equal to thethresholdvalue.
Returns¶
OperatorBaseThe comparison operator to use to check if the stop condition is valid.
Raises
TypeErrorIf
operatoris not an instance ofOperatorBase.
- property sensor: SensorBase¶
The sensor to be monitored to check if the stop condition is valid.
Returns¶
SensorBaseThe sensor to be monitored to check if the stop condition is valid.
Raises
TypeErrorIf
sensoris not an instance ofSensorBase.
- add_fixed_joint(master: RotatingObject, slave: RotatingObject) None¶
It creates a fixed joint between a
masterrotating object and aslaveone. The fixed joint forces the two elements to rotate at the same angular position, speed and acceleration.The
masterrotating object is closest to the powertrain driving motor (or it is actually it) and transfers the whole driving torque to theslaveone.Parameters¶
masterRotatingObjectDriving rotating object, it must be an instance of
RotatingObject.slaveRotatingObjectDriven rotating object, it must be an instance of
RotatingObject, but not an instance ofMotorBase.
Raises
TypeErrorIf
masteris not an instance ofRotatingObject,if
slaveis not an instance ofRotatingObject,if
slaveis an instance ofMotorBase.
ValueErrorIf
masterandslaveare the same rotating object.
See Also
- add_gear_mating(master: GearBase, slave: GearBase, efficiency: float | int) None¶
It creates a gear mating between two existing gears. This mating is used to compose the
Powertrain.The ratio of the angular speed of the
mastergear over the angular speed of theslavegear is equal to the ratio of theslavegear number of teeth over themastergear number of teeth.The
mastergear is closest to the motor and transfers a fraction of the driving torque to theslaveone, based on theefficiencyvalue: the higher theefficiency, the higher the fraction of transferred driving torque.Parameters¶
masterGearBaseDriving gear. It must be an instance of
GearBase.slaveGearBaseDriven gear. It must be an instance of
GearBase.efficiencyfloatorintMechanical efficiency of the gear mating. It must be a
floator anintbetween0and1.
Raises
TypeErrorValueErrorIf
masterandslaveare the same gear,if
efficiencyis not within0and1,if
masterandslavehave different values formodule(seeSpurGear.moduleorHelicalGear.module)if
masteris an instance ofHelicalGearbutslaveis not,if
slaveis an instance ofHelicalGearbutmasteris not,if both
masterandslaveare instances ofHelicalGear, but they have differentHelicalGear.helix_angle.
- add_worm_gear_mating(master: WormGear | WormWheel, slave: WormGear | WormWheel, friction_coefficient: float | int) None¶
It creates a gear mating between a worm gear and a worm wheel. This mating is used to compose the
Powertrain.The
mastergear is closest to the motor and transfers a fraction of the driving torque to theslaveone, based on the mating efficiency, which depends on thefriction_coefficient: the higher thefriction_coefficient, the lower the fraction of transferred driving torque.Parameters¶
masterWormGearorWormWheelDriving gear. It must be an instance of
WormGearorWormWheel, but different fromslave.slaveWormGearorWormWheelDriven gear. It must be an instance of
WormGearorWormWheel, but different frommaster.friction_coefficientfloatorintStatic friction coefficient of the gear mating. It must be a
floator anintbetween0and1.
Raises
TypeErrorValueErrorIf
friction_coefficientis not within0and1,if
masterandslavehave different values forpressure_angle(seeWormGear.pressure_angleorWormWheel.pressure_angle)
Notes
The gear ratio of the mating can be computed with the following relationship, regardless of
masterorslaveroles:\[\tau = \frac{n_z}{n_s}\]where:
\(\tau\) is the gear ratio, the ratio between the worm gear angular speed and the worm wheel angular speed,
\(n_z\) is the worm wheel number of teeth,
\(n_s\) is the worm gear number of starts.
If the
WormGearis themasterand theWormWheelis theslave, then the gear mating efficiency can be computed with the relationship:\[\eta = \frac{\cos \alpha - f \, \tan \beta}{\cos \alpha + \frac{f}{\tan \beta}}\]otherwise, if the
WormGearis theslaveand theWormWheelis themaster, then the gear mating efficiency can be computed with the relationship:\[\eta = \frac{\cos \alpha - \frac{f}{\tan \beta}}{\cos \alpha + f \, \tan \beta}\]where:
\(\eta\) is the gear mating efficiency,
\(\alpha\) is the gear pressure angle, equal for both worm gear and worm wheel (
WormGear.pressure_angleorWormWheel.pressure_angle),\(f\) is the
friction_coefficient,\(\beta\) is the gear helix angle (
WormGear.helix_angleorWormWheel.helix_angle).
The mating self-locking condition can be checked as:
\[f > \cos \alpha \, \tan \beta\]
- dc_motor_characteristics_animation(motor: DCMotor, time: list[Time], interval: float | int | None = 200, torque_speed_curve: bool | None = True, torque_current_curve: bool | None = True, angular_speed_unit: str | None = 'rad/s', torque_unit: str | None = 'Nm', current_unit: str | None = 'A', figsize: tuple | None = None, line_color: str | None = None, marker_color: str | None = None, marker_size: float | int | None = None, padding: float | int | None = 0.1, show: bool | None = True) FuncAnimation¶
It generates an animation of a
DCMotortorque-speed and torque-current characteristic curves and relative working points during the simulation.Each simulated time step is a frame on the animation.
It generates two subplots, one for each characteristic curve. It is possible to isolate a single characteristic to be plotted with optional parameters
torque_speed_curveandtorque_current_curve.The characteristic curves can be modified by the motor pulse width modulation
DCMotor.pwm.Plotted values’ units are managed with optional parameters
angular_speed_unit,torque_unitandcurrent_unit.Aesthetic parameters are managed with optional parameters
figsize,line_color,marker_color,marker_sizeandpadding.Parameters¶
motorDCMotorDC motor whose characteristic curves and working point have to be animated.
timelistThe list of
Timecomputed by the solver.intervalfloatorint, optionalDelay between animation frames in milliseconds. If not provided defaults to
200.torque_speed_curvebool, optionalWhether to plot the torque-speed characteristic curve. Default is
True.torque_current_curvebool, optionalWhether to plot the torque-current characteristic curve. Default is
True.angular_speed_unitstr, optionalSymbol of the unit of measurement to which convert the angular speed values in the plot. It must be a string. Default is
'rad/s'. SeeAngularSpeed.unitfor more details.torque_unitstr, optionalSymbol of the unit of measurement to which convert the torque values in the plot. It must be a string. Default is
'Nm'. SeeTorque.unitfor more details.current_unitstr, optionalSymbol of the unit of measurement to which convert the electric current values in the plot. It must be a string. Default is
'A'. SeeCurrent.unitfor more details.figsizetuple, optionalWidth and height of the window size, in inches. If not provided defaults to
[6.4, 4.8].line_colorstr, optionalColor of the characteristic curve lines. If not provided defaults to
'#1f77b4'.marker_colorstr, optionalColor of the motor working point marker. If not provided defaults to
'#ff7f0e'.marker_sizefloatorint, optionalSize, in points, of the motor working point marker. If not provided defaults to
6.paddingfloatorint, optionalExtra-space to be taken around each motor characteristics extreme points. It is expressed in percent points of the extreme point value. Default is
0.1, so it is taken 10% space around each characteristic extreme points.showbool, optionalWhether to show the animation. Default is
True.
Raises
TypeErrorIf
motoris not an instance ofDCMotor,if
timeis not alist,if an element of
timeis not an instance ofTime,if
torque_speed_curveis not abool,if
torque_current_curveis not abool,if
angular_speed_unitis not astr,if
torque_unitis not astr,if
current_unitis not astr,if
figsizeis not atuple,if
line_coloris not astr,if
marker_coloris not astr,if
showis not abool.
ValueErrorIf
timeis an emptylist,if both
torque_speed_curveandtorque_current_curveare set toFalse,if
torque_current_curveis set toTruebutmotorcannot computeDCMotor.electric_currentproperty,if
figsizehas not exactly two elements: one for width and the other for height,if
paddingis negative.
- export_time_variables(rotating_object: RotatingObject, file_path: str, time_array: list[Time], time_unit: str | None = 'sec', angular_position_unit: str | None = 'rad', angular_speed_unit: str | None = 'rad/s', angular_acceleration_unit: str | None = 'rad/s^2', torque_unit: str | None = 'Nm', driving_torque_unit: str | None = 'Nm', load_torque_unit: str | None = 'Nm', force_unit: str | None = 'N', stress_unit: str | None = 'MPa', current_unit: str | None = 'A') None¶
It xports the computed time variables of a rotating object to a file.
The exported file is a
.csvfile. The time variables are exported in a tabular form, in which each column is a time variable and each row is a simulated time step. The columns are separated by a comma. The first column reports the simulated time steps and the first row reports the column names.Parameters¶
rotating_objectRotatingObjectThe rotating object whose time variables are to be exported.
file_pathstrPath to the file in which to save the time variables. It must be a non-empty
str.time_arraylistSimulated time steps. It must be a non-empty
list.time_unitstr, optionalSymbol of the unit of measurement to which convert the time values in the exported file. It must be a
str. Default is'sec'. SeeTime.unitfor more details.angular_position_unitstr, optionalSymbol of the unit of measurement to which convert the angular position values in the exported file. It must be a
str. Default is'rad'. SeeAngularPosition.unitfor more details.angular_speed_unitstr, optionalSymbol of the unit of measurement to which convert the angular speed values in the exported file. It must be a
str. Default is'rad/s'. SeeAngularSpeed.unitfor more details.angular_acceleration_unitstr, optionalSymbol of the unit of measurement to which convert the angular acceleration values in the exported file. It must be a
str. Default is'rad/s^2'. SeeAngularAcceleration.unitfor more details.torque_unitstr, optionalSymbol of the unit of measurement to which convert the torque values in the exported file. It must be a
str. Default is'Nm'. SeeTorque.unitfor more details.driving_torque_unitstr, optionalSymbol of the unit of measurement to which convert the torque values in the exported file. It must be a
str. Default is'Nm'. SeeTorque.unitfor more details.load_torque_unitstr, optionalSymbol of the unit of measurement to which convert the torque values in the exported file. It must be a
str. Default is'Nm'. SeeTorque.unitfor more details.force_unitstr, optionalSymbol of the unit of measurement to which convert the force values in the exported file. It must be a
str. Default is'N'. SeeForce.unitfor more details.stress_unitstr, optionalSymbol of the unit of measurement to which convert the stress values in the exported file. It must be a
str. Default is'MPa'. SeeStress.unitfor more details.current_unitstr, optionalSymbol of the unit of measurement to which convert the electric current values in the exported file. It must be a
str. Default is'A'. SeeCurrent.unitfor more details.
Raises
TypeErrorIf
rotating_objectis not an instance ofRotatingObject,if
file_pathis not astr,if
time_arrayis not alist,if an element of
time_arrayis not an instance ofTimeor astr,if
time_unitis not astr,if
angular_position_unitis not astr,if
angular_speed_unitis not astr,if
angular_acceleration_unitis not astr,if
torque_unitis not astr,if
driving_torque_unitis not astr,if
load_torque_unitis not astr,if
force_unitis not astr,if
stress_unitis not astr,if
current_unitis not astr.
ValueError