def run(self):

        self.messenger = interactive_system.Messenger(self, 0.0)

        for teensy_name in self.teensy_manager.get_teensy_name_list():
            # ------ set mode ------
            cmd_obj = interactive_system.command_object(teensy_name, 'basic')
            protocol = self.teensy_manager.get_protocol(teensy_name)
            cmd_obj.add_param_change('operation_mode', protocol.MODE_MANUAL_CONTROL)
            self.enter_command(cmd_obj)
        self.send_commands()

         # initially update the Teensys with all the output parameters here
        self.update_output_params(self.teensy_manager.get_teensy_name_list())

        # start the messenger
        self.messenger.start()

        teensy_in_use = tuple(self.teensy_manager.get_teensy_name_list())

         # instantiate all the basic components
        for teensy_name in teensy_in_use:

            # check if the teensy exists
            if teensy_name not in self.teensy_manager.get_teensy_name_list():
                print('%s does not exist!' % teensy_name)
                continue

            # check the type of node
            protocol = self.teensy_manager.get_protocol(teensy_name)

            # -- Cricket Node ---
            if isinstance(protocol, CP.WashingtonCricketProtocol):
                self.node_list.update(self.build_cricket_node_components(teensy_name, protocol.NUM_CRICKET, protocol.NUM_LIGHT))
            # -- Fin-Cricket Node ---
            elif isinstance(protocol, CP.WashingtonFinCricketProtocol):
                self.node_list.update(self.build_fin_cricket_node_components(teensy_name, protocol.NUM_FIN, protocol.NUM_CRICKET))
            # -- Fin Node ---
            elif isinstance(protocol, CP.WashingtonFinProtocol):
                self.node_list.update(self.build_fin_node_components(teensy_name, protocol.NUM_FIN))
            # -- Sound Node ---
            elif isinstance(protocol, CP.WashingtonSoundProtocol):
                self.node_list.update(self.build_sound_node_components(teensy_name, protocol.NUM_SOUND))

            # -- operation mode ----
            operation_mode_var = Abs.Output_Node(self.messenger, teensy_name, node_name="operation_mode_var",
                                                 output='operation_mode')
            self.node_list.update({operation_mode_var.node_name: operation_mode_var})

        self.start_nodes()

        with self.all_nodes_created:
            self.all_nodes_created.notify_all()


        # wait for the nodes to destroy
        for node in self.node_list.values():
            node.join()

        return 0
예제 #2
0
    def send_output_cmd(self, teensy, output):

        if output:
            if not isinstance(teensy, str):
                raise TypeError('Teensy name must be string!')

            cmd_obj = command_object(teensy, msg_setting=1)
        else:
            return


        for output_name, value in output:
            if isinstance(value, Var):
                value = value.val
            cmd_obj.add_param_change(output_name, value)

        self.messenger.load_message(cmd_obj)
    def init_utilities(self):

        self.messenger = interactive_system.Messenger(self, 0.0)

        for teensy_name in self.teensy_manager.get_teensy_name_list():
            # ------ set mode ------
            cmd_obj = interactive_system.command_object(teensy_name, 'basic')
            protocol = self.teensy_manager.get_protocol(teensy_name)
            cmd_obj.add_param_change('operation_mode', protocol.MODE_CBLA)
            self.enter_command(cmd_obj)
        self.send_commands()

         # initially update the Teensys with all the output parameters here
        self.update_output_params(self.teensy_manager.get_teensy_name_list())

        # start the messenger
        self.messenger.start()

        return 0
