本文整理汇总了Python中Controller.Controller.add_spindle方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.add_spindle方法的具体用法?Python Controller.add_spindle怎么用?Python Controller.add_spindle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller.Controller
的用法示例。
在下文中一共展示了Controller.add_spindle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import add_spindle [as 别名]
def main():
# if no parameter option is given, default to example gcode
if len(sys.argv) == 1:
sys.argv.append("examples/tiroler_adler.ngc")
# bring GPIO to a clean state
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
# here we use a shift register
shift_register = ShiftRegister(23, 24, 25, 16, autocommit=True)
# and we use a fake GPIO Object to use ShiftRegister instead
m_a_a1 = ShiftGPIOWrapper(0)
m_a_a2 = ShiftGPIOWrapper(1)
m_a_b1 = ShiftGPIOWrapper(2)
m_a_b2 = ShiftGPIOWrapper(3)
m_b_a1 = ShiftGPIOWrapper(4)
m_b_a2 = ShiftGPIOWrapper(5)
m_b_b1 = ShiftGPIOWrapper(6)
m_b_b2 = ShiftGPIOWrapper(7)
m_c_a1 = ShiftGPIOWrapper(8)
m_c_a2 = ShiftGPIOWrapper(9)
m_c_b1 = ShiftGPIOWrapper(10)
m_c_b2 = ShiftGPIOWrapper(11)
try:
logging.info("Initialize GPIO Modes")
# build our controller
logging.info("Creating Controller Object")
# one turn is 8 mm * pi in 48 steps, motor and screw specifications
controller = Controller(resolution=8 * math.pi / 48, default_speed=1.0, delay=0.0)
controller.add_motor("X", UnipolarStepperMotor(coils=(2, 3, 4, 27), max_position=9999, min_position=-9999, delay=0.003))
controller.add_motor("Y", UnipolarStepperMotor(coils=(23, 24, 25, 8), max_position=9999, min_position=-9999, delay=0.003))
# controller.add_motor("Z", UnipolarStepperMotorOnOff(coils=(14, 15, 9, 7), on_position=10, on_direction=0, delay=0.003))
controller.add_motor("Z", UnipolarStepperMotor(coils=(14, 15, 9, 7), max_position=20, min_position=0, delay=0.003))
#controller.add_motor("Z", Motor(min_position=-10000, max_position=10000, delay=0.0))
controller.add_spindle(Spindle()) # generic spindle object
controller.add_transformer(PlotterTransformer(width=1000, heigth=500, scale=20.0)) # transformer for plotter usage
# create parser
logging.info("Creating Parser Object")
parser = Parser(filename=sys.argv[1])
parser.set_controller(controller)
# create gui
logging.info("Creating GUI")
gui = PlotterSimulator(automatic=True)
# gui = GcodeGuiConsole()
# connect gui with parser and controller
gui.set_controller(controller)
controller.set_gui_cb(gui.controller_cb)
gui.set_parser(parser)
parser.set_gui_cb(gui.parser_cb)
# start
logging.info("Please move pen to left top corner, the origin")
#key = raw_input("Press any KEY when done")
parser.read()
except ControllerExit, exc:
logging.info(exc)
示例2: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import add_spindle [as 别名]
def main():
# bring GPIO to a clean state
try:
GPIO.cleanup_existing()
GPIO.setmode(GPIO.BOARD)
except AttributeError:
GPIO.setmode(GPIO.BCM)
# we use GPIO Wrapper, object like interface to real GPIO Module
ser = gpio(7, GPIO)
ser.setup(GPIO.OUT)
rclk = gpio(8, GPIO)
rclk.setup(GPIO.OUT)
srclk = gpio(25, GPIO)
srclk.setup(GPIO.OUT)
# in this example a shift register will be used
shift_register = ShiftRegister(ser, rclk, srclk, 16, autocommit=True)
# and we use a fake GPIO Object to use ShiftRegister instead
# Motor A left upper corner
m_a_dir = ShiftGPIOWrapper(shift_register, 0)
m_a_step = ShiftGPIOWrapper(shift_register, 1)
m_a_enable = ShiftGPIOWrapper(shift_register, 2)
# motor B, should be reversed to A
m_b_dir = ShiftGPIOWrapper(shift_register, 3)
m_b_step = ShiftGPIOWrapper(shift_register, 4)
m_b_enable = ShiftGPIOWrapper(shift_register, 5)
# Motor C Penholder
m_c_dir = ShiftGPIOWrapper(shift_register, 6)
m_c_step = ShiftGPIOWrapper(shift_register, 7)
m_c_enable = ShiftGPIOWrapper(shift_register, 8)
try:
logging.info("Initialize GPIO Modes")
# build our controller
logging.info("Creating Controller Object")
motor_x = A5988DriverMotor(
enable_pin=m_a_enable,
dir_pin=m_a_dir,
step_pin=m_a_step,
max_position=9999,
min_position=-9999,
delay=0.05)
motor_y = A5988DriverMotor(
enable_pin=m_b_enable,
dir_pin=m_b_dir,
step_pin=m_b_step,
max_position=9999,
min_position=-9999,
delay=0.05)
motor_z = A5988DriverMotor(
enable_pin=m_c_enable,
dir_pin=m_c_dir,
step_pin=m_c_step,
max_position=9999,
min_position=-9999,
delay=0.05)
# one turn is 8 mm * pi in 48 steps, motor and screw specifications
controller = Controller(resolution=8 * math.pi / 48, default_speed=1.0, autorun=False)
controller.add_motor("X", motor_x)
controller.add_motor("Y", motor_y)
controller.add_motor("Z", motor_z)
controller.add_spindle(BaseSpindle()) # generic spindle object
transformer = PlotterTransformer(width=830, scale=15.0, ca_zero=320, h_zero=140) # transformer for plotter usage
controller.add_transformer(transformer) # transformer for plotter usage
# create parser
logging.info("Creating Parser Object")
parser = Parser(filename=FILENAME, autorun=False)
parser.set_controller(controller)
# create gui
logging.info("Creating GUI")
# gui = PlotterSimulator(automatic=True)
gui = GuiConsole()
# connect gui with parser and controller
gui.set_controller(controller)
gui.set_parser(parser)
controller.set_gui_cb(gui.controller_cb)
parser.set_gui_cb(gui.parser_cb)
transformer.set_gui_cb(gui.transformer_cb)
# start
logging.info("Please move pen to left top corner, the origin")
# key = raw_input("Press any KEY when done")
logging.error("start parsing")
parser.read()
logging.error("parsing done, calling controller methods")
parser.run()
logging.error("controller calculations done, calling physical world")
controller.run()
gui.quit()
except KeyboardInterrupt as exc:
logging.info(exc)
except StandardError as exc:
logging.exception(exc)
shift_register.clear()
GPIO.cleanup()
示例3: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import add_spindle [as 别名]
def main():
# if no parameter option is given, default to example gcode
if len(sys.argv) == 1:
sys.argv.append("examples/tiroler_adler.ngc")
# bring GPIO to a clean state
try:
GPIO.cleanup_existing()
except AttributeError:
pass
GPIO.setmode(GPIO.BOARD)
# we use GPIO Wrapper, object like interface to real GPIO Module
ser = gpio(23, GPIO)
ser.setup(GPIO.OUT)
rclk = gpio(24, GPIO)
rclk.setup(GPIO.OUT)
srclk = gpio(25, GPIO)
srclk.setup(GPIO.OUT)
# in this example a shift register will be used
shift_register = ShiftRegister(ser, rclk, srclk, 16, autocommit=True)
# and we use a fake GPIO Object to use ShiftRegister instead
m_a_a1 = ShiftGPIOWrapper(shift_register, 0)
m_a_a2 = ShiftGPIOWrapper(shift_register, 1)
m_a_b1 = ShiftGPIOWrapper(shift_register, 2)
m_a_b2 = ShiftGPIOWrapper(shift_register, 3)
# B-Motor
m_b_a1 = ShiftGPIOWrapper(shift_register, 6)
m_b_a2 = ShiftGPIOWrapper(shift_register, 7)
m_b_b1 = ShiftGPIOWrapper(shift_register, 4)
m_b_b2 = ShiftGPIOWrapper(shift_register, 5)
# C-Motor Pen Holder
m_c_a1 = ShiftGPIOWrapper(shift_register, 8)
m_c_a2 = ShiftGPIOWrapper(shift_register, 9)
m_c_b1 = ShiftGPIOWrapper(shift_register, 10)
m_c_b2 = ShiftGPIOWrapper(shift_register, 11)
try:
logging.info("Initialize GPIO Modes")
# build our controller
logging.info("Creating Controller Object")
# one turn is 8 mm * pi in 48 steps, motor and screw specifications
motor_x = UnipolarStepperMotor(coils=(m_a_a1, m_a_a2, m_a_b1, m_a_b2), max_position=9999, min_position=-9999, delay=0.003)
motor_y = UnipolarStepperMotor(coils=(m_b_a1, m_b_a2, m_b_b1, m_b_b2), max_position=9999, min_position=-9999, delay=0.003)
motor_z = UnipolarStepperMotor(coils=(m_c_a1, m_c_a2, m_c_b1, m_c_b2), max_position=10, min_position=-10, delay=0.003, sos_exception=False)
controller = Controller(resolution=1, default_speed=1.0)
controller.add_motor("X", motor_x)
controller.add_motor("Y", motor_y)
controller.add_motor("Z", motor_z)
controller.add_spindle(Spindle()) # generic spindle object
# controller.add_transformer(Transformer()) # transformer for plotter usage
controller.add_transformer(PlotterTransformer(width=1000, ca_zero=420, h_zero=140, scale=1.0)) # transformer for plotter usage
# create parser
logging.info("Creating Parser Object")
#parser = Parser(filename=sys.argv[1])
#parser.set_controller(controller)
# create gui
logging.info("Creating GUI")
#gui = PlotterSimulator(automatic=True)
gui = GcodeGuiConsole()
# connect gui with parser and controller
gui.set_controller(controller)
controller.set_gui_cb(gui.controller_cb)
#gui.set_parser(parser)
#parser.set_gui_cb(gui.parser_cb)
# start
logging.info("Please move pen to left top corner, the origin")
# key = raw_input("Press any KEY when done")
# parser.read()
pygame.init()
screen = pygame.display.set_mode((600,400))
pygame.key.set_repeat(50, 1)
finished = False
x = 0
y = 0
z = 0
while not finished:
# clock.tick(60) # not more than 60 frames per seconds
# pygame.event.wait()
event = pygame.event.wait()
if event.type == pygame.QUIT:
finished = True
key = pygame.key.get_pressed()
if event.type == pygame.KEYDOWN:
if key[pygame.K_a] : x += 1
elif key[pygame.K_y] : x -= 1
elif key[pygame.K_s] : y += 1
elif key[pygame.K_x] : y -= 1
elif key[pygame.K_d] : z += 1
elif key[pygame.K_c] : z -= 1
else: break
controller.G00({"X":x, "Y":y, "Z":z})
print controller.position
except KeyboardInterrupt as exc:
logging.info(exc)
except StandardError as exc:
logging.exception(exc)
shift_register.clear()
GPIO.cleanup()
示例4: Parser
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import add_spindle [as 别名]
class Parser(object):
"""
Class to parse GCode Text Commands
"""
def __init__(self, surface, filename):
self.surface = surface
self.filename = filename
# build our controller
self.controller = Controller(surface=surface, resolution=512/36, default_speed=1.0, delay=0.0)
self.controller.add_motor("X", BipolarStepperMotor(coils=(4, 2, 27, 22), max_position=512, min_position=0, delay=0.0))
self.controller.add_motor("Y", BipolarStepperMotor(coils=(24, 25, 7, 8), max_position=512, min_position=0, delay=0.0))
self.controller.add_motor("Z", LaserMotor(laser_pin=14, min_position=-10000, max_position=10000, delay=0.0))
self.controller.add_spindle(Spindle())
# last known g code
self.last_g_code = None
# draw grid
if self.surface is not None:
self.draw_grid()
# precompile regular expressions
self.rex_g = {}
self.g_params = ("X", "Y", "Z", "F", "I", "J", "K", "P", "R")
for g_param in self.g_params:
self.rex_g[g_param] = re.compile("%s([\+\-]?[\d\.]+)\D?" % g_param)
self.rex_m = {}
self.m_params = ("S", )
for m_param in self.m_params:
self.rex_m[m_param] = re.compile("%s([\+\-]?[\d\.]+)\D?" % m_param)
def draw_grid(self):
"""
draw grid on pygame window
first determine, which axis are to draw
second determine what the min_position and max_positions of each motor are
surface.X : self.motors["X"].min_position <-> surface.get_width() = self.motors["X"].max_position
surface.Y : self.motors["Y"].min_position <-> surface.get_height() = self.motors["Y"].max_position
"""
color = pygame.Color(0, 50, 0, 255)
for x in range(0, self.surface.get_height(), 10):
pygame.draw.line(self.surface, color, (x, 0), (x, self.surface.get_height()), 1)
for y in range(0, self.surface.get_width(), 10):
pygame.draw.line(self.surface, color, (0, y), (self.surface.get_width(), y), 1)
color = pygame.Color(0, 100, 0, 255)
pygame.draw.line(self.surface, color, (self.surface.get_width() / 2, 0), (self.surface.get_width() / 2, self.surface.get_height()))
pygame.draw.line(self.surface, color, (0, self.surface.get_height() / 2), (self.surface.get_width(), self.surface.get_height() / 2))
# draw motor scales
color = pygame.Color(100, 0, 0, 255)
pygame.draw.line(self.surface, color, (self.surface.get_width() - 10, 0), (self.surface.get_width() - 10, self.surface.get_height()))
pygame.draw.line(self.surface, color, (0, self.surface.get_height() - 10), (self.surface.get_width(), self.surface.get_height() - 10))
def parse_g_params(self, line):
"""parse known Parameters to G-Commands"""
result = {}
for parameter in self.g_params:
match = self.rex_g[parameter].search(line)
if match:
result[parameter] = float(match.group(1))
return(result)
def parse_m_params(self, line):
"""parse known Parameters to M-Commands"""
result = {}
for parameter in self.m_params:
match = self.rex_m[parameter].search(line)
if match:
result[parameter] = float(match.group(1))
return(result)
def caller(self, methodname=None, args=None):
"""
calls G- or M- code Method
if no G-Code Method was given, the last methos will be repeated
fo example G02 results in call of self.controller.G02(args)
"""
# logging.info("Methodname = %s" % methodname)
if methodname is None:
methodname = self.last_g_code
else:
self.last_g_code = methodname
method_to_call = getattr(self.controller, methodname)
method_to_call(args)
def read(self):
"""
read input file line by line, and parse gcode Commands
"""
for line in open(self.filename, "rb"):
# cleanup line
line = line.strip()
line = line.upper()
# filter out some incorrect lines
if len(line) == 0:
continue
if line[0] == "%":
continue
# start of parsing
logging.info("-" * 80)
#.........这里部分代码省略.........
示例5: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import add_spindle [as 别名]
def main():
if len(sys.argv) == 1:
sys.argv.append("examples/tiroler_adler.ngc")
# STEP 1 - GPIO Initialization
# bring GPIO to a clean state
try:
GPIO.cleanup_existing()
GPIO.setmode(GPIO.BOARD)
except AttributeError:
pass
# define GPIO Pins to use
enable_pin = gpio(23, GPIO)
enable_pin.setup(GPIO.OUT)
laser_pin = gpio(14, GPIO)
laser_pin.setup(GPIO.OUT)
m_x_step = gpio(4, GPIO)
m_x_step.setup(GPIO.OUT)
m_x_dir = gpio(2, GPIO)
m_x_dir.setup(GPIO.OUT)
m_x_enable = gpio(27, GPIO)
m_x_enable.setup(GPIO.OUT)
m_y_step = gpio(22, GPIO)
m_y_step.setup(GPIO.OUT)
m_y_dir = gpio(24, GPIO)
m_y_dir.setup(GPIO.OUT)
m_y_enable = gpio(25, GPIO)
m_y_enable.setup(GPIO.OUT)
m_b_b1 = gpio(7, GPIO)
m_b_b1.setup(GPIO.OUT)
m_b_b2 = gpio(8, GPIO)
m_b_b2.setup(GPIO.OUT)
logging.info("Initialize GPIO")
# enable pin for L293D Chip
enable_pin.output(1)
# laser power off
laser_pin.output(0)
# STEP 2 - create Objects and connect them
# build our controller
logging.info("Creating Controller Object")
controller = Controller(resolution=512/36, default_speed=1.0, autorun=False)
# step_pin, dir_pin, enable_pin, int max_position, int min_position, double delay, int sos_exception=False
controller.add_motor("X", StepDirMotor(m_x_step, m_x_dir, m_x_enable, max_position=512, min_position=0, delay=0.002))
controller.add_motor("Y", StepDirMotor(m_y_step, m_y_dir, m_y_enable, max_position=512, min_position=0, delay=0.002))
controller.add_motor("Z", LaserMotor(laser_pin=laser_pin, min_position=-10000, max_position=10000, delay=0.00))
controller.add_spindle(BaseSpindle())
controller.add_transformer(Transformer())
# create parser
logging.info("Creating Parser Object")
parser = Parser(filename=sys.argv[1], autorun=False)
parser.set_controller(controller)
# create gui
logging.info("Creating GUI")
# gui = LaserSimulator(automatic=True, zoom=10.0, controller=controller, parser=parser)
gui = GuiConsole()
controller.set_gui_cb(gui.controller_cb)
parser.set_gui_cb(gui.parser_cb)
# start
logging.info("Please move stepper motors to origin (0, 0, 0)")
#key = raw_input("Press any KEY when done")
# STEP 3 - run
# this is usually done from
try:
parser.read()
#key = raw_input("Parsing done, press Return to call controller")
parser.run()
#key = raw_input("Controller calculations done, press Return to move")
controller.run()
key = raw_input("Controller calculations done, press Return to move")
except ControllerExit as exc:
logging.info(exc)
except Exception as exc:
logging.exception(exc)
except KeyboardInterrupt as exc:
logging.exception(exc)
# STEP 4 - shutdown
# inidcate gui to quit
gui.stop_flag = True
# cleanup gpio
GPIO.cleanup()