示例#1
0
class AT2Controller:

    robot1ctrl_wrapper= RobotCtrl_Wrapper()
    robot1coordinator_wrapper= Robot1Coordinator_Wrapper()
    SERVER_ADDRESS = "/tmp/at2.sock"
    def __init__(self):
        self.unix_server = UnixServer(self.SERVER_ADDRESS)
        self.unix_server.start()
        print("\n \n Unix Server of Assembly task2 has just started \n \n")


    def start_working(self):
        while True:
            try:
                message_received= self.unix_server.read_data()
                if message_received!='' :
                    message = json.loads(message_received)
                    sender_address = message['sender']
                    print(message)

                    if sender_address == "coordinator":  # mono start mporei na steilei o coordinator
                        self.robot1ctrl_wrapper.create_client()
                        self.robot1ctrl_wrapper.connect_2_unix_server(RobotCtrl_Wrapper.SERVER_ADDRESS)
                        self.robot1ctrl_wrapper.send_2_robotctrl(self.robot1ctrl_wrapper.START_MESSAGE_PickAndPlace)
                        while True:
                            message = self.unix_server.read_data()
                            print(str(message))
                            if message ==  '{"PickAndPlace_MS": "FINISHED"}':
                                print("\n pick and place has completed \n")
                                self.robot1ctrl_wrapper.unix_client.close_client()
                                break
                        print(" PICK AND PLACE FINISHED . LETS START PICK AND INSERT NOW")

                        self.robot1ctrl_wrapper.create_client()
                        self.robot1ctrl_wrapper.connect_2_unix_server(RobotCtrl_Wrapper.SERVER_ADDRESS)
                        self.robot1ctrl_wrapper.send_2_robotctrl(self.robot1ctrl_wrapper.START_MESSAGE_PickAndFlipAndPress)
                        while True:
                            message = self.unix_server.read_data()
                            print(str(message))
                            if message ==  '{"PickAndFlipAndPress_MS": "FINISHED"}':
                                print("\n \n \n \n pick and flip and press has completed \n \n \n \n")
                                self.robot1ctrl_wrapper.unix_client.close_client()
                                break
                        print("PICK AND FLIP AND PRESS FINISHED")
                        print("controller free to service another call")

                        self.robot1coordinator_wrapper.create_client()
                        self.robot1coordinator_wrapper.connect_2_unix_server(Robot1Coordinator_Wrapper.SERVER_ADDRESS)
                        self.robot1coordinator_wrapper.send_2_robot_coordinator(Robot1Coordinator_Wrapper.COMPLETED_MESSAGE)
                        self.robot1coordinator_wrapper.unix_client.close_client()

            except (ConnectionResetError, OSError) as e:
                print(e)
示例#2
0
class W2Controller:

    SERVER_ADDRESS = "/tmp/w2ctrl.sock"
    w1_wrapper = W2Coordinator_Wrapper()

    def __init__(self):
        self.unix_server = UnixServer(self.SERVER_ADDRESS)
        self.unix_server.start()
        print("\n \n Unix Server of W2 Controller has just started \n \n")

#########################################################
#                            CALL MICROSERVICES
#########################################################

    def call_hold(self, device):
        hold = Hold()
        return hold.start_working(device)

    def call_release(self, device):
        release = Release()
        return release.start_working(device)

    def start_controller(self, device):
        while True:
            try:
                message_received = self.unix_server.read_data()
                print(message_received)

                if "HOLD" in message_received:
                    response = self.call_hold(device)
                    if "FINISHED" in response:
                        print("controller free to service another call")
                        self.w1_wrapper.create_client()
                        self.w1_wrapper.connect_2_unix_server(
                            W2Coordinator_Wrapper.SERVER_ADDRESS)
                        self.w1_wrapper.send_2_coordinator(response)
                        self.w1_wrapper.unix_client.close_client()
                if "RELEASE" in message_received:
                    response = self.call_release(device)
                    if "FINISHED" in response:
                        print("controller free to service another call")
                        self.w1_wrapper.create_client()
                        self.w1_wrapper.connect_2_unix_server(
                            W2Coordinator_Wrapper.SERVER_ADDRESS)
                        self.w1_wrapper.send_2_coordinator(response)
                        self.w1_wrapper.unix_client.close_client()

            except (ConnectionResetError, OSError) as e:
                print(e)