예제 #4
0
    def run(self):

        self.messenger = interactive_system.Messenger(self, 0.000)

        for teensy_name in self.teensy_manager.get_teensy_name_list():
            # ------ set mode ------
            cmd_obj = interactive_system.command_object(teensy_name, "basic")
            cmd_obj.add_param_change("operation_mode", CP.CBLATestBed_Triplet_FAST.MODE_CBLA2_MANUAL)
            self.enter_command(cmd_obj)

        self.send_commands()

        # initially update the Teensys with all the output parameters here
        self.update_output_params(self.teensy_manager.get_teensy_name_list())

        # start the messenger
        self.messenger.start()

        teensy_in_use = tuple(self.teensy_manager.get_teensy_name_list())

        # instantiate all the basic components
        for teensy in teensy_in_use:

            # check if the teensy exists
            if teensy not in self.teensy_manager.get_teensy_name_list():
                print("%s does not exist!" % teensy)
                continue

            # 3 fins
            for j in range(self.num_fin):

                # 2 ir sensors each
                ir_sensor_0 = Input_Node(
                    self.messenger, teensy, node_name="fin_%d.ir_0" % j, input="fin_%d_ir_0_state" % j
                )
                ir_sensor_1 = Input_Node(
                    self.messenger, teensy, node_name="fin_%d.ir_1" % j, input="fin_%d_ir_1_state" % j
                )

                self.node_list[ir_sensor_0.node_name] = ir_sensor_0
                self.node_list[ir_sensor_1.node_name] = ir_sensor_1

                # 1 3-axis acceleromter each
                acc = Input_Node(
                    self.messenger,
                    teensy,
                    node_name="fin_%d.acc" % j,
                    x="fin_%d_acc_x_state" % j,
                    y="fin_%d_acc_y_state" % j,
                    z="fin_%d_acc_z_state" % j,
                )
                self.node_list[acc.node_name] = acc

                # 2 SMA wires each
                sma_0 = Output_Node(
                    self.messenger, teensy, node_name="fin_%d.sma_0" % j, output="fin_%d_sma_0_level" % j
                )
                sma_1 = Output_Node(
                    self.messenger, teensy, node_name="fin_%d.sma_1" % j, output="fin_%d_sma_1_level" % j
                )

                self.node_list[sma_0.node_name] = sma_0
                self.node_list[sma_1.node_name] = sma_1

                # 1 fin
                motion_type = Var(0)
                # sma_param = {'KP': 15, 'K_heating': 0.00, 'K_dissipate': 0.05}
                fin = Fin(
                    self.messenger,
                    teensy,
                    node_name="fin_%d.fin" % j,
                    left_sma=sma_0.in_var["output"],
                    right_sma=sma_1.in_var["output"],
                    motion_type=motion_type,
                )
                # left_config=sma_param, right_config=sma_param)
                self.node_list[fin.node_name] = fin

                # 2 reflex each
                reflex_0 = Output_Node(
                    self.messenger, teensy, node_name="fin_%d.reflex_0" % j, output="fin_%d_reflex_0_level" % j
                )
                reflex_1 = Output_Node(
                    self.messenger, teensy, node_name="fin_%d.reflex_1" % j, output="fin_%d_reflex_1_level" % j
                )

                self.node_list[reflex_0.node_name] = reflex_0
                self.node_list[reflex_1.node_name] = reflex_1

            # for Interactive_Light
            for j in range(self.num_light):
                # 1 ambient light sensor
                als = Input_Node(self.messenger, teensy, node_name="light_%d.als" % j, input="light_%d_als_state" % j)
                self.node_list[als.node_name] = als
                # 1 led
                led = Output_Node(
                    self.messenger, teensy_name=teensy, node_name="light_%d.led" % j, output="light_%d_led_level" % j
                )
                self.node_list[led.node_name] = led

        with self.all_nodes_created:
            self.all_nodes_created.notify_all()

        self.start_nodes()

        # wait for the nodes to destroy
        for node in self.node_list.values():
            node.join()

        return 0
    def run(self):

        self.messenger = interactive_system.Messenger(self, 0.000)

        for teensy_name in self.teensy_manager.get_teensy_name_list():
            # ------ set mode ------
            cmd_obj = interactive_system.command_object(teensy_name, 'basic')
            cmd_obj.add_param_change('operation_mode', CP.CBLATestBed_Triplet_FAST.MODE_CBLA2_MANUAL)
            self.enter_command(cmd_obj)

        self.send_commands()

        # initially update the Teensys with all the output parameters here
        self.update_output_params(self.teensy_manager.get_teensy_name_list())

        self.messenger.start()

        teensy_in_use = tuple(self.teensy_manager.get_teensy_name_list())

        # instantiate all the basic components

        # data collector node
        data_variables = dict()

        for teensy in teensy_in_use:

            # check if the teensy exists
            if teensy not in self.teensy_manager.get_teensy_name_list():
                print('%s does not exist!' % teensy)
                continue

            # 3 fins
            for j in range(self.num_fin):
                # 2 ir sensors each
                ir_sensor_0 = Input_Node(self.messenger, teensy, node_name='fin_%d.ir_0' % j,
                                         input='fin_%d_ir_0_state' % j)
                ir_sensor_1 = Input_Node(self.messenger, teensy, node_name='fin_%d.ir_1' % j,
                                         input='fin_%d_ir_1_state' % j)

                self.node_list[ir_sensor_0.node_name] = ir_sensor_0
                self.node_list[ir_sensor_1.node_name] = ir_sensor_1

                # 1 3-axis accelerometer each
                acc = Input_Node(self.messenger, teensy, node_name='fin_%d.acc' % j,
                                 x='fin_%d_acc_x_state' % j,
                                 y='fin_%d_acc_y_state' % j,
                                 z='fin_%d_acc_z_state' % j)
                self.node_list[acc.node_name] = acc

                # 2 SMA wires each
                sma_0 = Output_Node(self.messenger, teensy, node_name='fin_%d.sma_0' % j,
                                    output='fin_%d_sma_0_level' % j)
                sma_1 = Output_Node(self.messenger, teensy, node_name='fin_%d.sma_1' % j,
                                    output='fin_%d_sma_1_level' % j)

                self.node_list[sma_0.node_name] = sma_0
                self.node_list[sma_1.node_name] = sma_1

                # 1 frond
                # motion_type = Var(0)
                sma_param = None# {'KP': 15, 'K_heating': 0.00, 'K_dissipate': 0.05}
                # fin = Cycling_Fin(self.messenger, teensy, node_name='fin_%d.fin' % j,
                #                     left_sma=sma_0.in_var['output'],
                #                     right_sma=sma_1.in_var['output'], motion_type=motion_type)
                # # left_config=sma_param, right_config=sma_param)
                # self.node_list[fin.node_name] = fin

                # 2 half fins
                temp_ref_0 = Var(0)
                halfFin_0 = CyclingHalfFin(self.messenger, node_name='%s.fin_%d.halfFin-0' % (teensy, j),
                                           sma=sma_0.in_var['output'], temp_ref=temp_ref_0,
                                           config=sma_param)
                temp_ref_1 = Var(0)
                halfFin_1 = CyclingHalfFin(self.messenger, node_name='%s.fin_%d.halfFin-1' % (teensy, j),
                                           sma=sma_1.in_var['output'], temp_ref=temp_ref_1,
                                           config=sma_param)

                self.node_list[halfFin_0.node_name] = halfFin_0
                self.node_list[halfFin_1.node_name] = halfFin_1

                # 2 reflex each
                reflex_0 = Output_Node(self.messenger, teensy, node_name='fin_%d.reflex_0' % j,
                                       output='fin_%d_reflex_0_level' % j)
                reflex_1 = Output_Node(self.messenger, teensy, node_name='fin_%d.reflex_1' % j,
                                       output='fin_%d_reflex_1_level' % j)

                self.node_list[reflex_0.node_name] = reflex_0
                self.node_list[reflex_1.node_name] = reflex_1

                # # acc diff
                # acc_x_diff = Pseudo_Differentiation(self.messenger, node_name='%s.fin_%d.acc_x_diff' % (teensy, j),
                #                                     input_var=acc.out_var['x'], diff_gap=15, smoothing=30,
                #                                     step_period=0.1)
                # acc_y_diff = Pseudo_Differentiation(self.messenger, node_name='%s.fin_%d.acc_y_diff' % (teensy, j),
                #                                     input_var=acc.out_var['y'], diff_gap=15, smoothing=30,
                #                                     step_period=0.1)
                # acc_z_diff = Pseudo_Differentiation(self.messenger, node_name='%s.fin_%d.acc_z_diff' % (teensy, j),
                #                                     input_var=acc.out_var['z'], diff_gap=15, smoothing=30,
                #                                     step_period=0.1)
                #
                # self.node_list[acc_x_diff.node_name] = acc_x_diff
                # self.node_list[acc_y_diff.node_name] = acc_y_diff
                # self.node_list[acc_z_diff.node_name] = acc_z_diff
                #
                # # acc running average
                # acc_x_avg = Running_Average(self.messenger, node_name='%s.fin_%d.acc_x_avg' % (teensy, j),
                #                             input_var=acc.out_var['x'], avg_window=10, step_period=0.1)
                # acc_y_avg = Running_Average(self.messenger, node_name='%s.fin_%d.acc_y_avg' % (teensy, j),
                #                             input_var=acc.out_var['y'], avg_window=10, step_period=0.1)
                # acc_z_avg = Running_Average(self.messenger, node_name='%s.fin_%d.acc_z_avg' % (teensy, j),
                #                             input_var=acc.out_var['z'], avg_window=10, step_period=0.1)
                #
                # self.node_list[acc_x_avg.node_name] = acc_x_avg
                # self.node_list[acc_y_avg.node_name] = acc_y_avg
                # self.node_list[acc_z_avg.node_name] = acc_z_avg

                # collecting data
                data_variables['%s.fin_%d.ir_0' % (teensy, j)] = ir_sensor_0.out_var['input']
                data_variables['%s.fin_%d.ir_1' % (teensy, j)] = ir_sensor_1.out_var['input']

                data_variables['%s.fin_%d.acc_x' % (teensy, j)] = acc.out_var['x']
                data_variables['%s.fin_%d.acc_y' % (teensy, j)] = acc.out_var['y']
                data_variables['%s.fin_%d.acc_z' % (teensy, j)] = acc.out_var['z']

                # data_variables['%s.fin_%d.acc_x_diff' % (teensy, j)] = acc_x_diff.out_var['output']
                # data_variables['%s.fin_%d.acc_y_diff' % (teensy, j)] = acc_y_diff.out_var['output']
                # data_variables['%s.fin_%d.acc_z_diff' % (teensy, j)] = acc_z_diff.out_var['output']
                # data_variables['%s.fin_%d.acc_x_avg' % (teensy, j)] = acc_x_avg.out_var['output']
                # data_variables['%s.fin_%d.acc_y_avg' % (teensy, j)] = acc_y_avg.out_var['output']
                # data_variables['%s.fin_%d.acc_z_avg' % (teensy, j)] = acc_z_avg.out_var['output']

                data_variables['%s.fin_%d.sma_0' % (teensy, j)] = sma_0.in_var['output']
                data_variables['%s.fin_%d.sma_1' % (teensy, j)] = sma_1.in_var['output']
                # data_variables['%s.fin_%d.fin' % (teensy, j)] = fin.in_var['motion_type']
                data_variables['%s.fin_%d.halfFin_0' % (teensy, j)] = halfFin_0.in_var['temp_ref']
                data_variables['%s.fin_%d.halfFin_1' % (teensy, j)] = halfFin_1.in_var['temp_ref']



            # for Interactive_Light
            for j in range(self.num_light):

                # 1 ambient light sensor
                als = Input_Node(self.messenger, teensy, node_name='light_%d.als' % j,
                                 input='light_%d_als_state' % j)
                self.node_list[als.node_name] = als

                # 1 led
                led = Output_Node(self.messenger, teensy_name=teensy, node_name='light_%d.led' % j,
                                  output='light_%d_led_level' % j )
                self.node_list[led.node_name] = led

                # collecting their values
                data_variables['%s.light_%d.led' % (teensy, j)] = led.in_var['output']
                data_variables['%s.light_%d.als' % (teensy, j)] = als.out_var['input']

        self.data_collector = Data_Collector_Node(self.messenger, file_header='sys_id_data',
                                                  data_collect_period=0.05, create_new_log=True, **data_variables)

        with self.all_nodes_created:
            self.all_nodes_created.notify_all()

        self.start_nodes()
        self.data_collector.start()

        # wait for the nodes to destroy
        for node in self.node_list.values():
            node.join()

        return 0
    def run(self):

        self.messenger = interactive_system.Messenger(self, 0.000)

        for teensy_name in self.teensy_manager.get_teensy_name_list():
            # ------ set mode ------
            cmd_obj = interactive_system.command_object(teensy_name, 'basic')
            cmd_obj.add_param_change('operation_mode', CP.CBLATestBed_Triplet_FAST.MODE_CBLA2_PRESCRIPTED)
            self.enter_command(cmd_obj)

        self.send_commands()

        # initially update the Teensys with all the output parameters here
        self.update_output_params(self.teensy_manager.get_teensy_name_list())

        # start the messenger
        self.messenger.start()

        teensy_in_use = tuple(self.teensy_manager.get_teensy_name_list())

        # table of all data variables being collected
        data_variables = dict()

        # instantiate all the basic components
        for teensy in teensy_in_use:

            # check if the teensy exists
            if teensy not in self.teensy_manager.get_teensy_name_list():
                print('%s does not exist!' % teensy)
                continue

             # ==== creating components related to the Light =====
            light_components = OrderedDict()
            for j in range(self.num_light):
                components, data_vars = self.build_light_components(teensy_name=teensy, light_id=j)
                light_components.update(components)
                data_variables.update(data_vars)
            self.node_list.update(light_components)

            # ===== creating components for related to the Fins ====
            fin_components = OrderedDict()
            for j in range(self.num_fin):
                components, data_vars = self.build_fin_components(teensy_name=teensy, fin_id=j)
                fin_components.update(components)
                data_variables.update(data_vars)
            self.node_list.update(fin_components)

        # ===== creating the CBLA Nodes ====
        if self.mode == 'default':
            for teensy in teensy_in_use:
                self.node_list.update(self.build_default_nodes(teensy, self.node_list))
        else:
            self.mode = 'default'
            for teensy in teensy_in_use:
                self.node_list.update(self.build_default_nodes(teensy, self.node_list))

        self.data_collector = Data_Collector_Node(self.messenger, file_header='prescripted_mode_data',
                                                  data_collect_period=0.5, create_new_log=True,
                                                  log_save_freq=5.0, logger_sleep_time=0.05,
                                                  **data_variables)

        with self.all_nodes_created:
            self.all_nodes_created.notify_all()

        self.start_nodes()
        self.data_collector.start()

        # wait for the nodes to destroy
        for node in self.node_list.values():
            node.join()

        return 0