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

Fix Motoman merges #18

Open
wants to merge 12 commits into
base: kinetic-devel
Choose a base branch
from
56 changes: 41 additions & 15 deletions Motoman.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# ----------------------------------------------------


def get_safe_name(progname, max_chars = 6):
def get_safe_name(progname, max_chars = 32):
"""Get a safe program name"""
# Remove special characters
for c in r'-[]/\;,><&*:%=+@!#^()|?^':
Expand Down Expand Up @@ -103,7 +103,9 @@ class RobotPost(object):

PROG_NAME = 'unknown' # Original name of the current program (example: ProgA)
PROG_NAME_CURRENT = 'unknown' # Auto generated name (different from PROG_NAME if we have more than 1 page per program. Example: ProgA2)


PROG_COMMENT = 'Generated using RoboDK'

nPages = 0 # Count the number of pages
PROG_NAMES_MAIN = [] # List of programs called by a main program due to splitting

Expand Down Expand Up @@ -204,11 +206,11 @@ def ProgFinish(self, progname, new_page = False):
header_ins += '//INST' + '\n'
header_ins += '///DATE %s' % datestr + '\n'
#///DATE 2012/04/25 14:11
header_ins += '///COMM Generated using RoboDK\n' # comment: max 28 chars
header_ins += '///COMM %s\n' % self.PROG_COMMENT[:32] # comment: max 32 chars
if self.USE_RELATIVE_JOB:
header_ins += '///ATTR SC,RW,RJ' + '\n'
if self.ACTIVE_FRAME is not None:
header_ins += '///FRAME USER %i' % self.ACTIVE_FRAME + '\n'
header_ins += '////FRAME USER %i' % self.ACTIVE_FRAME + '\n'
else:
header_ins += '///ATTR SC,RW' + '\n'

Expand Down Expand Up @@ -249,11 +251,12 @@ def progsave(self, folder, progname, ask_user = False, show_result = False):
return
else:
filesave = folder + progname
fid = open(filesave, "w")
import io
fid = io.open(filesave, "w", newline='\r\n')
#fid.write(self.PROG)
for line in self.PROG:
fid.write(line)
fid.write('\n')
fid.write(line.decode('unicode-escape'))
fid.write(u'\n')
fid.close()
print('SAVED: %s\n' % filesave) # tell RoboDK the path of the saved file
self.PROG_FILES.append(filesave)
Expand Down Expand Up @@ -434,18 +437,15 @@ def setSpeed(self, speed_mms):
"""Changes the robot speed (in mm/s)"""
speed_cm_min = speed_mms * 60.0 / 10.0
speedl = max(0.01,min(speed_cm_min,200.0)) # Important! Filter linear speed is in mm/s or cm/min (otherwise the program stops)
if speedl < 100:
self.STR_V = "V=%.2f" % speedl
else:
self.STR_V = "V=%.1f" % speedl
self.STR_V = "V=%.1f" % speedl

def setAcceleration(self, accel_mmss):
"""Changes the robot acceleration (in mm/s2)"""
self.addlog('Set acceleration not defined')

def setSpeedJoints(self, speed_degs):
"""Changes the robot joint speed (in deg/s)"""
speedj = max(0.01,min(speed,100.0)) # Joint speed must be in %
speedj = max(0.01, min(speed_degs, 100.0)) # Joint speed must be in %
if speedj < 100:
self.STR_VJ = "VJ=%.2f" % speedj
else:
Expand Down Expand Up @@ -487,7 +487,7 @@ def waitDI(self, io_var, io_value, timeout_ms=-1):
io_value = 'OFF'

# at this point, io_var and io_value must be string values
if timeout_ms < 0:
if timeout_ms <= 0:
#WAIT IN#(12)=ON
self.addline('WAIT %s=%s' % (io_var, io_value))
else:
Expand All @@ -511,7 +511,7 @@ def RunCode(self, code, is_function_call = False):
self.addline(code)

def RunMessage(self, message, iscomment = False):
"""Add a joint movement"""
"""Add a message/comment"""
if iscomment:
for i in range(0,len(message), 29):
i2 = min(i + 29, len(message))
Expand All @@ -521,7 +521,33 @@ def RunMessage(self, message, iscomment = False):
for i in range(0,len(message), 25):
i2 = min(i + 25, len(message))
self.addline('MSG "%s"' % message[i:i2])


# ------------------ Motoman specifics ------------------
def Macro(self, number, mf, args):
macro_line = 'MACRO%s MJ#(%s)' % (number, mf)

if len(args) > 16:
self.addlog('Macro supports only 16 arguments')
return

for arg in args:
# Only ARGF are supported
macro_line += (' ARGF%s' % (arg))

self.addline(macro_line)

def Arcon(self, asf_number = 0):
if asf_number is 0:
self.addline('ARCON')
else:
self.addline('ARCON ASF#(%s)' % asf_number)

def Arcof(self, aef_number = 0):
if aef_number is 0:
self.addline('ARCOF')
else:
self.addline('ARCOF AEF#(%s)' % aef_number)

# ------------------ private ----------------------
def page_size_control(self):
if self.LINE_COUNT >= self.MAX_LINES_X_PROG:
Expand Down
16 changes: 7 additions & 9 deletions robodk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,15 +1335,13 @@ def UploadFTP(program, robot_ip, remote_path, ftp_user, ftp_pass):
# inspired from:
# http://stackoverflow.com/questions/10057672/correct-way-to-implement-a-custom-popup-tkinter-dialog-box

#------------------
# Python 3.X only:
import tkinter
from tkinter import filedialog
#------------------
#Python 2.X only:
#import Tkinter as tkinter
#import tkFileDialog as filedialog
#------------------
try:
## Python 2.X
import Tkinter as tkinter
import tkFileDialog as filedialog
except ImportError:
## Python 3.X
from tkinter import filedialog

def getOpenFile():
"""Pop up a file dialog window to select a file to open."""
Expand Down