From: Jérémie D. <Ba...@us...> - 2011-04-04 08:37:39
|
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 92ce3ad8d7d5a762d198226d65c5e3d721f7ecea (commit) from fed2ad770503e3c2c71f46c3fc1b29989cf4773e (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 92ce3ad8d7d5a762d198226d65c5e3d721f7ecea Author: Jérémie Dimino <je...@di...> Date: Mon Apr 4 10:36:57 2011 +0200 [info] add optimal cubic bezier curve computation ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 1292204..e74d55b 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -38,7 +38,8 @@ Library krobot Krobot_can, Krobot_bus, Krobot_message, - Krobot_service + Krobot_service, + Krobot_geom Library "krobot-can" FindlibName: can diff --git a/info/control2011/krobot-api.odocl b/info/control2011/krobot-api.odocl index f4916e1..a6dd103 100644 --- a/info/control2011/krobot-api.odocl +++ b/info/control2011/krobot-api.odocl @@ -1,8 +1,9 @@ # OASIS_START -# DO NOT EDIT (digest: 0d5bc1930a2026d83d7053264b79ba8f) +# DO NOT EDIT (digest: e58fdc99e81067f38e47e3f89ed4db14) src/lib/Krobot_can src/lib/Krobot_bus src/lib/Krobot_message src/lib/Krobot_service +src/lib/Krobot_geom src/can/Krobot_can_bus # OASIS_STOP diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index 48d05a0..d3ed546 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 60affd9777295d3612011711e6241ee4) *) +(* DO NOT EDIT (digest: 698f29e4a2f614788e3b1ec0344c74ff) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5116,7 +5116,8 @@ let setup_t = "Krobot_can"; "Krobot_bus"; "Krobot_message"; - "Krobot_service" + "Krobot_service"; + "Krobot_geom" ]; lib_internal_modules = []; lib_findlib_parent = None; diff --git a/info/control2011/src/lib/krobot.mllib b/info/control2011/src/lib/krobot.mllib index 46a8f9d..b2daa79 100644 --- a/info/control2011/src/lib/krobot.mllib +++ b/info/control2011/src/lib/krobot.mllib @@ -1,7 +1,8 @@ # OASIS_START -# DO NOT EDIT (digest: c29896a0604d0996c07a96abc42f0884) +# DO NOT EDIT (digest: d28f502a765cf0ae56f93e800363c356) Krobot_can Krobot_bus Krobot_message Krobot_service +Krobot_geom # OASIS_STOP diff --git a/info/control2011/src/lib/krobot_geom.ml b/info/control2011/src/lib/krobot_geom.ml new file mode 100644 index 0000000..c5a6941 --- /dev/null +++ b/info/control2011/src/lib/krobot_geom.ml @@ -0,0 +1,130 @@ +(* + * krobot_geom.ml + * -------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +let sqr x = x *. x + +(* +-----------------------------------------------------------------+ + | Vectors | + +-----------------------------------------------------------------+ *) + +type vector = { vx : float; vy : float } + +let null = { vx = 0.; vy = 0. } + +let add a b = { + vx = a.vx +. b.vx; + vy = a.vy +. b.vy; +} + +let sub a b = { + vx = a.vx -. b.vx; + vy = a.vy -. b.vy; +} + +let minus v = { + vx = -. v.vx; + vy = -. v.vy; +} + +let mul v s = { + vx = v.vx *. s; + vy = v.vy *. s; +} + +let div v s = { + vx = v.vx /. s; + vy = v.vy /. s; +} + +let ( +| ) = add +let ( -| ) = sub +let ( ~| ) = minus +let ( *| ) = mul +let ( /| ) = div + +let norm v = sqrt (sqr v.vx +. sqr v.vy) + +(* +-----------------------------------------------------------------+ + | Vertices | + +-----------------------------------------------------------------+ *) + +type vertice = { x : float; y : float } + +let origin = { x = 0.; y = 0. } + +let translate a v = { + x = a.x +. v.vx; + y = a.y +. v.vy; +} + +let vector a b = { + vx = b.x -. a.x; + vy = b.y -. a.y; +} + +let distance a b = + sqrt (sqr (a.x -. b.x) +. sqr (a.y -. b.y)) + +(* +-----------------------------------------------------------------+ + | Cubic bezier curves | + +-----------------------------------------------------------------+ *) + +module Bezier = struct + + type curve = { + p : vector; + a : vector; + b : vector; + c : vector; + } + + let of_vertices p q r s = + let p = vector origin p + and q = vector origin q + and r = vector origin r + and s = vector origin s in + let c = (q -| p) *| 3. in + let b = (r -| q) -| c in + let a = s -| p -| c -| b in + { p; a; b; c } + + let make ~p ~s ~vp ~vs ~a ~error_max = + let sp = norm vp and ss = norm vs in + (* Compute Rp and Rs. *) + let r_p = sqr sp /. a and r_s = sqr ss /. a in + (* Normalize speed vectors. *) + let vp = vp /| sp and vs = vs /| ss in + (* Compute g0, g1, g2, h0, h1 and h2. *) + let g0 = s.x -. p.x and h0 = s.y -. p.y in + let g1 = 2. *. (vs.vy *. vp.vx -. vs.vx *. vp.vy) in + let g2 = g1 in + let h1 = 2. *. (h0 *. vp.vx -. g0 *. vp.vy) in + let h2 = 2. *. (h0 *. vs.vx -. g0 *. vs.vy) in + (* The loop for finding d1 and d2. *) + let rec loop d1 d2 = + let rho_p = 3. *. d1 *. d1 /. (h1 +. d2 *. g1) + and rho_s = 3. *. d2 *. d2 /. (h2 +. d1 *. g2) in + let err_1 = r_p -. rho_p and err_2 = r_s -. rho_s in + let error = max (abs_float err_1) (abs_float err_2) in + if error < error_max then + let q = translate p (vp *| d1) + and r = translate s (vs *| d2) in + of_vertices p q r s + else + loop (d1 +. err_1 /. r_p) (d2 +. err_2 +. r_s) + in + loop 1. 1. + + let vertice b t = + if t < 0. || t > 1. then invalid_arg "Krobot_geom.Bezier.vertice"; + let t1 = t in + let t2 = t1 *. t in + let t3 = t2 *. t in + translate origin ((b.a *| t3) +| (b.b *| t2) +| (b.c *| t1) +| b.p) +end diff --git a/info/control2011/src/lib/krobot_geom.mli b/info/control2011/src/lib/krobot_geom.mli new file mode 100644 index 0000000..748b85e --- /dev/null +++ b/info/control2011/src/lib/krobot_geom.mli @@ -0,0 +1,62 @@ +(* + * krobot_geom.mli + * --------------- + * Copyright : (c) 2011, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(** Geometry *) + +(** {6 Basic geometry} *) + +type vector = { vx : float; vy : float } +type vertice = { x : float; y : float } + +val null : vector +val origin : vertice + +val add : vector -> vector -> vector +val sub : vector -> vector -> vector +val minus : vector -> vector +val mul : vector -> float -> vector +val div : vector -> float -> vector + +val ( +| ) : vector -> vector -> vector +val ( -| ) : vector -> vector -> vector +val ( ~| ) : vector -> vector +val ( *| ) : vector -> float -> vector +val ( /| ) : vector -> float -> vector + +val translate : vertice -> vector -> vertice +val vector : vertice -> vertice -> vector + +val norm : vector -> float +val distance : vertice -> vertice -> float + +(** {6 Cubic Bezier curves} *) + +module Bezier : sig + type curve + (** Type of cubic Bezier curves. *) + + val of_vertices : vertice -> vertice -> vertice -> vertice -> curve + (** [of_vertices p q r s] creates a bezier curve from the given + four control points. [p] and [s] are the first and end point + of the curve. *) + + val make : p : vertice -> s : vertice -> vp : vector -> vs : vector -> a : float -> error_max : float -> curve + (** [make p s vp vs sp ss a] creates a bezier curve. + @param p is the first control point + @param s is the last control point + @param vp is the speed vector in [p] + @param vs is the speed vector in [s] + @param a is the radial acceleration of the robot + @param error_max is the maximum allowed error or the + computation of intermediate control points *) + + val vertice : curve -> float -> vertice + (** [vertice curve u] returns the vertice on the given curve for + the given paramter [u] which must be in the range [0..1]. *) +end hooks/post-receive -- krobot |