implement scripting language
This commit is contained in:
parent
98b17bd2ff
commit
00db142df7
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""ArmCtlListener.py: python listener for ArmControl scripts."""
|
||||
|
||||
__author__ = "Kevin Matz"
|
||||
__copyright__ = "Copyright 2019, Company 235, LLC"
|
||||
__credits__ = ["Kevin Matz"]
|
||||
|
||||
__license__ = "MIT"
|
||||
__version__ = "0.1"
|
||||
__maintainer__ = "Kevin Matz"
|
||||
__email__ = "kevin@company235.com"
|
||||
|
||||
__status__ = "Prototype"
|
||||
|
||||
|
||||
import logging
|
||||
from ArmControlParser import ArmControlParser
|
||||
from ArmControlListener import ArmControlListener
|
||||
from robot import Robot
|
||||
from time import sleep
|
||||
|
||||
logger = logging.getLogger('__main__')
|
||||
|
||||
|
||||
class ArmCtlListener(ArmControlListener):
|
||||
def __init__(self, robot):
|
||||
self.r = robot
|
||||
|
||||
# Exit a parse tree produced by ArmControlParser#Go.
|
||||
def exitGo(self, ctx: ArmControlParser.GoContext):
|
||||
if ctx.coords() is not None:
|
||||
self.r.move(ctx.coords().values)
|
||||
return
|
||||
if ctx.name() is None:
|
||||
logger.error("ERROR: Go command with no name?")
|
||||
return
|
||||
if ctx.value() is None:
|
||||
logger.info("Go-ing to presets not supported yet.")
|
||||
return
|
||||
values = []
|
||||
values.insert(self.r.config.get(ctx.name.getText(), None),
|
||||
ctx.value().value)
|
||||
self.r.move(values)
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by ArmControlParser#Pause.
|
||||
def exitPause(self, ctx: ArmControlParser.PauseContext):
|
||||
sleep(ctx.number().value)
|
||||
|
||||
# Exit a parse tree produced by ArmControlParser#Wait.
|
||||
def exitWait(self, ctx: ArmControlParser.WaitContext):
|
||||
while self.r.isMoving:
|
||||
pass
|
||||
if (ctx.number() is not None):
|
||||
sleep(ctx.number().value)
|
||||
|
||||
# Enter a parse tree produced by ArmControlParser#coords.
|
||||
def enterCoords(self, ctx: ArmControlParser.CoordsContext):
|
||||
self.values = []
|
||||
self.index = 0
|
||||
|
||||
# Exit a parse tree produced by ArmControlParser#number.
|
||||
def exitNumber(self, ctx: ArmControlParser.NumberContext):
|
||||
try:
|
||||
ctx.value = int(ctx.getText())
|
||||
except ValueError:
|
||||
ctx.value = float(ctx.getText())
|
||||
if isinstance(ctx.parentCtx, ArmControlParser.CoordsContext):
|
||||
ctx.parentCtx.values.insert(ctx.parentCtx.index, ctx.value)
|
||||
|
||||
# Exit a parse tree produced by ArmControlParser#seperator.
|
||||
def exitSeperator(self, ctx: ArmControlParser.SeperatorContext):
|
||||
if isinstance(ctx.parentCtx, ArmControlParser.CoordsContext):
|
||||
ctx.parentCtx.index += 1
|
Loading…
Reference in New Issue