Interface de récupération
Obtenir les Étapes utilisées dans le projet Mech-Viz en cours
La fonction permettant d’obtenir les Étapes utilisées dans le projet Mech-Viz en cours est la suivante.
def get_viz_task_names(self, msg={}, timeout=None):
result = self.call_viz("getAllTaskNames", msg, timeout)
logging.info("Property result: {}".format(json.loads(result)))
return result
Après l’appel de get_viz_task_names(), une chaîne au format JSON représentant toutes les Étapes obtenues est renvoyée.
Obtenir les paramètres dans un projet Mech-Viz ou Mech-Vision
La fonction permettant d’obtenir les paramètres dans un projet Mech-Viz ou Mech-Vision est la suivante.
def get_property_info(self, msg={}, get_viz=True, timeout=None):
result = (self.call_viz if get_viz else self.call_vision)("getPropertyInfo", msg, timeout)
logging.info("{0} property result: {1}".format("Viz" if get_viz else "Vision", json.loads(result)))
return result
Lorsque la fonction est appelée sans « type » spécifié pour le paramètre « msg », tous les paramètres sont obtenus. Si un certain type est spécifié, seuls les paramètres de l’Étape correspondante seront obtenus. Par exemple, après l’appel à get_property_info(msg={"type": "move"}), une chaîne au format JSON représentant les paramètres de l’Étape de déplacement à point fixe sera renvoyée.
Obtenir l’état d’exécution du projet Mech-Vision ou Mech-Viz
La fonction on_exec_status_changed() de la classe Adapter obtient l’état d’exécution du projet Mech-Vision ou Mech-Viz. Chaque fois que le projet Mech-Vision ou Mech-Viz s’arrête, l’état d’exécution est envoyé à Adapter via la fonction on_exec_status_changed(). Ainsi, la fonction on_exec_status_changed() est appelée après l’arrêt du projet Mech-Vision ou Mech-Viz. L’extrait de code pour appeler la fonction on_exec_status_changed() est le suivant.
def on_exec_status_changed(self, req_dict, err_dict=None):
project_dir = req_dict.get(jk.project_dir, "")
source_app = req_dict.get(jk.source_app, "")
exit_info = req_dict.get(jk.exit_info, {})
error_code = exit_info.get(jk.error_code, "")
msg = exit_info.get(jk.msg, "")
project_dict = self.get_vision_projects_dict()
if source_app == jk.mech_vision and project_dir in project_dict.values():
project_num = list(project_dict.keys())[list(project_dict.values()).index(project_dir)]
elif source_app == jk.mech_viz:
project_num = 0
else:
return
self.err_dict[project_num] = [error_code, msg] if error_code and error_code[-4:] != "0000" else None
if err_dict:
err_dict[project_num] = [error_code, msg] if error_code and error_code[-4:] != "0000" else None
Le tableau ci-dessous explique les variables utilisées dans l’extrait de code ci-dessus.
| Nom de la variable | Description | ||
|---|---|---|---|
jk.project_dir |
Le chemin du projet. |
||
jk.source_app |
La source de l’état. La valeur peut être Mech-Vision ou Mech-Viz. |
||
jk.exit_info |
Les informations de sortie du logiciel. Le type de données est DICTIONARY. |
||
jk.error_code |
Le code d’état. |
||
jk.msg |
Les informations détaillées correspondant au code d’état. |
||
project_dict |
Les informations du projet. Le type de données est DICTIONARY. Par exemple, {1:"simulate_vis"} indique que l’ID du projet Mech-Vision est 1 et que le nom du projet est simulate_vis.
|
Les codes d’état (indiqués par jk.error_code) peuvent être divisés en deux catégories : codes d’état Mech-Vision et codes d’état Mech-Viz, comme illustré dans la figure ci-dessous.
| Catégorie | Code d’état | Infos brèves |
|---|---|---|
Codes d’état Mech-Vision |
CV-EXXXX |
VISION_RUN_ERROR |
CV-E0201 |
VISION_CAMERA_CONNECT_FAIL |
|
CV-E0401 |
VISION_RECIPE_NOT_SET |
|
CV-E0403 |
VISION_RECP_NUM_OUT_RANGE |
|
MP-EXXXX |
VISION_PLANNER_RUN_ERROR |
|
MP-E0001 |
VISION_PLANNER_PLAN_FAILED |
|
MP-E0005 |
VISION_PLANNER_NOT_REACHABLE |
|
MP-E0008 |
VISION_PLANNER_SINGULARITY |
|
MP-E0011 |
VISION_PLANNER_COLLISION |
|
MP-E0019 |
VISION_PLANNER_NO_TARGET_IN_VISUALMOVE |
|
MP-E0021 |
VISION_PLANNER_VISION_SERVER_NOT_REGISTED |
|
MP-E0022 |
VISION_PLANNER_SET_TOOL_INVALID |
|
Codes d’état Mech-Viz |
MP-EXXXX |
VIZ_RUN_ERROR |
MP-E0001 |
VIZ_PLAN_FAILED |
|
MP-E0005 |
VIZ_NOT_REACHABLE |
|
MP-E0008 |
VIZ_SINGULARITY |
|
MP-E0011 |
VIZ_COLLISION |
|
MP-E0016 |
VIZ_VISION_NO_RESULT |
|
MP-E0017 |
VIZ_VISION_NOT_CALLED |
|
MP-E0018 |
VIZ_VISION_NO_CLOUD_IN_ROI |
|
MP-E0019 |
VIZ_NO_TARGET_IN_VISUALMOVE |
|
MP-E0020 |
VIZ_VISION_REUSE_PLAN_FAILED |
|
MP-E0021 |
VIZ_VISION_SERVER_NOT_REGISTED |
|
MP-E0022 |
VIZ_SET_TOOL_INVALID |
|
MP-E0023 |
VIZ_BRANCH_OUTPORT_ERROR |
De plus, vous pouvez hériter de la fonction on_exec_status_changed() pour traiter self.err_dict. Extrait de code d’exemple :
def on_exec_status_changed(self, req_dict, err_dict=None):
super().on_exec_status_changed(req_dict, err_dict)
err_list = self.err_dict.get(0, [])
if err_list and err_list[0] not in ["MP-E0020"]:
self.handle_viz_error()