Commits

bergsoe  committed 0419079

Cleanup of the planner types.

  • Participants
  • Parent commits 255a97a

Comments (0)

Files changed (4)

File src/PaplPlanner.ml

 
 type 'a region_pair_t = 'a region_t pair_t
 
-(* path *)
-
-type ('target, 'q) t =
-    PaplStopCriteria.t -> 'target -> 'q list
+exception Path_not_found of string
 
-type ('target, 'q) option_t =
-    PaplStopCriteria.t -> 'target -> 'q list option
+type ('target, 'result) t = PaplStopCriteria.t -> 'target -> 'result
 
-type 'a point_t = ('a * 'a, 'a) t
+type ('target, 'result) option_t = ('target, 'result option) t
 
-type 'a sampler_t = ('a region_pair_t, 'a) t
+type ('target, 'q) path_t = ('target, 'q list) t
 
-(* trajectory *)
+type 'a point_t = ('a * 'a, 'a) path_t
 
-type ('target, 'q) trajectory_t =
-    PaplStopCriteria.t -> 'target -> 'q PaplTrajectory.t
+type 'a sampler_t = ('a region_pair_t, 'a) path_t
 
-type 'q point_trajectory_t =
-    ('q * 'q, 'q) trajectory_t
+type ('target, 'q) trajectory_t = ('target, 'q PaplTrajectory.t) t
 
-type 'a sampler_trajectory_t =
-    ('a list PaplSampler.t pair_t, 'a) trajectory_t
+type 'q point_trajectory_t = ('q * 'q, 'q) trajectory_t
 
-exception Path_not_found of string
+type 'a sampler_trajectory_t = ('a region_pair_t, 'a) trajectory_t
 
 let fail msg = raise (Path_not_found msg)
 
   in
     planner
 
-let bind_target f planner = fun stop target -> planner stop (f target)
+let bind_target f planner = ();
+  fun stop target -> planner stop (f target)
 
-let map_path f planner =
-  fun stop target -> List.map f (planner stop target)
+let map_result f planner = ();
+  fun stop target -> f (planner stop target)
 
 let point_to_sampler_target target =
   BatPair.map (fun q -> BatList.enum [[q]]) target
     sp
 
 module Trajectory = struct
-  let to_trajectory convert path_planner =
-    let planner stop target =
-      convert (path_planner stop target)
-    in
-      planner
-
   let of_metric ?t0 interpolate metric path_planner =
-    to_trajectory
-      (PaplTrajectory.of_path ?t0 interpolate metric)
+    map_result
+      (fun path -> PaplTrajectory.of_path ?t0 interpolate metric path)
       path_planner
 end
 
   type a_t
   type b_t
 
-  val planner : (a_t * b_t, q_t) t
+  val planner : (a_t * b_t, q_t) path_t
 end
 
 module type POINT_BIDIR = sig

File src/PaplPlanner.mli

 
 exception Path_not_found of string
 
-(** {3 Path planner types} *)
+(** {3 General planner types} *)
 
-type ('target, 'q) t =
-    PaplStopCriteria.t -> 'target -> 'q list
+type ('target, 'result) t = PaplStopCriteria.t -> 'target -> 'result
 
-type ('target, 'q) option_t =
-    PaplStopCriteria.t -> 'target -> 'q list option
+type ('target, 'result) option_t = ('target, 'result option) t
 
-type 'a point_t = ('a * 'a, 'a) t
+(** {3 Path planner types} *)
 
-type 'a sampler_t = ('a region_pair_t, 'a) t
+type ('target, 'q) path_t = ('target, 'q list) t
 
-(** {3 Trajectory planner types} *)
+type 'a point_t = ('a * 'a, 'a) path_t
 
-type ('target, 'q) trajectory_t =
-    PaplStopCriteria.t -> 'target -> 'q PaplTrajectory.t
+type 'a sampler_t = ('a region_pair_t, 'a) path_t
 
