def main(args=None): maude.init() rclpy.init(args=args) maude_publisher = MaudePublisher() rclpy.spin(maude_publisher) # Destroy the node explicitly # (optional - otherwise it will be done automatically # when the garbage collector destroys the node object) maude_publisher.destroy_node() rclpy.shutdown()
("astar-iteration-vc13", "Queue nonempty, front position open: postcondition follows"), ("astar-iteration-vc14", "Queue empty, and next as well: precondition of recursive call"), ("astar-iteration-vc15", "Queue empty, and next as well: postcondition"), ("astar-iteration-vc16", "Queue empty, but not next: precondition of recursive call"), ("astar-iteration-vc17", "Queue empty, but not next: postcondition"), ]), ("ASTAR-VERIF", [ "Pose", "Pose", "CostMap", "Integer", "PotentialMap", "Real", "Real", "PoseQueue", "PoseQueue", "PoseQueue" ], [ ("astar-vc1", "Call to BuildInitialPotentialMap meets precondition"), ("astar-vc2", "Call to EuclidDistance meets precondition"), ("astar-vc3", "Call to InitCurrentQueue meets precondition"), ("astar-vc4", "Call to AStarIteration meets precondition"), ]) ] if __name__ == '__main__': maude.init() maude.load('vcs_navfnplanner.maude') for (mod_name, sorts, vcs) in modules: vm = VerificationModule(mod_name, sorts) for (name, description) in vcs: vm.add_vc(name, description) vm.check()
import maude except ImportError: print( 'Giving the name of the fractal implies using the maude library ' 'to compute it, but it does not seem to be available.\nIt can be ' 'installed with «pip install maude». Otherwise, the fractal term ' 'can be copied here from Maude.') maude = None else: maude = None # Compute the fractal with Maude if maude is not None: maude.init(advise=False) maude.load('fractals.maude') # Looks for the given fractal as view if maude.getView(args.fractal) is None: print(f'The given fractal «{args.fractal}» is not defined.') sys.exit(1) # Instantiate the fractal module with the given view maude.input( f'smod FRACTALS-TEMPORARY-MODULE is protecting FRACTALS-STRAT{{{args.fractal}}} . endsm' ) m = maude.getCurrentModule() t = m.parseTerm('(0.0, 0.0) >> (1.0, 0.0)') s = m.parseStrategy(f'expandTimes({args.times})')
default='maude,ltsmin,pymc,nusmv,builtin') parser.add_argument('--verbose', '-v', help='Show more information', action='store_true') parser.add_argument('--no-advise', help='Disable advises from Maude', action='store_true') args = parser.parse_args() if args.initial is not None and args.strategy is None: print('An initial term was given, but not a strategy.') sys.exit(1) maude.init(advise=not args.no_advise) maude.load('opsem') # Benchmarking if args.strategy is None: test_benchmark(args.file) sys.exit(0) # Build the instance of the operational semantics for the given problem instance, t = build_instance(args.file, args.initial, args.strategy, args.module) # If no formula is given, we only rewrite the term and show the results if args.formula is None: srewrite(instance, t) sys.exit(0)
def __init__(self, implementation='a*', map_in_python=True): super().__init__('maude_planner_action_server' ) # Node name, could be changed to fit the BT maude.init() maude.load(self.ASTAR_MAUDE_PATH[implementation]) self.astar_module = maude.getModule('ASTAR') if self.astar_module is None: self.get_logger().fatal( 'Cannot find Maude ASTAR module in {}'.format( self.ASTAR_MAUDE_PATH[implementation])) else: self.get_logger().info('Maude planner node is ready') self.occupancy_grid = None # It will be read and updated from the map topic self.maude_map = None self.amcl_pose = None # It will be read and updated from the topic /amcl_pose # Configures the action server to respond to ComputePathToPose actions self._action_server = ActionServer(self, ComputePathToPose, 'ComputePathToPose', self.action_callback) # Listen to map topic self._map_subscription = self.create_subscription( OccupancyGrid, 'global_costmap/costmap', self.map_callback, 10) # Queue size # Listen to topic /amcl_pose self._amcl_pose_subscription = self.create_subscription( PoseWithCovarianceStamped, 'amcl_pose', self.amcl_pose_callback, 10) # Queue size # Plan publisher (so that it is represented in the view) self._plan_publisher = self.create_publisher(Path, '/plan', 10) # Connect the Maude special operator to the map self.map_in_python = map_in_python if map_in_python: if implementation == 'a*': self.map_hook = MapProvider(self, self.astar_module) maude.connectEqHook('open2?', self.map_hook) else: self.map_hook = MapProviderGet(self) maude.connectEqHook('get', self.map_hook) # Find sorts and operators needed to construct the a* term # (once for all) m = self.astar_module pose_kind = m.findSort('Pose').kind() costmap_kind = m.findSort('CostMap').kind() float_kind = m.findSort('Float').kind() path_kind = m.findSort('Path').kind() int_kind = m.findSort('IntList').kind() # Init Goal NumRow NumCol # op a* : Pose Pose CostMap Float Float -> Path . self.astar_symb = m.findSymbol( self.ASTAR_OPNAME[implementation], [pose_kind, pose_kind, costmap_kind, float_kind, float_kind], path_kind) self.intlist_symb = m.findSymbol('_`,_', [int_kind] * 2, int_kind) self.cmap_symb = m.findSymbol('`{_`}', [int_kind], costmap_kind) # Constants that will be used multiple times self.zero_term = m.parseTerm('0') self.one_term = m.parseTerm('1') self.mtIL_term = m.parseTerm('mtIL')
def __init__(self, test_path, obtain_navfn=True): with open(test_path, 'r') as ftest: lines = ftest.readlines() self.w, self.h = lines[0].strip().split() self.w = int(self.w) self.h = int(self.h) self.map_bin_file = lines[1].strip() # Filename relative to the test case self.map_data = [0] * (self.w * self.h) # Avoid appending test_full_path = os.path.abspath(ftest.name) test_dir = os.path.dirname(test_full_path) map_full_map_path = os.path.join(test_dir, self.map_bin_file) self.map_bin_file = map_full_map_path # Full path with open(self.map_bin_file, 'rb') as fmap: for i in range(self.w * self.h): cell = fmap.read(1) self.map_data[i] = int.from_bytes(cell, 'big') # It's one byte, it doesn't matter big or little endian self.test_cases = list() for test in lines[3:]: if test.strip().startswith('-1'): continue x0, y0, x1, y1 = [float(c) for c in test.strip().split()] self.test_cases.append(((x0, y0, 0.0), (x1, y1, 0.0))) # Orientation 0 degrees maude.init() maude.load(self.ASTAR_MAUDE_PATH) # Find sorts and operators needed to construct the a* term self.m = maude.getModule('ASTAR') pose_kind = self.m.findSort('Pose').kind() costmap_kind = self.m.findSort('CostMap').kind() float_kind = self.m.findSort('Float').kind() path_kind = self.m.findSort('Path').kind() int_kind = self.m.findSort('IntList').kind() nat_kind = self.m.findSort('Nat').kind() potential_kind = self.m.findSort('Potential').kind() gradient_kind = self.m.findSort('Gradient').kind() # We need it to solve an ambiguity later self.pose_kind = pose_kind # Use different functions whether obtaining the potential or not if not obtain_navfn: self.astar = self.m.findSymbol('a*', [pose_kind, pose_kind, costmap_kind] + [nat_kind] * 4, path_kind) self.get_potential = None self.compute_path = None else: self.astar = None # op getPotential : Pose Pose CostMap Nat Nat Nat -> Potential . self.get_potential = self.m.findSymbol('getPotential', [pose_kind, pose_kind, costmap_kind, nat_kind, nat_kind, nat_kind], potential_kind) # op computePath : CostMap Potential Pose Pose Float Gradient Nat Nat Nat -> Path . self.compute_path = self.m.findSymbol('computePath', [potential_kind, pose_kind, pose_kind, float_kind, gradient_kind, nat_kind, nat_kind, nat_kind], path_kind) intlist = self.m.findSymbol('_`,_', [int_kind] * 2, int_kind) cmap = self.m.findSymbol('`{_`}', [int_kind], costmap_kind) self.pattern = self.m.parseTerm('{ X:Float, Y:Float, Z:Float } O:Nat') self.mod = self.m # Constants that will be used multiple times zero = self.m.parseTerm('0') one = self.m.parseTerm('1') mtIL = self.m.parseTerm('mtIL') self.noPath = self.m.parseTerm('noPath') self.empyList = self.m.parseTerm('nil') # Dictionary with Maude integer terms from 0 to 255 to avoid parsing # when constructing the map_list in Maude int_terms = dict() for i in range(0,256): int_terms[i] = self.m.parseTerm(str(i)) # Build the IntList with the costmap data map_list = mtIL # There is no need to build the map, because it will be read from the hook # for c in self.map_data: # map_list = intlist(map_list, int_terms[c]) cycles = str(max(int(self.w * self.h / 20), self.w + self.h)) # Same number of cycles as ROS path_cycles = str(4 * self.w) self.static_args = [ cmap(map_list), self.m.parseTerm(str(int(self.w))), self.m.parseTerm(str(int(self.h))), self.m.parseTerm(cycles), self.m.parseTerm(path_cycles), ] # Hook for "op get : CostMap Nat Nat Nat -> Float" class MapHook(maude.Hook): def __init__(self, parent): super().__init__() self.parent = parent # DirectProfiler object to access attributes as the map or the Maude module for parsing self.cache = dict() # Dictionary int in [0..255] -> Maude term representing the corresponding Float for i in range(0, 256): self.cache[i] = self.parent.m.parseTerm(str(float(i))) def run(self, term, data): try: _, x, y, ncols = [int(arg) for arg in term.arguments()] cell_value = self.parent.map_data[y * ncols + x] ret_term = self.cache[cell_value] # print(f'FAST {term} --> {ret_term}') return ret_term except Exception as e: print('hook:', e) self.mapHook = MapHook(self) maude.connectEqHook('get', self.mapHook)
def parse_initial_data(args): """Inits Maude and parse common initial data of a model-checking problem""" maude.init(advise=args.advise) data = InitialData() # Checks whether the file exists data.filename = find_maude_file(args.file) if data.filename is None: usermsgs.print_error('No such file.') return None if not maude.load(args.file): usermsgs.print_error('Error loading file') return None # Loads the module if args.module is None: data.module = maude.getCurrentModule() if data.module is None: usermsgs.print_error('No last module.') return None else: data.module = maude.getModule(args.module) if data.module is None: usermsgs.print_error(f'Module {args.module} does not exist.') return None # Loads a metamodule (if required) if args.metamodule is not None: mt = data.module.parseTerm(args.metamodule) if mt is None: usermsgs.print_error('Bad parse for metamodule term.') return None data.metamodule = mt data.module = maude.downModule(mt) if data.module is None: usermsgs.print_error('Bad metamodule.') return None # Parse the initial term data.term = data.module.parseTerm(args.initial) if data.term is None: usermsgs.print_error('Bad parse for initial term') return None # Parse the strategy if args.strategy is not None: data.strategy = data.module.parseStrategy(args.strategy) if data.strategy is None: usermsgs.print_error('Bad parse for strategy') return None else: data.strategy = None # Opaque strategies and full matchrew data.opaque = [] if args.opaque == '' else args.opaque.split(',') data.full_matchrew = args.full_matchrew return data