From 3e57afece9a84d99cc35812d96e5c84fc8aa37fd Mon Sep 17 00:00:00 2001 From: ft-Demo <fischertechnik-team@fischer.de> Date: Tue, 8 Nov 2022 10:12:04 +0000 Subject: [PATCH] commit by robo pro coding --- lib/NodeRED.blockly | 91 ++++++++++++++++++++++++++++++++++----------- lib/NodeRED.py | 13 +++++-- lib/SLD.blockly | 77 +++++++++++++++++++++++++++----------- lib/SLD.py | 50 +++++++++++++++---------- 4 files changed, 166 insertions(+), 65 deletions(-) diff --git a/lib/NodeRED.blockly b/lib/NodeRED.blockly index 502da58..4bc0991 100644 --- a/lib/NodeRED.blockly +++ b/lib/NodeRED.blockly @@ -11,9 +11,9 @@ <variable id="#ZVIt[,H@%Ms3XJhPF7y">gtyp_Setup_i_Pos_Selection</variable> <variable id="zOwa}}!Kwpb%%^EeOYAT">payload</variable> <variable id="gE_}aCN*#~^yOmZlqKv9">gtyp_Setup_x_Color_Sensor_Calibration</variable> - <variable id="cTcpwCvGLYg4_[qJf{CM">state_positioning</variable> <variable id=")XfA{xXx7sN)MA=qSY=H">gtyp_Setup_i_Color_Sensor_Selection</variable> <variable id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</variable> + <variable id="cTcpwCvGLYg4_[qJf{CM">state_positioning</variable> <variable id="aQ:d%c!ilWYQz|GZ5N0~">gtyp_Setup_w_Threshold_White_Red</variable> <variable id="A{`)A3~(6e.5r^y~X;S1">gtyp_Setup_w_Threshold_Red_Blue</variable> <variable id="1R^uniMizt=l7#?^bm$c">gtyp_Setup_di_Pos_Rotate</variable> @@ -120,10 +120,10 @@ <block type="variables_set" id=";b,Xj$#gxX+raC)3wD6k"> <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> <value name="VALUE"> - <block type="import_function_return" id="%TX;`Di-?u.+9)/@Nv{#"> - <mutation parentId="$]uSxm9]*Qu3iZl~w~MW"/> - <field name="name">readColorValue</field> - <data>$]uSxm9]*Qu3iZl~w~MW</data> + <block type="import_function_return" id="XuyjM1.@;#HA+@mFrv/e"> + <mutation parentId="DG!Qx,-mV.+.OJkbzR!G"/> + <field name="name">get_detectedColor</field> + <data>DG!Qx,-mV.+.OJkbzR!G</data> </block> </value> <next> @@ -1123,6 +1123,13 @@ <field name="BOOL">FALSE</field> </shadow> </value> + <next> + <block type="import_function_noreturn" id="X}$nC/,(jef7FiXlsu~W"> + <mutation parentId="g=6%Ka9Y1qYH|_c:bu9]"/> + <field name="name">startSLD</field> + <data>g=6%Ka9Y1qYH|_c:bu9]</data> + </block> + </next> </block> </next> </block> @@ -1199,6 +1206,13 @@ <field name="BOOL">FALSE</field> </shadow> </value> + <next> + <block type="import_function_noreturn" id="u1)G_=d%!+QY7JCi149-"> + <mutation parentId="g=6%Ka9Y1qYH|_c:bu9]"/> + <field name="name">startSLD</field> + <data>g=6%Ka9Y1qYH|_c:bu9]</data> + </block> + </next> </block> </next> </block> @@ -1275,6 +1289,13 @@ <field name="BOOL">FALSE</field> </shadow> </value> + <next> + <block type="import_function_noreturn" id="}MYfC9)%|HWIiwZveWkf"> + <mutation parentId="g=6%Ka9Y1qYH|_c:bu9]"/> + <field name="name">startSLD</field> + <data>g=6%Ka9Y1qYH|_c:bu9]</data> + </block> + </next> </block> </next> </block> @@ -1707,6 +1728,13 @@ </next> </block> </statement> + <next> + <block type="import_function_noreturn" id="[XY^fpiM9?lE|wqa=(Xv"> + <mutation parentId="[VeFt!3!rIfU$B.I(^(^"/> + <field name="name">stopSLD</field> + <data>[VeFt!3!rIfU$B.I(^(^</data> + </block> + </next> </block> </next> </block> @@ -1818,6 +1846,13 @@ <field name="NUM">0</field> </block> </value> + <next> + <block type="import_function_noreturn" id="i-1D#zm];#0H7ww9m4Yg"> + <mutation parentId="[VeFt!3!rIfU$B.I(^(^"/> + <field name="name">stopSLD</field> + <data>[VeFt!3!rIfU$B.I(^(^</data> + </block> + </next> </block> </next> </block> @@ -1938,6 +1973,13 @@ </value> </block> </value> + <next> + <block type="import_function_noreturn" id="ti#5)tatK*KSfQ?~f~AW"> + <mutation parentId="[VeFt!3!rIfU$B.I(^(^"/> + <field name="name">stopSLD</field> + <data>[VeFt!3!rIfU$B.I(^(^</data> + </block> + </next> </block> </next> </block> @@ -2075,37 +2117,44 @@ </block> </value> <next> - <block type="variables_set" id="9x5:lZLpAx9wmr9(j=_s"> - <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> + <block type="variables_set" id="S2G]dx)f~jgzuW0k^kNp"> + <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> <value name="VALUE"> - <block type="math_number" id="gz]b+,C1~FgTaNK~=r,5"> + <block type="math_number" id="C=d/[ap2uVxKy:e^MI:Z"> <field name="NUM">0</field> </block> </value> <next> - <block type="variables_set" id="S2G]dx)f~jgzuW0k^kNp"> - <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> + <block type="variables_set" id="9x5:lZLpAx9wmr9(j=_s"> + <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> <value name="VALUE"> - <block type="math_number" id="C=d/[ap2uVxKy:e^MI:Z"> + <block type="math_number" id="gz]b+,C1~FgTaNK~=r,5"> <field name="NUM">0</field> </block> </value> <next> - <block type="variables_set" id="K8LkNm#7hFX|dJ!z6$7i"> - <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> + <block type="variables_set" id="=~039uS6s1=!E3E6zijO"> + <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> <value name="VALUE"> - <block type="math_number" id="ke^5kEWYDF/S$ln@)=%_"> + <block type="math_number" id="s(Z7II`Fld+4)J.OPb9T"> <field name="NUM">0</field> </block> </value> <next> - <block type="variables_set" id="=~039uS6s1=!E3E6zijO"> - <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> + <block type="variables_set" id="K8LkNm#7hFX|dJ!z6$7i"> + <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> <value name="VALUE"> - <block type="math_number" id="s(Z7II`Fld+4)J.OPb9T"> + <block type="math_number" id="ke^5kEWYDF/S$ln@)=%_"> <field name="NUM">0</field> </block> </value> + <next> + <block type="import_function_noreturn" id="IJy_!,2i)(ygN%+GHla}"> + <mutation parentId="[VeFt!3!rIfU$B.I(^(^"/> + <field name="name">stopSLD</field> + <data>[VeFt!3!rIfU$B.I(^(^</data> + </block> + </next> </block> </next> </block> @@ -2598,7 +2647,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="$jNNx1Oeez9#x~eQYP}z" x="0" y="7551"> + <block type="procedures_defnoreturn" id="$jNNx1Oeez9#x~eQYP}z" x="0" y="7747"> <field name="NAME">initMQTTLocal</field> <statement name="STACK"> <block type="variables_set" id="_C*fQdBXqrGb1uUWi?_1"> @@ -2694,7 +2743,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="R4vMowGJ0I?IYs_!-IwU" x="0" y="8063"> + <block type="procedures_defnoreturn" id="R4vMowGJ0I?IYs_!-IwU" x="0" y="8259"> <field name="NAME">thread_MQTTLocal</field> <statement name="STACK"> <block type="util_python" id="IiRVsU4_~OPjE]@(VC;/" inline="true"> @@ -2710,7 +2759,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="8u`{W^33E#gAnZ}n#.-h" x="0" y="8323"> + <block type="procedures_defnoreturn" id="8u`{W^33E#gAnZ}n#.-h" x="0" y="8519"> <mutation> <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="_4Lef8L=}Do}$CNf.$X3"/> <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid=".~Cx#%[dpU*oKQFZ*1}G"/> @@ -2948,7 +2997,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="a]0!I}Zd7AawL:mU%,P1" x="0" y="9117"> + <block type="procedures_defnoreturn" id="a]0!I}Zd7AawL:mU%,P1" x="0" y="9313"> <mutation> <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="`n4M@;+Y^Ab44Gi.YYy-"/> <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid="]gLOm[vhCT0;N+Cp[1?5"/> diff --git a/lib/NodeRED.py b/lib/NodeRED.py index 97f2c17..84f8994 100644 --- a/lib/NodeRED.py +++ b/lib/NodeRED.py @@ -56,7 +56,7 @@ def thread_updateColorValue(): client.publish(topic='gtyp_Setup/w_Actual_ColorValue', payload=gtyp_Setup_w_Actual_ColorValue, qos=2, retain=False) elif gtyp_Setup_i_Color_Sensor_Selection == 2: logging.debug('2') - gtyp_Setup_w_Actual_ColorValue = readColorValue() + gtyp_Setup_w_Actual_ColorValue = get_detectedColor() client.publish(topic='gtyp_Setup/w_Actual_ColorValue', payload=gtyp_Setup_w_Actual_ColorValue, qos=2, retain=False) time.sleep(1) @@ -147,14 +147,17 @@ def processReceivedMessage(topic, m_decode): logging.debug('blue') set_calibvalue_blue(gtyp_Setup_w_Actual_ColorValue) client.publish(topic='gtyp_Setup/w_Calib_ColorValue_Blue', payload=(get_calibvalue_list())[2], qos=2, retain=False) + startSLD() elif topic == 'gtyp_Setup/x_Set_Calib_Value_Color_Red': logging.debug('red') set_calibvalue_red(gtyp_Setup_w_Actual_ColorValue) client.publish(topic='gtyp_Setup/w_Calib_ColorValue_Red', payload=(get_calibvalue_list())[1], qos=2, retain=False) + startSLD() elif topic == 'gtyp_Setup/x_Set_Calib_Value_Color_White': logging.debug('white') set_calibvalue_white(gtyp_Setup_w_Actual_ColorValue) client.publish(topic='gtyp_Setup/w_Calib_ColorValue_White', payload=(get_calibvalue_list())[0], qos=2, retain=False) + startSLD() elif topic == 'gtyp_Setup/x_Calculate_Value_Color': logging.debug('calculate') calculate_thresh() @@ -178,6 +181,7 @@ def processReceivedMessage(topic, m_decode): client.publish(topic='gtyp_SLD/w_Threshold_Red_Blue', payload=gtyp_SLD_w_Threshold_Red_Blue, qos=2, retain=False) else: pass + stopSLD() elif topic == 'gtyp_Setup/x_Color_Sensor_Calibration': logging.debug('calibrate color sensor') gtyp_Setup_x_Color_Sensor_Calibration = m_decode @@ -189,6 +193,7 @@ def processReceivedMessage(topic, m_decode): set_lights_mode(0) display.set_attr("txt_status_indicator.active", str(False).lower()) gtyp_Setup_w_Actual_ColorValue = 0 + stopSLD() elif topic == 'gtyp_Setup/i_Color_Sensor_Selection': logging.debug('sensor selection') gtyp_Setup_i_Color_Sensor_Selection = int(m_decode, 10) @@ -197,6 +202,7 @@ def processReceivedMessage(topic, m_decode): gtyp_Setup_w_Actual_ColorValue = readDPSColorValue() gtyp_SSC_w_Threshold_Red_Blue = (get_calib_data_DPS())[0] gtyp_SSC_w_Threshold_White_Red = (get_calib_data_DPS())[1] + stopSLD() elif gtyp_Setup_i_Color_Sensor_Selection == 2: logging.debug('2') gtyp_Setup_w_Actual_ColorValue = readColorValue() @@ -209,10 +215,11 @@ def processReceivedMessage(topic, m_decode): set_calibvalue_white(0) set_calibvalue_red(0) set_calibvalue_blue(0) - gtyp_SSC_w_Threshold_Red_Blue = 0 gtyp_SSC_w_Threshold_White_Red = 0 - gtyp_SLD_w_Threshold_Red_Blue = 0 + gtyp_SSC_w_Threshold_Red_Blue = 0 gtyp_SLD_w_Threshold_White_Red = 0 + gtyp_SLD_w_Threshold_Red_Blue = 0 + stopSLD() client.publish(topic='gtyp_Setup/w_Actual_ColorValue', payload=gtyp_Setup_w_Actual_ColorValue, qos=2, retain=False) client.publish(topic='gtyp_Setup/w_Calib_ColorValue_White', payload=(get_calibvalue_list())[0], qos=2, retain=False) client.publish(topic='gtyp_Setup/w_Calib_ColorValue_Red', payload=(get_calibvalue_list())[1], qos=2, retain=False) diff --git a/lib/SLD.blockly b/lib/SLD.blockly index d67a47a..882679f 100644 --- a/lib/SLD.blockly +++ b/lib/SLD.blockly @@ -4,9 +4,10 @@ <variable id="x?rbx}Z!7+Jx9E.L=:pX">_code</variable> <variable id="Hq*BSR/(QEo9c0kQRW{y">_active</variable> <variable id="1X|m)*QO^oo}EfHf=nBO">speed</variable> + <variable id="ey.@ye[RiHweS+e|GIKG">started</variable> <variable id="78bW9521)(I[oMydfNIz">state_code</variable> <variable id="[V))lfBm^j7t@3LJVWGf">state_active</variable> - <variable id="ey.@ye[RiHweS+e|GIKG">started</variable> + <variable id="caAu/l+mpfP^b1#tA{Kr">detectedColorValue</variable> <variable id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</variable> <variable id="?]F?rtn:F#wq@5Ag|9yE">thresh_white_red_defaults</variable> <variable id="Krv1?O$_~Yha=/]3-u{i">thresh_red_blue_defaults</variable> @@ -15,7 +16,6 @@ <variable id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</variable> <variable id="g%%DHmT#UX~.YdQn3gcf">_ts_state</variable> <variable id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</variable> - <variable id="caAu/l+mpfP^b1#tA{Kr">detectedColorValue</variable> <variable id="?Hi+81vv*K@yZim!8fD_">lastColorValue</variable> <variable id="_?QtuoxDM2ZJ#rQLHhaQ">counter</variable> <variable id="Cb}mUgnt@Vc|BuR6[;{s">lastStateCounterSwitch</variable> @@ -36,7 +36,28 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="]$}!d~iPi$faCfYn-,02" x="0" y="210"> + <block type="procedures_defnoreturn" id="[VeFt!3!rIfU$B.I(^(^" x="0" y="210"> + <field name="NAME">stopSLD</field> + <statement name="STACK"> + <block type="variables_set" id="7LOa@K(:,jIDi3D_cppv"> + <field name="VAR" id="ey.@ye[RiHweS+e|GIKG">started</field> + <value name="VALUE"> + <block type="logic_boolean" id=";urBD?;LnP-Pr0.C1}|+"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </statement> + </block> + <block type="procedures_defreturn" id="DG!Qx,-mV.+.OJkbzR!G" x="0" y="319"> + <field name="NAME">get_detectedColor</field> + <value name="RETURN"> + <block type="variables_get" id=")O%dQpuFd{FuGTm%_AM("> + <field name="VAR" id="caAu/l+mpfP^b1#tA{Kr">detectedColorValue</field> + </block> + </value> + </block> + <block type="procedures_defnoreturn" id="]$}!d~iPi$faCfYn-,02" x="0" y="438"> <field name="NAME">thread_SLD</field> <statement name="STACK"> <block type="util_python" id="or=tulIX]{S?#ofKV+]h" inline="true"> @@ -171,8 +192,22 @@ <block type="controls_whileUntil" id="Y3)fnloS|8,DEOQG{n2-"> <field name="MODE">UNTIL</field> <value name="BOOL"> - <block type="procedures_callreturn" id="mewh8q@GplOPE!2od1f?"> - <mutation name="isEjectionTriggered"/> + <block type="logic_operation" id="b86)=u[1_Vvq({h(zY2d" inline="false"> + <field name="OP">OR</field> + <value name="A"> + <block type="procedures_callreturn" id="mewh8q@GplOPE!2od1f?"> + <mutation name="isEjectionTriggered"/> + </block> + </value> + <value name="B"> + <block type="logic_negate" id="v99bx#LrCQ/9GaTKrUb0"> + <value name="BOOL"> + <block type="variables_get" id="sh96A,Bv1[6MB0!88(!o"> + <field name="VAR" id="ey.@ye[RiHweS+e|GIKG">started</field> + </block> + </value> + </block> + </value> </block> </value> <statement name="DO"> @@ -629,7 +664,7 @@ </block> </statement> </block> - <block type="procedures_defreturn" id="x=/1p3KO=Q%QK7t2K5l%" x="0" y="2237"> + <block type="procedures_defreturn" id="x=/1p3KO=Q%QK7t2K5l%" x="0" y="2493"> <field name="NAME">get_calib_data_SLD_defaults</field> <statement name="STACK"> <block type="util_python" id="cO!#.ICg79WkS?A?cG[j" inline="true"> @@ -652,7 +687,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="b|1;0mU=wNNO2Ry{f6,Z" x="0" y="2398"> + <block type="procedures_defreturn" id="b|1;0mU=wNNO2Ry{f6,Z" x="0" y="2654"> <field name="NAME">get_calib_data_SLD</field> <statement name="STACK"> <block type="util_python" id="t;Zg(`vb3R)aQZ])LhpC" inline="true"> @@ -675,7 +710,7 @@ </block> </value> </block> - <block type="procedures_defnoreturn" id="3Qf0~|~$oG8z5tP{6Km;" x="0" y="2559"> + <block type="procedures_defnoreturn" id="3Qf0~|~$oG8z5tP{6Km;" x="0" y="2815"> <mutation> <arg name="_data" varid="$E/GDp,,dwQrGbs7N*=C" argid="^}Z*XZLpIfstV5L7ggN|"/> </mutation> @@ -731,7 +766,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="gsD|}/@_.f.D_8KfM;**" x="0" y="2778"> + <block type="procedures_defnoreturn" id="gsD|}/@_.f.D_8KfM;**" x="0" y="3034"> <mutation> <arg name="_code" varid="x?rbx}Z!7+Jx9E.L=:pX" argid=",ZCb|vi(m3g0A4u*(!{`"/> <arg name="_active" varid="Hq*BSR/(QEo9c0kQRW{y" argid="mqa@Al(.5xeP*B]Jl`8%"/> @@ -814,7 +849,7 @@ </block> </statement> </block> - <block type="procedures_defreturn" id="eO[xQ[akMe*EVjm,{7m0" x="0" y="3123"> + <block type="procedures_defreturn" id="eO[xQ[akMe*EVjm,{7m0" x="0" y="3379"> <field name="NAME">get_state_code_SLD</field> <statement name="STACK"> <block type="util_python" id="(HOmJd*Bw@nwPNCHY0mu" inline="true"> @@ -827,7 +862,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="wpN6M:c*2cKgK+MM+G.W" x="0" y="3256"> + <block type="procedures_defreturn" id="wpN6M:c*2cKgK+MM+G.W" x="0" y="3512"> <field name="NAME">get_state_active_SLD</field> <statement name="STACK"> <block type="util_python" id="Ht%%JB`?HUum}h9K*t-9" inline="true"> @@ -840,7 +875,7 @@ </block> </value> </block> - <block type="procedures_defnoreturn" id="%z2U,T)U0wd2S}!Lot[s" x="0" y="3389"> + <block type="procedures_defnoreturn" id="%z2U,T)U0wd2S}!Lot[s" x="0" y="3645"> <mutation> <arg name="speed" varid="1X|m)*QO^oo}EfHf=nBO" argid="pePpK@*+w{Ry]Ltz(Z95"/> </mutation> @@ -866,7 +901,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="IKFw+yZgK[}QgIvIQk]A" x="0" y="3560"> + <block type="procedures_defnoreturn" id="IKFw+yZgK[}QgIvIQk]A" x="0" y="3816"> <field name="NAME">ejectWhite</field> <statement name="STACK"> <block type="util_python" id="L9].u`N0?,H+tU)=o?Me" inline="true"> @@ -942,7 +977,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="M^8-tj!Sv{KHcQSAS;$K" x="0" y="3927"> + <block type="procedures_defnoreturn" id="M^8-tj!Sv{KHcQSAS;$K" x="0" y="4183"> <field name="NAME">ejectRed</field> <statement name="STACK"> <block type="util_python" id="?:UCrMJUl%q(jYcN8(IE" inline="true"> @@ -1018,7 +1053,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="YLSy9_KOy{GM#LBmqJ8x" x="0" y="4294"> + <block type="procedures_defnoreturn" id="YLSy9_KOy{GM#LBmqJ8x" x="0" y="4550"> <field name="NAME">ejectBlue</field> <statement name="STACK"> <block type="util_python" id="n-s%L0Ie7qkf@WU-[H8o" inline="true"> @@ -1094,7 +1129,7 @@ </block> </statement> </block> - <block type="procedures_defreturn" id="0.,m:~DVx{zBe-|XxpG-" x="0" y="4661"> + <block type="procedures_defreturn" id="0.,m:~DVx{zBe-|XxpG-" x="0" y="4917"> <field name="NAME">isColorSensorTriggered</field> <statement name="STACK"> <block type="util_python" id="23n|f!bBfO#m?@_HlHB}" inline="true"> @@ -1108,7 +1143,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="}*yI=aY}$^7875;e4Wo_" x="0" y="4794"> + <block type="procedures_defreturn" id="}*yI=aY}$^7875;e4Wo_" x="0" y="5050"> <field name="NAME">isEjectionTriggered</field> <statement name="STACK"> <block type="util_python" id="wrT1c1;%@kF-Riy28O;." inline="true"> @@ -1122,7 +1157,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="Fys9OK!K-FNH-W0o}@h," x="0" y="4927"> + <block type="procedures_defreturn" id="Fys9OK!K-FNH-W0o}@h," x="0" y="5183"> <field name="NAME">isWhite</field> <statement name="STACK"> <block type="util_python" id="h?(Tr@S1VYchJ5e6())[" inline="true"> @@ -1136,7 +1171,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="iE@eN47vK?la`*X4EQ-8" x="0" y="5060"> + <block type="procedures_defreturn" id="iE@eN47vK?la`*X4EQ-8" x="0" y="5316"> <field name="NAME">isRed</field> <statement name="STACK"> <block type="util_python" id="fN{]~9g]|*Kx,bpmy_i$" inline="true"> @@ -1150,7 +1185,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="w|KTmb#01-L]2ZG4mz)b" x="0" y="5193"> + <block type="procedures_defreturn" id="w|KTmb#01-L]2ZG4mz)b" x="0" y="5449"> <field name="NAME">isBlue</field> <statement name="STACK"> <block type="util_python" id="U(Y(8WN=vCJzgw~oLdbs" inline="true"> @@ -1164,7 +1199,7 @@ </block> </value> </block> - <block type="procedures_defreturn" id="$]uSxm9]*Qu3iZl~w~MW" x="0" y="5326"> + <block type="procedures_defreturn" id="$]uSxm9]*Qu3iZl~w~MW" x="0" y="5582"> <field name="NAME">readColorValue</field> <statement name="STACK"> <block type="util_python" id="JSm|]EZ0cs6:5)g-C23(" inline="true"> diff --git a/lib/SLD.py b/lib/SLD.py index 917b934..71ea40b 100644 --- a/lib/SLD.py +++ b/lib/SLD.py @@ -11,6 +11,7 @@ _code = None _active = None speed = None started = None +detectedColorValue = None state_code = None state_active = None calibvalue_white = None @@ -21,19 +22,28 @@ thresh_red_blue = None calibvalue_red = None _ts_state = None calibvalue_blue = None -detectedColorValue = None lastColorValue = None counter = None lastStateCounterSwitch = None def startSLD(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch started = True +def stopSLD(): + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch + started = False + + +def get_detectedColor(): + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch + return detectedColorValue + + def thread_SLD(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, '-') calibvalue_white = 0 calibvalue_red = 0 @@ -50,7 +60,7 @@ def thread_SLD(): _set_state_SLD(2, 1) detectedColorValue = 3000 setConvBeltSpeedSLD(512) - while not isEjectionTriggered(): + while not (isEjectionTriggered() or not started): lastColorValue = readColorValue() if lastColorValue < detectedColorValue: detectedColorValue = lastColorValue @@ -93,26 +103,26 @@ def thread_SLD(): def get_calib_data_SLD_defaults(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, '-') return [thresh_white_red_defaults, thresh_red_blue_defaults] def get_calib_data_SLD(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, '-') return [thresh_white_red, thresh_red_blue] def set_calib_data_SLD(_data): - global _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, _data) thresh_white_red = _data[0] thresh_red_blue = _data[1] def _set_state_SLD(_code, _active): - global _data, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') if state_code != _code or state_active != _active: _ts_state = 0 @@ -121,26 +131,26 @@ def _set_state_SLD(_code, _active): def get_state_code_SLD(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return state_code def get_state_active_SLD(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return state_active def setConvBeltSpeedSLD(speed): - global _data, _code, _active, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, 'speed: %d', speed) TXT_SLD_E5_M1_encodermotor.set_speed(int(speed), Motor.CW) TXT_SLD_E5_M1_encodermotor.start() def ejectWhite(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, '-') TXT_SLD_E5_O5_magnetic_valve.on() time.sleep(0.5) @@ -154,7 +164,7 @@ def ejectWhite(): def ejectRed(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, '-') TXT_SLD_E5_O6_magnetic_valve.on() time.sleep(0.5) @@ -168,7 +178,7 @@ def ejectRed(): def ejectBlue(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE, '-') TXT_SLD_E5_O7_magnetic_valve.on() time.sleep(0.5) @@ -182,37 +192,37 @@ def ejectBlue(): def isColorSensorTriggered(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return TXT_SLD_E5_I1_photo_transistor.is_dark() def isEjectionTriggered(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return TXT_SLD_E5_I3_photo_transistor.is_dark() def isWhite(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return TXT_SLD_E5_I6_photo_transistor.is_dark() def isRed(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return TXT_SLD_E5_I7_photo_transistor.is_dark() def isBlue(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return TXT_SLD_E5_I8_photo_transistor.is_dark() def readColorValue(): - global _data, _code, _active, speed, started, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch + global _data, _code, _active, speed, started, detectedColorValue, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, lastColorValue, counter, lastStateCounterSwitch logging.log(logging.TRACE0, '-') return TXT_SLD_E5_I2_color_sensor.get_voltage() -- GitLab