本文整理汇总了Python中Controller.Controller.run方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.run方法的具体用法?Python Controller.run怎么用?Python Controller.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller.Controller
的用法示例。
在下文中一共展示了Controller.run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Machine
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [as 别名]
class Machine(object):
def __init__(self, cfile, debug):
self.debug = debug
self.cfile = cfile
self.controller = Controller(self.cfile, self.debug)
def run(self):
print("Running...")
ticks = self.controller.run()
return ticks
示例2: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [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: Controller
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [as 别名]
from Controller import Controller
objApp = Controller()
objApp.run()
示例4: Controller
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [as 别名]
from Controller import Controller
controller = Controller()
controller.run()
示例5: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [as 别名]
def main(argv=None):
if argv is None:
argv = sys.argv
parser = OptionParser()
parser.add_option(
'-V', '--version', dest='version', default=False,
action="store_true",
help="show version information and exit")
parser.add_option(
'-r', '--autorun', dest='autorun', default=False, action='store_true',
help='automatically launch morphogenesis')
parser.add_option(
'-i', '--iterations', dest='iterations', type='int', default=1000,
help='when running automatically, stop after this many iterations',
metavar='ITERATIONS')
parser.add_option(
'-p', '--dump_path', dest='dumpAtEndPath', type="string", default=None,
help='when running automatically, if not empty, save the final image and quit',
metavar='PATH')
parser.add_option(
'-s', dest='D_s', type="float", default=0.0005,
help="reaction rate parameter [default: %default]", metavar='RATE')
parser.add_option(
'-a', dest='D_a', type="float", default=0.25,
help="diffusion rate parameter for a [default: %default]", metavar='RATE')
parser.add_option(
'-b', dest='D_b', type="float", default=0.0625,
help="diffusion rate parameter for b [default: %default]", metavar='RATE')
parser.add_option(
'-d', dest='beta_i', type="float", default=12,
help="decay rate for b [default: %default]", metavar='DECAY')
parser.add_option(
'-x', '--width', dest='width', type="int", default=400,
help="width of the generated texture [default: %default]", metavar='WIDTH')
parser.add_option(
'-y', '--height', dest='height', type="int", default=400,
help="height of the generated texture [default: %default]", metavar='HEIGHT')
parser.add_option(
'-g', '--generator', dest='generator', type='string', default='random',
help='generator to use for the initial conditions [default: %default] (other possible values: stripe)',
metavar='NAME')
(options, args) = parser.parse_args()
if options.version:
print program + ', ' + version
quit()
from PyQt4 import QtGui
from MainWindow import MainWindow
from Controller import Controller
app = QtGui.QApplication(args)
window = MainWindow()
controller = Controller(window)
controller.awake()
controller.setOptions(options)
window.show()
if options.autorun:
controller.run(maxIterations=options.iterations, dumpAtEndPath=options.dumpAtEndPath)
app.exec_()
示例6: ArgumentParser
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [as 别名]
elif action == ACTIONS.GET_DRINK:
obs = self.turtle_ctrl.getDrink()
else:
print "incorrect action selected: %s " % action
raise Exception
return obs
if __name__=="__main__":
from argparse import ArgumentParser
parser = ArgumentParser("select which turtle to use. default is Donatello")
parser.add_argument("-d", "--donatello", action="store_true", help="select donatello",dest="donatello")
parser.add_argument("-l", "--leonardo", action="store_true", help="select leonardo", dest="leonardo")
args = parser.parse_args()
if not (args.leonardo or args.donatello):
name = "donatello"
elif args.leonardo:
name = "leonardo"
else:
name = "donatello"
rospy.init_node("waiter_"+name)
rospy.loginfo("starting waiter with turtle %s " % name)
agent = TurtleAgent(name)
ctrl = Controller(agent)
raw_input("Hit enter to start...")
ctrl.run(0, [3,0,0,2], True)
示例7: main
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import run [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()