def gen_states_str(self):
     """
     Return a string version of the states parameters for the
     ConcurrentState.
     """
     states_str = "{"
     # Key should be in quotes, but not the value
     dict_items = ["'{0}': {1}".format(label, class_decl_to_string(class_decl))
                   for (label, class_decl)
                   in self.internal_states.items()]
     states_str += ", ".join(dict_items)
     states_str += "}"
     return states_str
Ejemplo n.º 2
0
 def gen_states_str(self):
     """
     Return a string version of the states parameters for the
     ConcurrentState.
     """
     states_str = "{"
     # Key should be in quotes, but not the value
     dict_items = [
         "'{0}': {1}".format(label, class_decl_to_string(class_decl))
         for (label, class_decl) in self.internal_states.items()
     ]
     states_str += ", ".join(dict_items)
     states_str += "}"
     return states_str
 def get_out_map(self, class_decl):
     """Get the output mapping associated with a class declaration."""
     class_decl_str = class_decl_to_string(class_decl)
     return self.class_decl_to_out_map[class_decl_str]
    def __init__(self, config, all_in_vars, all_out_vars, automata):
        self.config = config

        # List of in/out vars of the substates
        self.all_in_vars = all_in_vars
        self.all_out_vars = all_out_vars

        self.automata = automata

        # Map from what a substate thinks is the final transition to what it
        # actually should be (e.g. "done" -> "finished")
        self.sm_fake_out_to_real_out = config['output']

        # List of outputs of the entire SM
        self.sm_fake_outputs = self.sm_fake_out_to_real_out.keys()

        # To exit this SM, we find states that should exit. At the end, we'll
        # make any transition that goes to one of these states go to the real
        # output.
        self.state_name_to_sm_output = self.get_state_name_to_sm_output()

        """
        Populate various dictionaries to future functions. These lines
        should should be at the end of the initializer
        """
        # what class declaration goes with an input variable?
        self.in_var_to_class_decl = {}
        # to map response variables back to their activation variable
        self.in_var_to_out_var = {}
        # the map from class declaration to its out_map
        self.class_decl_to_out_map = {}

        try:
            for out_var, var_config in self.config.items():
                # If class_decl isn't in var_config,
                # it's not configuration for a state
                if 'class_decl' not in var_config:
                    continue
                class_decl = var_config['class_decl']
                out_map = var_config['output_mapping']
                class_decl_str = class_decl_to_string(class_decl)
                self.class_decl_to_out_map[class_decl_str] = out_map
                for in_var, state_outcome in out_map.items():
                    # check if this is a response variable
                    if in_var in self.all_in_vars and out_var in self.all_out_vars:
                        self.in_var_to_class_decl[in_var] = class_decl
                        self.in_var_to_out_var[in_var] = out_var

            # Make one more pass to handle environment propositions
            for in_var in self.all_in_vars:

                if not self.is_response_var(in_var): # it's a sensor prop
                    var_config = self.config[in_var]
                    class_decl = var_config['class_decl']
                    out_map = var_config['output_mapping']
                    class_decl_str = class_decl_to_string(class_decl)
                    self.class_decl_to_out_map[class_decl_str] = out_map

        except KeyError:
            rospy.logerr("The configuration file is invalid.")
            raise SMGenError(SynthesisErrorCodes.CONFIG_FILE_INVALID)