-
Notifications
You must be signed in to change notification settings - Fork 37
/
ActuatorControllermod.py
121 lines (97 loc) · 3.78 KB
/
ActuatorControllermod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import logging
import hardwaremod
import emailmod
import actuatordbmod
import autofertilizermod
import REGandDBmod
logger = logging.getLogger("hydrosys4."+__name__)
def activateactuator(target, value, command_override=""): # return true in case the state change: activation is >0 or a different position from prevoius position.
# all the transaction are supposed to be strings
value=str(value)
# check the actuator
isok=False
out=""
if not command_override:
actuatortype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,target,hardwaremod.HW_CTRL_CMD)
actuatortypelist=actuatortype.split("/")
if actuatortypelist:
actuatortype=actuatortypelist[0]
else:
actuatortype=command_override
print (" Actuator " + actuatortype + " target " + target)
supportedactuators=["pulse","servo","stepper"]
# stepper motor
if actuatortype=="stepper":
out, isok = hardwaremod.GO_stepper_position(target,value)
if isok:
actuatordbmod.insertdataintable(target,value)
# hbridge motor
if actuatortype=="hbridge":
realvalue=value
isok=False
out=""
if value=="OPEN":
realvalue=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, target, hardwaremod.HW_CTRL_MAX)
elif value=="CLOSE":
realvalue=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME, target, hardwaremod.HW_CTRL_MIN)
if value=="STOP":
out, isok = hardwaremod.gpio_stop_hbridge(target)
else:
out, isok = hardwaremod.GO_hbridge_position(target,realvalue)
if isok:
REGandDBmod.register_output_value(target,out,saveonDB=True)
# pulse
if actuatortype=="pulse":
duration=hardwaremod.toint(value,0)
if value=="ON" or duration>0:
if value=="ON":
# act like a switch
out, isok=hardwaremod.makepulse(target,value)
# salva su database
if isok:
REGandDBmod.register_output_value(target,value)
else:
# check the fertilizer doser flag before activating the pulse
doseron=autofertilizermod.checkactivate(target,duration)
# start pulse
out, isok=hardwaremod.makepulse(target,value)
# salva su database
if isok:
REGandDBmod.register_output_value(target,value)
else:
if value=="OFF":
out , isok =hardwaremod.switchOFF(target)
else:
out, isok =hardwaremod.stoppulse(target)
print ("value is: ", value , " isOK :" , isok)
if isok:
REGandDBmod.register_output_value(target,"0",saveonDB=False)
# servo motor
if actuatortype=="servo":
out, isok = hardwaremod.servoangle(target,value,0.5)
if isok:
actuatordbmod.insertdataintable(target,value)
# photo
if actuatortype=="photo":
duration=hardwaremod.toint(value,0)
if duration>0:
isok=hardwaremod.takephoto(True)
# save action in database
if isok:
actuatordbmod.insertdataintable(target,1)
# mail
if (actuatortype=="mail+info+link")or(actuatortype=="mail+info"):
duration=hardwaremod.toint(value,0)
if duration>0:
mailtext=value
isok=emailmod.sendmail(target,"info","Automation Value:" + mailtext)
# save action in database
if isok:
actuatordbmod.insertdataintable(target,1)
return out , isok
if __name__ == '__main__':
"""
prova functions
"""
target="Relay1_1"
value="10"