From dfd3686bf50279cfb6dbba4d72da37a98c104157 Mon Sep 17 00:00:00 2001 From: MrManlu Date: Thu, 23 May 2019 00:33:11 +0200 Subject: [PATCH] Fixed YAMLLoadWarning when creating Dorna object --- dorna/api.py | 55 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/dorna/api.py b/dorna/api.py index 67a8fc9..9c57f64 100644 --- a/dorna/api.py +++ b/dorna/api.py @@ -82,7 +82,7 @@ def __init__(self): False sync True - False + False """ def set_io(self, prm, fulfill = True, append = True, sync = True): try: @@ -249,21 +249,21 @@ def gcode(self, prm, fulfill = True, append = True): """ prm: - gcode = None, list, json list + gcode = None, list, json list gcode_path = None, string, json, list """ def play_gcode(self, gcode_path = None, gcode = None, **kwargs): - + data = False # open gcode_path if gcode_path: try: with open(gcode_path, 'r') as f: - data = f.read().splitlines() + data = f.read().splitlines() except: data = False - # gcode: list, str, JSON, + # gcode: list, str, JSON, if gcode: # str to data (dict or list) if type(gcode) == str: @@ -289,7 +289,7 @@ def play_gcode(self, gcode_path = None, gcode = None, **kwargs): # xyz space self.play({"command": "move", "prm": {"path": "line", "movement": 1, "x": 0}}, append = False) - + return self.play(commands) @@ -303,9 +303,9 @@ def play_gcode(self, gcode_path = None, gcode = None, **kwargs): class Dorna(_port_usb, easy_method): def __init__(self, config_path = None): - + super(Dorna, self).__init__() - + # ================================================================= # print # ================================================================= @@ -586,7 +586,7 @@ def reset_board(self, port_name = None): """ self._log_add({"status": 1, "message": "Progressing..."}, "update_firmware") print("Progressing...") - + num_try = 8 @@ -698,7 +698,7 @@ def update_firmware(self, port_name = None, firmware_path = None): """ self._log_add({"status": 1, "message": "Progressing..."}, "update_firmware") print("Progressing...") - + num_try = 8 @@ -850,7 +850,7 @@ def _connect_percentage(self, _init_nom, denom, command_list, max_time): # add to the log self._log_add({"nom":_init_nom, "denom": denom}, "connect_percentage") else: - time.sleep(0.02) + time.sleep(0.02) except Exception as e: time.sleep(0.02) @@ -866,7 +866,7 @@ def _connect_percentage_backup(self, _init_nom, denom, command_list, max_time): # add to the log self._log_add({"nom":_init_nom, "denom": denom}, "connect_percentage") else: - time.sleep(0.02) + time.sleep(0.02) def _command_mask(self, command): #_allowed_keys = ["id", "state", "error", "message", "command","prm","fulfill", "key"] @@ -1225,7 +1225,7 @@ def _connect(self,port_name,file_init): job.append([{"command": "g2core", "prm": "c"} for c in content]) except: pass - + # number of jobs _init_num = [0] for j in job: @@ -1596,7 +1596,7 @@ def calibrate(self, prm): # not empty if not prm: return None - + # set_joint if not self.set_joint(prm): @@ -1629,12 +1629,12 @@ def calibrate(self, prm): with open(self._device["config"], 'w') as yaml_file: yaml.dump(_config_tmp, yaml_file, default_flow_style=False) """ - + # add to log self.config() return self.position("joint") - + def calibrate_backup(self, prm): # robot is homed @@ -2363,7 +2363,7 @@ def _home_update(self, response): def _init_config(self): # Read YAML file with open(self._device["config"], 'r') as stream: - self._config = yaml.load(stream) + self._config = yaml.load(stream, Loader=yaml.SafeLoader) if self._config["unit"]["length"] == "mm": # speed_xyz @@ -2562,7 +2562,7 @@ def set_limit(self, limit): except: pass - + if "j0" in limit and len(limit["j0"]) == 2 and limit["j0"][0]<= limit["j0"][1] : self._config["limit"]["j0"] = limit["j0"] @@ -2576,7 +2576,7 @@ def set_limit(self, limit): #self.save_config() return self.limit() - + def set_limit_backup(self, limit): # json try: @@ -2662,12 +2662,12 @@ def i_k(self, xyz): x = xyz[0] y = xyz[1] z = xyz[2] - + if self._config["unit"]["length"] == "mm": x = self._mm_to_inch(x) y = self._mm_to_inch(y) - z = self._mm_to_inch(z) - + z = self._mm_to_inch(z) + alpha = xyz[3] beta = xyz[4] @@ -2863,7 +2863,7 @@ def _joint_validate(self, joint_init, joint_final): joint_achieve[i] = max(joint_final[i], self._config["limit"]["j"+ str(i)][0]) message = "initial position (joint: "+str(joint_init)+") is out of limit" status = 100 - + elif self._config["limit"]["j"+ str(i)][0] <= joint_init[i] <= self._config["limit"]["j"+ str(i)][1]: # between joint_achieve[i] = min(max(joint_final[i], self._config["limit"]["j"+ str(i)][0]),self._config["limit"]["j"+ str(i)][1] ) @@ -3096,12 +3096,12 @@ def _form_io(self,prm): prm = prm_tmp prm = json.dumps(prm) - return prm.replace('"', "") - + return prm.replace('"', "") + def _M100 (self, prm): prm = self._form_io(prm) return {'gc_list': ["M100("+prm+")"], 'status':0} - + def _M100_backup (self, prm): """ prm = json.dumps(prm) @@ -3555,7 +3555,7 @@ def _set_io_async(self, prm): if "servo" in prm: result["gc_list"] += self._servo(prm["servo"])["gc_list"] - return result + return result # {"command": "input", "prm":{"in1": 0, "in2":1, "in3":1}} def _wait_for_input(self, prm): @@ -3621,4 +3621,3 @@ def toolhead(self): # log toolhead #self._log_add({"toolhead": json.loads(result)}, "config") return self.config(["toolhead"]) -