From: Pierre C. <Ba...@us...> - 2011-05-29 17:23:59
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 3a6ff5c10518195cb32e982dd6650e87d204f66f (commit) from 97c00ff7a3292278cb11474f3432f40d9f9a09fb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 3a6ff5c10518195cb32e982dd6650e87d204f66f Author: chambart <cha...@cr...> Date: Sun May 29 19:23:10 2011 +0200 [info] avoid wall in pathfinding ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_pathfinding.ml b/info/control2011/src/lib/krobot_pathfinding.ml index 47f77d8..be9b3fa 100644 --- a/info/control2011/src/lib/krobot_pathfinding.ml +++ b/info/control2011/src/lib/krobot_pathfinding.ml @@ -129,7 +129,8 @@ include Tangentes type board = { src : point; dst : point; - obstacles : circle list; } + obstacles : circle list; + box : point*point } type tangente = { orig : point; @@ -143,16 +144,17 @@ type result = { path : segment list; length : float } +let middle s p = + ( scal + (vect s.p1 s.p2) + (vect s.p1 p) >= 0. ) + && ( scal + (vect s.p2 s.p1) + (vect s.p2 p) >= 0. ) + + let distance' s nv p = - let middle = - ( scal - (vect s.p1 s.p2) - (vect s.p1 p) >= 0. ) - && ( scal - (vect s.p2 s.p1) - (vect s.p2 p) >= 0. ) - in - if middle + if middle s p then abs_float (scal (turn_trigo nv) (vect s.p1 p)) else @@ -233,6 +235,9 @@ let intersect l1 l2 = let after {p1;p2} p = scal (vect p1 p2) (vect p2 p) >= 0. +let in_box (p1,p2) p = + p1.px <= p.px && p1.py <= p.py && p2.px >= p.px && p2.py >= p.py + let make_tangente b t c ({p1;p2} as s) = if (scal (line s).v (vect t.contact t.circle.c) >= 0.) && (check_segment_circle b (t.circle,c) s) @@ -242,7 +247,8 @@ let make_tangente b t c ({p1;p2} as s) = match intersect l1 l2 with | None -> None | Some inter -> - if (after {p1 = t.orig;p2 = t.contact} inter) + if (in_box b.box inter) + && (after {p1 = t.orig;p2 = t.contact} inter) && (check_segment_circle b (t.circle,c) {p1 = inter; p2 = t.contact}) then Some { distance = norm (vect t.orig inter) +. t.distance; @@ -336,8 +342,14 @@ let v_of_vertice { Krobot_geom.x; y } = let vertice_of_seg { p1 = {px;py} } = { Krobot_geom.x = px; y = py } -let find_path ~src ~dst objects = - let b = { src = v_of_vertice src; - dst = v_of_vertice dst; - obstacles = List.map (fun (v,r) -> { c = v_of_vertice v; r }) objects; } in - map_option (fun res -> List.rev_map vertice_of_seg res.path) (fst (stepn b 10)) +let find_path ~src ~dst (box_min,box_max) objects = + let box = (v_of_vertice box_min, v_of_vertice box_max) in + let dst = v_of_vertice dst in + if not (in_box box dst) + then None + else + let b = { src = v_of_vertice src; + dst; + obstacles = List.map (fun (v,r) -> { c = v_of_vertice v; r }) objects; + box } in + map_option (fun res -> List.rev_map vertice_of_seg res.path) (fst (stepn b 10)) diff --git a/info/control2011/src/lib/krobot_pathfinding.mli b/info/control2011/src/lib/krobot_pathfinding.mli index 3719e4c..1b6644d 100644 --- a/info/control2011/src/lib/krobot_pathfinding.mli +++ b/info/control2011/src/lib/krobot_pathfinding.mli @@ -1,6 +1,9 @@ +open Krobot_geom + val find_path : - src:Krobot_geom.vertice -> - dst:Krobot_geom.vertice -> - ( Krobot_geom.vertice * float ) list -> - Krobot_geom.vertice list option + src:vertice -> + dst:vertice -> + vertice * vertice -> + ( vertice * float ) list -> + vertice list option diff --git a/info/control2011/src/tools/krobot_planner.ml b/info/control2011/src/tools/krobot_planner.ml index 312deea..b47756e 100644 --- a/info/control2011/src/tools/krobot_planner.ml +++ b/info/control2011/src/tools/krobot_planner.ml @@ -71,9 +71,13 @@ let border_safety_distance = sqrt (sqr robot_size /. 2.) +. 0.05 let object_safety_distance = object_radius +. robot_size /. 2. let find_path planner src dst = - let objects = List.filter (fun obj -> distance dst obj >= object_radius) planner.objects in + let objects = List.filter (fun obj -> distance dst obj >= object_safety_distance) planner.objects in match Krobot_pathfinding.find_path ~src ~dst + ({ x = border_safety_distance; + y = border_safety_distance}, + { x = world_width -. border_safety_distance; + y = world_height -. border_safety_distance}) (List.map (fun v -> v,object_safety_distance) objects) with | None -> [] hooks/post-receive -- krobot |