Module SimulatedProcess
[hide private]
[frames] | no frames]

Source Code for Module SimulatedProcess

 1  # -*- coding: iso-8859-1 -*- 
 2   
 3  """ 
 4   Realizes the simulation of the inverted pendulum. 
 5   
 6   Calculates the simulation in steps of about 10ms. 
 7   (So we don't need the correct differential equations.) 
 8    
 9   Beside the movement is also tries to model static and slipping friction. 
10   Both values are set to the same value and simply modeled as force against  
11   the movement direction. If the friction force is larger then the driving  
12   force (external or own mass in movement) the movement stops. 
13   
14   Also contains some modifiable parameters. 
15  """ 
16  from simulation import Process,Pendulum 
17  import math 
18   
19   
20 -class SimulatedProcess(Process.Process,Pendulum.Pendulum):
21 """Simulation of real process.""" 22 23
24 - def __init__(self):
25 """Initialize the simulation.""" 26 Process.Process.__init__(self) 27 Pendulum.Pendulum.__init__(self) 28 29 self.X = 0.0 #: position [m] 30 self.dX_dT = 0.0 #: velocity [m/s] 31 self.Phi = math.radians(45.0) #: angle [rad] 32 self.dPhi_dT = 0.0 #: angle velocity [rad/s] 33 34 self.a = 0.0 #: acceleration [m/s²] 35 36 self.l = 1.0 #: length of pendulum [m] 37 self.m = 10.0 #: mass of pendulum [kg] 38 self.M_P = 0.1 #: friction of bearing of pendulum expressed as torque [kgm²/s²=Nm] 39 self.a_W = 0.1 #: friction of car expressed as acceleration [m/s²] 40 41 self.W = 2.0 #: gain for incoming acceleration value 42 self.Z = 0.01 #: disturbance
43
44 - def setStateValues(self,dict):
45 self.X = dict["X"] 46 self.dX_dT = dict["dX_dT"] 47 self.Phi = math.radians(dict["Phi"]) 48 self.dPhi_dT = math.radians(dict["dPhi_dT"])
49
50 - def getStateValues(self,dict={}):
51 dict["X"] = self.X 52 dict["dX_dT"] = self.dX_dT 53 dict["Phi"] = math.degrees(self.Phi) 54 dict["dPhi_dT"] = math.degrees(self.dPhi_dT) 55 return dict
56
57 - def setControlValues(self,dict={}):
58 try: 59 self.a = dict["a"] 60 except KeyError: 61 pass # don't change value 62 return dict
63
64 - def getDefaultControlValues(self):
65 return { 66 "a":0.0, 67 }
68