import sys, os
import linuxcnc
ini = linuxcnc.ini(sys.argv[1])
nproblems = 0
def report_problem(msg, *args):
global nproblems
nproblems += 1
if args:
print msg % args
else:
print msg
def get_int(section, key):
return int(ini.find(section, key).split()[0])
def get_float(section, key):
return float(ini.find(section, key).split()[0])
if ini.find("EMCMOT", "BASE_PERIOD") is None:
period = 0.
else:
period = get_int("EMCMOT", "BASE_PERIOD")
njoints = get_int("KINS", "JOINTS")
is_stepper = ini.find("JOINT_0", "STEPGEN_MAXVEL")
if is_stepper: print "Appears to be a stepper configuration"
else: print "Appears to be a servo configuration"
for i in range(njoints):
joint = "JOINT_%d" % i
if ini.find(joint,"INPUT_SCALE") is None: continue
scale = get_float(joint, "INPUT_SCALE")
if is_stepper:
if ini.find(joint,"STEPGEN_MAXVEL") is None: continue
vel = get_float(joint, "STEPGEN_MAXVEL")
cycles_per_step = 2
required_period = 1000000000 / vel / scale / cycles_per_step
if abs(required_period) < abs(period):
report_problem(
"Max Velocity %g and scale %g require BASE_PERIOD below %d",
vel, scale, int(required_period))
vel = get_float(joint, "MAX_VELOCITY")
headroom_vel = get_float(joint, "STEPGEN_MAXVEL")
if headroom_vel < vel * 1.01:
report_problem(
"Less than 1%% velocity headroom from %g to %g",
vel, headroom_vel)
acc = get_float(joint, "MAX_ACCELERATION")
headroom_acc = get_float(joint, "STEPGEN_MAXACCEL")
if headroom_acc < acc * 1.01:
report_problem(
"Less than 1%% acceleration headroom from %g to %g",
acc, headroom_acc)
if nproblems == 0:
print "No problems found"
elif nproblems == 1:
print "One problem found"
else:
print "%d problems found" % nproblems