def main():
    """
    primary function for command-line execution. return an exit status integer
    or a bool type (where True indicates successful exection)
    """
    formatter = argparse.RawDescriptionHelpFormatter
    argp = argparse.ArgumentParser(formatter_class=formatter, description=(
        "Connects to a YASNAC ERC and sends system control command(s)\n"
        "Make sure you quote each command, for example: \n"
        '\nmotocommand "SVON 1" "JWAIT 10" "START TESTJOB"\n'
        "\nAvailable System Control Functions:\n"
        "-----------------------------------\n"
        "CANCEL - Cancels the error status\n"
        "CYCLE n - Selects a motion cycle mode, n is between 1 and 3\n"
        "DELETE j - Deletes the specified job, j is a job name or * \n"
        "HLOCK n - Turns operator's panel interlock on/off, n is 1 or 0\n"
        "HOLD n - Puts a hold on the robot manipulator, n is 1 or 0\n"
        "JSEQ s,n - Set job and line number; s is job name, n is line no.\n"
        "JWAIT n - Wait n sec., return running job status, n is -1 to 32767\n"
        "MDSP s - Displays a message on the console, s is up to 28 chars.\n"
        "RESET - Resets robot alarms\n"
        "SETMJ j - Makes the specified job the master job, j is a job name\n"
        "START j - Starts robot operation. j is a an OPTIONAL job name\n"
        "SVON n - Turns servo power on/off. n is 1 or 0\n"
        "RUFRAME ? - Unknown undocumented function\n"
        "WUFRAME ? - Unknown undocumented function\n"
        "CVTRJ ? - Unknown undocumented function\n"
        "\nAvailable Status Read Functions:\n"
        "--------------------------------\n"
        "RALARM - Lists error and alarm codes\n"
        "RJDIR j - Lists all jobs or subjobs of j, j is * or a job name\n"
        "RJSEQ - Lists the current job name, line number and step number\n"
        "RPOS - Lists the current robot position in rectangular coordinates\n"
        "RPOSJ - Lists the current robot position in joint coordinates\n"
        "RSTATS - Lists the status of several robot conditions\n"))
    argp.add_argument('command', nargs="+", help=(
        "A command to send to the ERC controller"))
    argp.add_argument('-d', '--debug', action="store_true", help=(
        "Enable transaction debugging output"))
    args = argp.parse_args()

    if sys.version_info < (3,0) :
        input = raw_input
    uri = input("Enter the uri of the robot instance: ").strip()
    Pyro4.config.SERIALIZER = "pickle"
    Pyro4.config.SERIALIZERS_ACCEPTED = {"json","marshal","serpent","pickle"}
    robot = Pyro4.Proxy(uri)
    #uri = input("Enter the uri of the robot lib: ").strip()
    #erc = Pyro4.Proxy(uri)
    #robot = erc.ERC()

    #erc.DEBUG = args.debug

    command = ""
    for command_part in args.command:
        command = command + command_part + " "
    #

    print "about to " + command + " !"
    result = robot.execute_command(command.strip())
    if result:
        print ",".join(result)
        if command == 'RSTATS':
            erc.warn("The result represents these flags: "
                     + ",".join(erc.decode_rstats(result)), True)


    return True
Example #2
0
def main():
    """
    primary function for command-line execution. return an exit status integer
    or a bool type (where True indicates successful exection)
    """
    argp = argparse.ArgumentParser(description=(
        "Connect to an ERC-series robot and move the manipulator"), epilog=(
        'If you see a "too few arguments" error, try adding "--" before '
        "your position argument. For example: "
        'motomove -- "coordinates"'))
    argp.add_argument('--speed', nargs="?", type=float, default=10.0, help=(
        "The speed at which the robot is to perform the motion, in mm/s. "
        "Allowable values are from 0.1 to 1200.00. The default is a glacial "
        "and safeish 10.0. BE SAFE."))
    argp.add_argument('--power', choices=('on', 'off', 'onoff'), help=(
        'Controls servo power; a value of "on" will activate servo power '
        'in order to perform the motion, a value of "off" will turn the '
        'servo power off after performing the motion, a value of "onoff" '
        'will both activate the servo power before the motion and deactivate '
        'the servo power after the motion is complete. The default is not to '
        'make any change to the state of servo power.'))
    argp.add_argument('-d', '--debug', action="store_true", help=(
        "Enable transaction debugging output"))
    argp.add_argument('position', help=(
        "The position to move the robot into. Must be in rectangular "
        "coordinates and comma separated: x,y,z,tx,ty,tz. tx,ty,tz are tool "
        "list angles in degrees. If you don't want to specify a particular "
        'value, leave it empty. You can specify deltas, such as '
        "+=10.1,-=5,/=3,*=2 for movement relative to the robot's current "
        "position. NOTE: The resulting values won't be sanity-checked!"))
    args = argp.parse_args()

    #erc.DEBUG = args.debug

    # sanity check
    if not (0.1 <= args.speed <= 1200.0):
        print "Invalid speed value, must be between 0.1 and 1200.0"
        return False

    speed_string = "{:.2f}".format(args.speed)

    if sys.version_info < (3,0) :
        input = raw_input
    uri = input("Enter the uri of the robot: ").strip()
    Pyro4.config.SERIALIZER = "pickle"
    Pyro4.config.SERIALIZERS_ACCEPTED = {"json","marshal","serpent","pickle"}
    robot = Pyro4.Proxy(uri)
    # now actually do stuff
    #robot = erc.ERC()

    # Calculate the 6 target coordinates based on the given argument and
    # the current position of the robot
    target = robot.execute_command("RPOS")[0:6]  # retrieve the current pos.
    for index, coordinate in enumerate(args.position.split(',')[:6]):
        if coordinate:
            target[index] = resolve_maths(coordinate.strip(), target[index])

    target_string = ",".join(target)

    # are the robot servos on?
    rstats = erc.decode_rstats(robot.execute_command("RSTATS"))
    if not "servos on" in rstats:
        if args.power in ('on', 'onoff'):
            # Turn them on
            robot.execute_command("SVON 1")
            # fixme: error checking
        else:
            erc.warn("Cannot move the manipulator when the servos are off",
                     force=True)
            return False

    print "moving to {} at {} mm/s".format(target_string, speed_string)

    robot.execute_command(("MOVL 0,{speed},0,{pos},"
                           "0,0,0,0,0,0,0,0").format(speed=speed_string,
                                                     pos=target_string))
    robot.execute_command("JWAIT -1")

    # shoule we turn off the servos?
    if args.power in ('off', 'onoff'):
        # Turn them off
        robot.execute_command("SVON 0")

    return True