Coverage for D:\Ralf Gerlich\git\modypy\modypy\blocks\elmech.py : 0%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2A collection fo electro-mechanical blocks.
3"""
5import math
7from modypy.model import Block, Port, SignalState, State, signal_method
10class DCMotor(Block):
11 """A DC motor with external load.
13 This model has the following inputs:
15 ``voltage``
16 representing the terminal voltage on the motor
17 ``external_torque``
18 representing the braking torque of the external load
20 It has two outputs:
22 ``speed_rps``
23 representing the speed in RPS
24 ``torque``
25 representing the torque generated by the motor
27 The parameters are:
29 ``motor_constant``
30 the motor constant in usually Vs/rad
31 ``resistance``
32 the internal resistance of the coil in Ohms
33 ``inductance``
34 the inductance of the coil in Henry
35 ``moment_of_inertia``
36 the moment of inertia of the rotor and the load in ``kg*m^2``
38 The model expresses the following equations of motion::
40 U(t) = motor_constant * omega(t) + resistance * i(t)
41 + inductance * di(t)/dt
42 motor_constant * I(t) = moment_of_inertia * domega(t)/dt + tau_ext(t)
43 """
45 def __init__(self,
46 parent,
47 motor_constant,
48 resistance,
49 inductance,
50 moment_of_inertia,
51 initial_omega=0, initial_current=0):
52 Block.__init__(self, parent)
54 self.motor_constant = motor_constant
55 self.resistance = resistance
56 self.inductance = inductance
57 self.moment_of_inertia = moment_of_inertia
59 self.voltage = Port()
60 self.external_torque = Port()
62 self.omega = State(self,
63 derivative_function=self.omega_dot,
64 initial_condition=initial_omega)
65 self.current = SignalState(self,
66 derivative_function=self.current_dot,
67 initial_condition=initial_current)
69 def omega_dot(self, data):
70 """Calculates the derivative of the speed in rad/s^2
71 """
72 current = self.current(data)
73 tau_ext = self.external_torque(data)
74 return (self.motor_constant * current - tau_ext) \
75 / self.moment_of_inertia
77 def current_dot(self, data):
78 """Calculates the derivative of the current in A/s
79 """
80 omega = self.omega(data)
81 current = self.current(data)
82 voltage = self.voltage(data)
84 return (voltage
85 - self.motor_constant * omega
86 - self.resistance * current) / self.inductance
88 @signal_method
89 def speed_rps(self, data):
90 """Calculates the current speed in RPS
91 """
92 return self.omega(data) / (2 * math.pi)
94 @signal_method
95 def torque(self, data):
96 """Calculates the torque generated by the motor in kg*m/s^2
97 """
98 return self.motor_constant * self.current(data)