Ejemplo n.º 1
0
 def __init__(self):
     Receiver.__init__(self)
     OpMode.__init__(self)
     self.register_name("DepCamera_OFFLOAD")
     self.attached_unit = None
     self.attached_unit_ip = None
     self.clisock = None
Ejemplo n.º 2
0
    def __init__(self):
        Receiver.__init__(self)
        Actuator.__init__(self)
        OpMode.__init__(self)

        self.register_name("Dummy")

        self.val1 = 0
        self.val2 = 0
Ejemplo n.º 3
0
    def __init__(self):
        Receiver.__init__(self)
        Actuator.__init__(self)
        OpMode.__init__(self)

        self.register_name("Joystick")  # make this mode available
        # globally

        self.xval = 0  # joystick value for direction
        self.yval = 0  # joystick value for average speed.
Ejemplo n.º 4
0
    def __init__(self):
        Receiver.__init__(self)
        Actuator.__init__(self)
        OpMode.__init__(self)

        self.register_name("DepCamera")

        self.angle_bottom = 0
        self.angle_middle = 0
        self.angle_top = 0
Ejemplo n.º 5
0
    def __init__(self):
        Receiver.__init__(self)
        Actuator.__init__(self)
        OpMode.__init__(self)

        self.register_name("RoboticArm")  # make this mode available
        # globally

        self.angle_1 = 0  # base servo
        self.angle_2 = 0  # intermediate servo
        self.angle_3 = 0  # servo closest to gripper
        self.angle_grp = 0  # gripper
Ejemplo n.º 6
0
def gen_enum():
    '''Create an enum based on available operational modes.'''
    mode_names = OpMode.get_all_names().copy()
    enum_names = mode_names.copy()
    for i in range(len(mode_names)):
        enum_names[i] = mode_names[i]
    return Enum('OP_MODES', enum_names)
Ejemplo n.º 7
0
def process_as_unit(argv):
    '''Equivalent of main() for attached units. Connect to the main unit and 
await instructions from it.'''
    if len(argv) != 3 and len(argv) != 4:
        dg.print(usage_str)
        sys.exit(1)

    unitname = argv[2]

    try:
        if len(argv) == 4:
            cfg.Configuration.settings_file(argv[3])
        else:
            cfg.Configuration.settings_file()
    except cfg.ConfigurationError as e:
        dg.print(str(e) + "\nExiting...")
        sys.exit(1)

    cfg.overall_config.running_as_unit = True

    success = False
    dg.print("Attempting to connect to main unit...")
    while not success:
        success = unit.register_unit(unitname)
        if not success:
            dg.print("Could not connect to main unit. Retrying...")
        time.sleep(1)

    dg.print("Running as unit with name {}".format(unitname))

    try:
        OpMode.opmodes_initialise()  # check for available operational modes
    except OpModeError as e:
        dg.print(str(e) + "\nExiting...")
        sys.exit(1)  # exit with error code
    if OpMode.get_all():  # list of registered modes is not empty
        dg.print("Found operational modes: ")
    for name in OpMode.get_all_names():  # print registered names of all modes
        dg.print('  ' + name)

    try:
        mgr.global_resources.initialise()
    except mgr.ResourceError as e:
        dg.print(str(e) + "\nExiting...")
        sys.exit(1)
Ejemplo n.º 8
0
 def __init__(self):
     OpMode.__init__(self)
     self.register_name("Auto")
     self.goals_initialise()
Ejemplo n.º 9
0
    def __init__(self):
        CameraUser.__init__(self)
        OpMode.__init__(self)

        self.register_name("Stream")
Ejemplo n.º 10
0
 def __init__(self):
     OpMode.__init__(self)
     self.register_name("MockOpMode")
Ejemplo n.º 11
0
 def test_init(self):
     all_names = OpMode.get_all_names()
     if not 'MockOpMode' in all_names:
         self.fail()
Ejemplo n.º 12
0
 def setUp(self, mocked_cfg):
     if not type(self).ranSetup:
         OpMode.opmodes_initialise()
         type(self).ranSetup = True
Ejemplo n.º 13
0
def main(argv):
    '''Rover operation starts here! Wait for a connection from a remote
    computer, interpret commands received and take appropriate action.
    '''
    if len(argv) < 2 and len(argv) > 4:
        dg.print(usage_str)
        sys.exit(1)

    if argv[1] == '--as-unit':  # not the main unit
        process_as_unit(argv)
        return

    # The rest of main() should only run on the main unit

    try:
        port = int(argv[1])  # port to receive commands on
    except ValueError:
        dg.print("Port number should be an integer")
        sys.exit(1)  # exit with error code

    try:
        if len(argv) == 3:  # settings file specified
            cfg.Configuration.settings_file(argv[2])
        else:  # use the default settings file (settings.xml)
            cfg.Configuration.settings_file()
    except cfg.ConfigurationError as e:  # error related to settings file
        dg.print(str(e) + "\nExiting...")
        sys.exit(1)  # exit with error code

    try:
        OpMode.opmodes_initialise()  # check for available operational modes
    except OpModeError as e:
        dg.print(str(e) + "\nExiting...")
        sys.exit(1)  # exit with error code
    if OpMode.get_all():  # list of registered modes is not empty
        dg.print("Found operational modes: ")
    for name in OpMode.get_all_names():  # print registered names of all modes
        dg.print('  ' + name)

    try:
        mgr.global_resources.initialise()  # get all resources ready
        # (motors, camera, etc)
    except mgr.ResourceError as e:
        dg.print(str(e) + "\nExiting...")
        sys.exit(1)  # exit with error code

    dg.initialise()  # start diagnostics
    unit.activate_main_unit_services(
    )  # service connections from attached units

    # start operation
    while (True):
        dg.print("Waiting for connection...")
        try:
            main_sock = wait_for_remote(port)
            host, _ = main_sock.get_ip_address()
            cfg.overall_config.set_ip(host)
        except TcpSocketError as e:  # connection error
            dg.print(str(e))
            cleanup()
            continue  # wait for connection again
        shutdown = run(main_sock)
        if shutdown:
            break
    cleanup()
    unit.deactivate_main_unit_services()
    dg.close()
    sys.exit(0)  # shutdown