class AT3Controller:

    robot2ctrl_wrapper = RobotCtrl_Wrapper()
    robot2coordinator_wrapper = Robot2Coordinator_Wrapper()
    SERVER_ADDRESS = "/tmp/at3.sock"

    def __init__(self):
        self.unix_server = UnixServer(self.SERVER_ADDRESS)
        self.unix_server.start()
        print("\n \n Unix Server of Assembly Task3 has just started \n \n")

    def start_working(self):
        while True:
            try:
                message_received = self.unix_server.read_data()
                if message_received != '':
                    message = json.loads(message_received)
                    sender_address = message['sender']
                    print(message)

                    if sender_address == "coordinator":  # mono start mporei na steilei o coordinator
                        self.robot2ctrl_wrapper.create_client()
                        self.robot2ctrl_wrapper.connect_2_unix_server(
                            RobotCtrl_Wrapper.SERVER_ADDRESS)
                        self.robot2ctrl_wrapper.send_2_robotctrl(
                            self.robot2ctrl_wrapper.START_MESSAGE_PickAndInsert
                        )
                        while True:
                            message = self.unix_server.read_data()
                            print(str(message))
                            if message == '{"PickAndInsert_MS": "FINISHED"}':
                                print(
                                    "\n \n \n \n pick and insert has completed \n \n \n \n"
                                )
                                self.robot2ctrl_wrapper.unix_client.close_client(
                                )
                                break
                        print(
                            " PICK AND INSERT FINISHED . LETS START SCREW PICK AND FASTEN NOW"
                        )

                        self.robot2ctrl_wrapper.create_client()
                        self.robot2ctrl_wrapper.connect_2_unix_server(
                            RobotCtrl_Wrapper.SERVER_ADDRESS)
                        self.robot2ctrl_wrapper.send_2_robotctrl(
                            self.robot2ctrl_wrapper.
                            START_MESSAGE_ScrewPickAndFasten)
                        while True:
                            message = self.unix_server.read_data()
                            print(str(message))
                            if message == '{"ScrewPickAndFasten_MS": "FINISHED"}':
                                print(
                                    "\n \n \n \n screw pick and fasten has completed \n \n \n \n"
                                )
                                self.robot2ctrl_wrapper.unix_client.close_client(
                                )
                                break
                        print("SCREW PICK AND FASTEN FINISHED")
                        print("controller free to service another call")

                        self.robot2coordinator_wrapper.create_client()
                        self.robot2coordinator_wrapper.connect_2_unix_server(
                            Robot2Coordinator_Wrapper.SERVER_ADDRESS)
                        self.robot2coordinator_wrapper.send_2_robot_coordinator(
                            Robot2Coordinator_Wrapper.COMPLETED_MESSAGE)
                        self.robot2coordinator_wrapper.unix_client.close_client(
                        )

            except (ConnectionResetError, OSError) as e:
                print(e)
class RobotController:

    SERVER_ADDRESS = "/tmp/robot2ctrl.sock"

    def __init__(self):
        self.unix_server = UnixServer(self.SERVER_ADDRESS)
        self.unix_server.start()

        print("\n \n Unix Server of Robot Controller has just started \n \n")

#########################################################
#                            CALL MICROSERVICES
#########################################################

    def call_pick_and_place(self, device):
        pickandplace = PickAndPlace()
        return pickandplace.start_working(device)  # pick and place service

    def call_pick_and_insert(self, device):
        pickandinsert = PickAndInsert()
        return pickandinsert.start_working(device)  # pick and insert service

    def call_screw_pick_and_fasten(self, device):
        screwpickandfasten = ScrewPickAndFasten()
        return screwpickandfasten.start_working(
            device)  # screw pick and fasten service

    def call_pick_and_press(self, device):
        return "screw pick and press service "  # pick and press service

    def call_move(self, message, device):
        move = Move()
        return move.start_working(message, device)  # move service

    def call_pick_and_flip_and_press(self, device):
        pickandflipandpress = PickAndFlipAndPress()
        return pickandflipandpress.start_working(
            device)  # pick and flip and press service

    def stop_controller(self):
        return " ad"

    def wrong_message_response(self):
        return "wrong messsage received"

    @staticmethod
    def call_microservice(self, service):
        switcher = {
            "pick_and_place": self.call_pick_and_place(),
            "pick_and_insert": self.call_pick_and_insert(),
            "screw_pick_And_fasten": self.call_screw_pick_and_fasten(),
            "pick_and_press": self.call_pick_and_press(),
            "move": self.call_move(),
            "pick_and_flip_press": self.call_pick_and_flip_press(),
        }
        return switcher.get(service, self.wrong_message_response())

    def start_controller(self, device):
        while True:
            try:
                message_received = self.unix_server.read_data()
                print(message_received)
                sender_address = message_received["sender"]
                print(sender_address)
                if "PickAndPlace" in message_received:
                    response = self.call_pick_and_place(device)
                    if "FINISHED" in response:
                        print("controller free to service another call")
                        self.unix_client = UnixClient(str(sender_address))
                        self.unix_client.connect_client(str(sender_address))
                        self.unix_client.send_data(response)
                        self.unix_client.close_client()
                        print("\n \n \n \n ok")
                if "PickAndInsert" in message_received:
                    response = self.call_pick_and_insert(device)
                    if "FINISHED" in response:
                        print("controller free to service another call")
                        self.unix_client = UnixClient(str(sender_address))
                        self.unix_client.connect_client(str(sender_address))
                        self.unix_client.send_data(response)
                        self.unix_client.close_client()
                if "ScrewPickAndFasten" in message_received:
                    response = self.call_screw_pick_and_fasten(device)
                    if "FINISHED" in response:
                        print("controller free to service another call")
                        self.unix_client = UnixClient(str(sender_address))
                        self.unix_client.connect_client(str(sender_address))
                        self.unix_client.send_data(response)
                        self.unix_client.close_client()
                if "PickAndFlipAndPress" in message_received:
                    response = self.call_pick_and_flip_and_press(device)
                    if "FINISHED" in response:
                        print("controller free to service another call")
                        self.unix_client = UnixClient(str(sender_address))
                        self.unix_client.connect_client(str(sender_address))
                        self.unix_client.send_data(response)
                        self.unix_client.close_client()
                if "Move" in message_received:
                    position = message_received["Move"]
                    response = self.call_move(position, device)
                    print("\n \n \n \n \n " + str(position) +
                          "\n \n \n \n \n ")
                    if "REACHED" in response:
                        print("controller free to service another call")
                        self.unix_client = UnixClient(str(sender_address))
                        self.unix_client.connect_client(str(sender_address))
                        self.unix_client.send_data(response)
                        self.unix_client.close_client()

            except (ConnectionResetError, OSError) as e:
                print(e)