Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed YAMLLoadWarning when creating Dorna object #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions dorna/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self):
False
sync
True
False
False
"""
def set_io(self, prm, fulfill = True, append = True, sync = True):
try:
Expand Down Expand Up @@ -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:
Expand All @@ -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)


Expand All @@ -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
# =================================================================
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1596,7 +1596,7 @@ def calibrate(self, prm):
# not empty
if not prm:
return None


# set_joint
if not self.set_joint(prm):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]

Expand All @@ -2576,7 +2576,7 @@ def set_limit(self, limit):
#self.save_config()

return self.limit()

def set_limit_backup(self, limit):
# json
try:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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] )
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -3621,4 +3621,3 @@ def toolhead(self):
# log toolhead
#self._log_add({"toolhead": json.loads(result)}, "config")
return self.config(["toolhead"])