Python remap INTERP_ERROR strange behaviour

More
26 Jul 2023 13:58 - 26 Jul 2023 14:04 #276302 by arabel1a
Hi everyone! I am stuck facing strange behavior in python remap. Namely:
0. TL;DR: if i uncomment `return INTERP_ERROR` line in attached remapping code, it falls with an error without executing prolog and ngc. If M66 appears before my function, it fails on M66. If not, it fails when program is started.

1. I have a machine with several tool nests. In each nest can be a tool or a clamp -- a thing that holds the material. They are located on X axis. My goal is to check if all tools and clamps are inserted correctly. Also i want to check if there is a matrix inside every tool.
2. To do that, i have a two sensor ("matrix sensor" and "clamp sensor"). They works following way. Imagine that X axis is in position of checking nest 1:
* if matrix_sensor == 1 and clamp_sensor == 1, then a tool with matrix in inserted in current nest.
* if matrix_sensor == 0 and clamp_sensor == 1, then a tool is inserted without matrix.
* if matrix_sensor = 1 and clamp_sensor ==1, there is a clamp.
* if matrix_sensor == 0 and clamp_sensor == 0, then the nest is empty.
3. To check all nests, i wrote a classicladder page, which seems to work fine: if enabled, it compares current cordinate with nests coordinates and assigns hal signals matrix_in_nest_1 ... matrix_in_nest_11 and clamp_in_nest_1 ... clamp_in_nest_11.
4. Then i remapped M-function M333.
I have a prologue which resets this signals and signals to classicladder to start wacthing after nests.
Then there is a shorn ngc which just make a motion from X=0 to X=1300
finally, i have a epilog:

def check_nests_e(self, **words):
global gnezda # global tooltable
if self.task == 1:
# checking if all is ok
error=False
errors =
for gnezdo in sorted(gnezda):
if int(gnezdo) == 0:
continue
if gnezda[gnezdo] == "nothing":
if int(self.params[f"_hal[matrix_in_nest_{gnezdo}]"]) == 1:
error |= True
errors += [ f"Лишний инструмент в гнезде {gnezdo}" ] #[ f"error: redundant tool in nest {gnezdo}\n" ]
if int(self.params[f"_hal[clamp_in_nest_{gnezdo}]"]) == 1:
error |= True
errors += [ f"Лишняя клешня в гнезде {gnezdo}" ] #[ f"error: redundant tool in nest {gnezdo}\n" ]
elif "Pratze" in gnezda[gnezdo]:
if int(self.params[f"_hal[matrix_in_nest_{gnezdo}]"]) == 1:
error |= True
errors += [f"Инструмент в гнезде {gnezdo} вместо клешни"]# [f"error: tool in nest {gnezdo} while clamp is expected\n"]
if int(self.params[f"_hal[clamp_in_nest_{gnezdo}]"]) != 1:
error |= True
errors += [f"Отсутствует клешня в гнезде {gnezdo}"] #[f"error: tool in nest {gnezdo} while clamp is expected\n"]
else:
if int(self.params[f"_hal[matrix_in_nest_{gnezdo}]"]) != 1:
if int(self.params[f"_hal[clamp_in_nest_{gnezdo}]"]) == 1:
error |= True
errors += [f"Клешня в гнезде {gnezdo} вместо инструмента"] #f"error: clamp in nest {gnezdo} while the tool is expected\n"
else:
error |= True
errors += [f"Отсутствует инструмент в гнезде {gnezdo}"]#f"error: not found tool in nest {gnezdo}\n"
elif int(self.params[f"_hal[clamp_in_nest_{gnezdo}]"]) != 0:
error |= True
errors += [f"Отсутствует матрица в держателе в гнезде {gnezdo}"]#f"error: not found tool in nest {gnezdo}\n"

if error:
self.set_errormsg("\n".join(errors))
print(errors)
return INTERP_ERROR
else:
# MESSAGE("all tools and clamps are ok")
MESSAGE("Проверка инструментов пройдена")
print("all tools and clamps are ok")

# turning off wathing over nests content
try:
# bash_line_call_wait(['halcmd',
# "sets",
# "matrix_check_flag",
# "0"
# ])
pass

except Exception as detail:
print("error", detail)

return INTERP_OK
Last edit: 26 Jul 2023 14:04 by arabel1a.

Please Log in or Create an account to join the conversation.

More
26 Jul 2023 14:07 #276304 by arabel1a
Replied by arabel1a on topic Python remap INTERP_ERROR strange behaviour
PS: how to wrap a large piece of code? if i use "code" button, it joints the whole function to one string

Please Log in or Create an account to join the conversation.

Time to create page: 0.051 seconds
Powered by Kunena Forum