From: Jérémie D. <Ba...@us...> - 2011-04-26 15:49:15
|
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 896f3b133a8cb61279c49959082fb53ee066fb6b (commit) from fa8932bc991c708686e7813f52e5d441c1f3b966 (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 896f3b133a8cb61279c49959082fb53ee066fb6b Author: Jérémie Dimino <je...@di...> Date: Mon Apr 25 22:41:19 2011 +0200 [info] handle backward trajectories ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/src/lib/krobot_geom.ml b/info/control2011/src/lib/krobot_geom.ml index 7ca6909..8f09d85 100644 --- a/info/control2011/src/lib/krobot_geom.ml +++ b/info/control2011/src/lib/krobot_geom.ml @@ -149,43 +149,43 @@ module Bezier = struct translate origin ((b.a *| t3) +| (b.b *| t2) +| (b.c *| t1) +| b.p) let fold_vertices f initial vertices acc = - let add_vertices q r v1 v2 acc = f q (translate q v1) (translate r v2) r acc in + let add_vertices sign q r v1 v2 acc = f sign q (translate q v1) (translate r v2) r acc in (* Compute cubic bezier curves. *) - let rec loop acc = function + let rec loop sign acc = function | p :: (q :: r :: s :: _ as rest) -> (* Computes tangents with a length that is half of the minimum length of the adjacent segments. *) let _, v1 = tangents p q r and v2, _ = tangents q r s in let v1 = v1 *| (min (distance p q) (distance q r) /. 2.) and v2 = v2 *| (min (distance q r) (distance r s) /. 2.) in - loop (add_vertices q r v1 v2 acc) rest + loop sign (add_vertices sign q r v1 v2 acc) rest | [p; q; r] -> let _, v1 = tangents p q r and v2 = vector r q /| distance q r in let v1 = v1 *| (min (distance p q) (distance q r) /. 2.) and v2 = v2 *| (distance q r /. 2.) in - add_vertices q r v1 v2 acc + add_vertices sign q r v1 v2 acc | _ -> acc in match vertices with | q :: r :: s :: _ -> - let initial = if prod initial (vector q r) < 0. then minus initial else initial in + let initial, sign = if prod initial (vector q r) < 0. then (minus initial, -1.) else (initial, 1.) in let v1 = initial and v2, _ = tangents q r s in let v1 = v1 *| (distance q r /. 2.) and v2 = v2 *| (distance q r /. 2.) in - loop (add_vertices q r v1 v2 acc) vertices + loop sign (add_vertices sign q r v1 v2 acc) vertices | [q; r] -> - let initial = if prod initial (vector q r) < 0. then minus initial else initial in + let initial, sign = if prod initial (vector q r) < 0. then (minus initial, -1.) else (initial, 1.) in let v1 = initial and v2 = vector r q /| distance q r in let v1 = v1 *| (distance q r /. 2.) and v2 = v2 *| (distance q r /. 2.) in - add_vertices q r v1 v2 acc + add_vertices sign q r v1 v2 acc | [_] | [] -> acc let fold_curves f initial vertices acc = - fold_vertices (fun p q r s acc -> f (of_vertices p q r s) acc) initial vertices acc + fold_vertices (fun sign p q r s acc -> f (of_vertices p q r s) acc) initial vertices acc end diff --git a/info/control2011/src/lib/krobot_geom.mli b/info/control2011/src/lib/krobot_geom.mli index abebd94..df40b0d 100644 --- a/info/control2011/src/lib/krobot_geom.mli +++ b/info/control2011/src/lib/krobot_geom.mli @@ -76,7 +76,8 @@ module Bezier : sig passing through the given list of vertices. [vector] is the initial direction vector. *) - val fold_vertices : (vertice -> vertice -> vertice -> vertice -> 'a -> 'a) -> vector -> vertice list -> 'a -> 'a + val fold_vertices : (float -> vertice -> vertice -> vertice -> vertice -> 'a -> 'a) -> vector -> vertice list -> 'a -> 'a (** [fold_vertices f vector vertices acc] same as {!fold_curves} - but pass parameters instead of curves to [f]. *) + but pass parameters instead of curves to [f]. The first + parameter passed to [f] is the sign of [d1]. *) end diff --git a/info/control2011/src/tools/krobot_planner.ml b/info/control2011/src/tools/krobot_planner.ml index 5f872e5..e1e3596 100644 --- a/info/control2011/src/tools/krobot_planner.ml +++ b/info/control2011/src/tools/krobot_planner.ml @@ -41,7 +41,7 @@ type planner = { mutable vertices : vertice list; (* The list of vertices for the trajectory. *) - mutable curves : (vertice * vertice * vertice * vertice) list; + mutable curves : (float * vertice * vertice * vertice * vertice) list; (* The parameters of bezier curves. *) mutable moving : bool; @@ -87,10 +87,11 @@ let set_vertices planner ?curves vertices = l | None -> let v = { vx = cos planner.orientation; vy = sin planner.orientation } in - List.rev (Bezier.fold_vertices (fun p q r s acc -> (p, q, r, s) :: acc) v vertices []) + List.rev (Bezier.fold_vertices (fun sign p q r s acc -> (sign, p, q, r, s) :: acc) v vertices []) in planner.curves <- curves; - ignore (Krobot_bus.send planner.bus (Unix.gettimeofday (), Trajectory_vertices(vertices, curves))) + ignore (Krobot_bus.send planner.bus (Unix.gettimeofday (), Trajectory_vertices(vertices, + List.map (fun (sign, p, q, r, s) -> (p, q, r, s)) curves))) let set_moving planner moving = planner.moving <- moving; @@ -210,9 +211,9 @@ let go planner rotation_speed rotation_acceleration moving_speed moving_accelera planner.mover <- ( try_lwt (* Send a bezier curve to the robot. *) - let send_curve (p, q, r, s) v_end = + let send_curve (sign, p, q, r, s) v_end = (* Compute parameters. *) - let d1 = distance p q and d2 = distance r s in + let d1 = sign *. distance p q and d2 = distance r s in let v = vector r s in let theta_end = atan2 v.vy v.vx in @@ -311,7 +312,7 @@ let handle_message planner (timestamp, message) = let ts = Unix.gettimeofday () in let vertices = if planner.moving then planner.vertices else planner.position :: planner.vertices in join [ - Krobot_bus.send planner.bus (ts, Trajectory_vertices(vertices, planner.curves)); + Krobot_bus.send planner.bus (ts, Trajectory_vertices(vertices, List.map (fun (sign, p, q, r, s) -> (p, q, r, s)) planner.curves)); Krobot_bus.send planner.bus (ts, Trajectory_moving planner.moving); ] ) hooks/post-receive -- krobot |