-type 'q point_trajectory_t =
-    ('q * 'q, 'q) trajectory_t
+(** {3 Trajectory planner types} *)
+
+type ('target, 'q) trajectory_t = ('target, 'q PaplTrajectory.t) t
 
-type 'a sampler_trajectory_t =
-    ('a region_pair_t, 'a) trajectory_t
+type 'q point_trajectory_t = ('q * 'q, 'q) trajectory_t
 
-(** {2 Miscellaneous} *)
+type 'a sampler_trajectory_t = ('a region_pair_t, 'a) trajectory_t
 
-val to_option : ('target, 'q) t -> ('target, 'q) option_t
+(** {2 General planner operations} *)
 
 val fail : string -> 'a
 (** [fail msg] raises [Path_not_found msg]. *)
 
-(** {3 Path planner operations} *)
-
-val bind_target : ('b -> 'a) -> ('a, 'q) t -> ('b, 'q) t
+val to_option : ('target, 'result) t -> ('target, 'result) option_t
+(** [to_option planner] calls [planner] and returns [Some result] if the planner
+    succesfully returns [result] and [None] if the planner throws a
+    [Path_not_found] exception.
+*)
 
-val map_path : ('q -> 'r) -> ('a, 'q) t -> ('a, 'r) t
+val bind_target :
+  ('target2 -> 'target1) ->
+  ('target1, 'result) t ->
+  ('target2, 'result) t
 
-val sampler_to_point_planner : 'a sampler_t -> 'a point_t
+val map_result :
+  ('result1 -> 'result2) ->
+  ('target, 'result1) t ->
+  ('target, 'result2) t
 
-val point_to_sampler_planner : 'a point_t -> 'a sampler_t
-(**
-   The sampler planner [sp = point_to_sampler_planner pp] calls the point
-   planner [pp] for the first pair of points retrieved from the regions.
-   If [pp] fails to connect those points then [sp] fails too.
+val sampler_to_point_planner :
+  ('a region_t pair_t, 'result) t ->
+  ('a pair_t, 'result) t
 
-   The stop criteria is called for every polling of the region. If a region is
-   empty or the stop criteria says stop before a point in the region is found,
-   then [sp] fails too.
-*)
+val point_to_sampler_planner :
+  ('a pair_t, 'result) t ->
+  ('a region_t pair_t, 'result) t
 
 (** {3 Trajectory planner operations} *)
 
 module Trajectory : sig
-  val to_trajectory :
-    ('a list -> 'b PaplTrajectory.t) ->
-    ('target, 'a) t ->
-    ('target, 'b) trajectory_t
-  (** Path planner to trajectory planner conversion.
-
-      [to_trajectory convert planner] calls [convert] on the path of [planner] to
-      convert the result to a trajectory type.
-  *)
-
   val of_metric :
     ?t0:float ->
     'a PaplInterpolate.t ->
     'a PaplMetric.t ->
-    ('target, 'a) t ->
+    ('target, 'a) path_t ->
     ('target, 'a) trajectory_t
   (** Path planner to trajectory planner conversion.
   *)
   type a_t
   type b_t
 
-  val planner : (a_t * b_t, q_t) t
+  val planner : (a_t * b_t, q_t) path_t
 end
 
 module type POINT_BIDIR = sig

File src/PaplTime.ml

 end
 
 module Planner = struct
-
   let points_are_unordered (start, goal) = goal.time < start.time
 
   let fail_if_unordered target =
       PaplPlanner.fail "Distance in time from start to goal too great"
 
   let to_trajectory interpolate path_planner =
-    PaplPlanner.Trajectory.to_trajectory
-      (Trajectory.of_path interpolate)
+    PaplPlanner.map_result
+      (fun path -> Trajectory.of_path interpolate path)
       path_planner
 end
 

File src/PaplTime.mli

 module Planner : sig
   val to_trajectory :
     'q t PaplInterpolate.t ->
-    ('target, 'q t) PaplPlanner.t ->
+    ('target, 'q t) PaplPlanner.path_t ->
     ('target, 'q) PaplPlanner.trajectory_t
 (** Path planner to trajectory planner conversion.