From: Jérémie D. <Ba...@us...> - 2011-04-05 15:34:45
|
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 773e02438462c3eb9d7b58086faac1e5e096d280 (commit) via 45a5cf2f19790d43b614389c01bd916972da6ce4 (commit) from e4efb4a37ad629588ff4f3a2f0308754b236bdc1 (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 773e02438462c3eb9d7b58086faac1e5e096d280 Author: Jérémie Dimino <je...@di...> Date: Tue Apr 5 17:33:48 2011 +0200 [krobot_viewer] compute simple bezier curves commit 45a5cf2f19790d43b614389c01bd916972da6ce4 Author: Jérémie Dimino <je...@di...> Date: Tue Apr 5 11:46:56 2011 +0200 [krobot_graph] use floats instead of ints ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index 8eb1060..a1e18d0 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -128,7 +128,7 @@ Executable "krobot-plot" Install$: flag(gtk) CompiledObject: best MainIs: krobot_plot.ml - BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib, threads + BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib Executable "krobot-plot-battery" Path: src/tools @@ -136,7 +136,7 @@ Executable "krobot-plot-battery" Install$: flag(gtk) CompiledObject: best MainIs: krobot_plot_battery.ml - BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib, threads + BuildDepends: krobot, lwt.syntax, cairo.lablgtk2, lwt.glib Executable "krobot-viewer" Path: src/tools diff --git a/info/control2011/_tags b/info/control2011/_tags index 7c5ae73..593a279 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 5cd0fff2e5e7303cfc985c8215a456e0) +# DO NOT EDIT (digest: c5fb31f60362628ba2becc8b6a98c80b) # Library krobot-interfaces "src/interfaces": include "src/interfaces/krobot-interfaces.cmxs": use_krobot-interfaces @@ -73,7 +73,6 @@ # Executable krobot-plot-battery <src/tools/krobot_plot_battery.{native,byte}>: use_krobot <src/tools/krobot_plot_battery.{native,byte}>: use_krobot-interfaces -<src/tools/krobot_plot_battery.{native,byte}>: pkg_threads <src/tools/krobot_plot_battery.{native,byte}>: pkg_obus <src/tools/krobot_plot_battery.{native,byte}>: pkg_lwt.unix <src/tools/krobot_plot_battery.{native,byte}>: pkg_lwt.syntax @@ -119,13 +118,11 @@ # Executable krobot-plot <src/tools/krobot_plot.{native,byte}>: use_krobot <src/tools/krobot_plot.{native,byte}>: use_krobot-interfaces -<src/tools/krobot_plot.{native,byte}>: pkg_threads <src/tools/krobot_plot.{native,byte}>: pkg_obus <src/tools/krobot_plot.{native,byte}>: pkg_lwt.unix <src/tools/krobot_plot.{native,byte}>: pkg_lwt.syntax <src/tools/krobot_plot.{native,byte}>: pkg_lwt.glib <src/tools/krobot_plot.{native,byte}>: pkg_cairo.lablgtk2 -<src/tools/*.ml{,i}>: pkg_threads <src/tools/*.ml{,i}>: pkg_lwt.glib <src/tools/*.ml{,i}>: pkg_cairo.lablgtk2 # Executable krobot-simulator diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index 05b8ab2..2ba8666 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: ab615aa1d52e40116d1afa35b031733b) *) +(* DO NOT EDIT (digest: 4dcf80b777e23d14096fb05b034e73dc) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5382,8 +5382,7 @@ let setup_t = InternalLibrary "krobot"; FindlibPackage ("lwt.syntax", None); FindlibPackage ("cairo.lablgtk2", None); - FindlibPackage ("lwt.glib", None); - FindlibPackage ("threads", None) + FindlibPackage ("lwt.glib", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; @@ -5558,8 +5557,7 @@ let setup_t = InternalLibrary "krobot"; FindlibPackage ("lwt.syntax", None); FindlibPackage ("cairo.lablgtk2", None); - FindlibPackage ("lwt.glib", None); - FindlibPackage ("threads", None) + FindlibPackage ("lwt.glib", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; diff --git a/info/control2011/src/lib/krobot_geom.ml b/info/control2011/src/lib/krobot_geom.ml index 7f04395..28178d6 100644 --- a/info/control2011/src/lib/krobot_geom.ml +++ b/info/control2011/src/lib/krobot_geom.ml @@ -71,12 +71,10 @@ let vector a b = { let distance a b = sqrt (sqr (a.x -. b.x) +. sqr (a.y -. b.y)) -let tangent a b c = - let a = vector origin a - and b = vector origin b - and c = vector origin c in - let v = (b -| a) +| (b -| c) in - v /| norm v +let tangents a b c = + let ba = vector b a /| distance b a and bc = vector b c /| distance b c in + let v1 = ba -| bc and v2 = bc -| ba in + (v1 /| norm v1, v2 /| norm v2) (* +-----------------------------------------------------------------+ | Cubic bezier curves | @@ -97,7 +95,7 @@ module Bezier = struct and r = vector origin r and s = vector origin s in let c = (q -| p) *| 3. in - let b = (r -| q) -| c in + let b = (r -| q) *| 3. -| c in let a = s -| p -| c -| b in { p; a; b; c } diff --git a/info/control2011/src/lib/krobot_geom.mli b/info/control2011/src/lib/krobot_geom.mli index b1a9936..ddeabbf 100644 --- a/info/control2011/src/lib/krobot_geom.mli +++ b/info/control2011/src/lib/krobot_geom.mli @@ -35,8 +35,9 @@ val vector : vertice -> vertice -> vector val norm : vector -> float val distance : vertice -> vertice -> float -val tangent : vertice -> vertice -> vertice -> vector - (** [tangent a b c] returns the tangent to the triangle abc in b. *) +val tangents : vertice -> vertice -> vertice -> vector * vector + (** [tangents a b c] returns the two unitary vectors tangent to the + triangle abc in b. *) (** {6 Cubic Bezier curves} *) diff --git a/info/control2011/src/tools/krobot_graph.ml b/info/control2011/src/tools/krobot_graph.ml index 327ae72..4a9bdde 100644 --- a/info/control2011/src/tools/krobot_graph.ml +++ b/info/control2011/src/tools/krobot_graph.ml @@ -16,10 +16,10 @@ let graph_duration = 10.0 (* Type of graphs. *) type graph = { - points : (float * int) Queue.t array; + points : (float * float) Queue.t array; (* Queue of points with their time. They are ordered by increasing date. *) - mutable max : int; + mutable max : float; (* The maximum reached. *) } @@ -27,7 +27,7 @@ type graph = { let update_graph graph time = Array.iter (fun q -> - while not (Queue.is_empty q) && fst (Queue.top q) +. graph_duration < time do + while not (Queue.is_empty q) && fst (Queue.top q) +. graph_duration *. 1.5 < time do ignore (Queue.take q) done) graph.points @@ -52,7 +52,7 @@ let plot ctx width height graph time = Queue.iter (fun (date, position) -> let x = (date -. (time -. graph_duration)) /. graph_duration *. width - and y = height -. height *. (float position /. float graph.max) in + and y = height -. height *. (position /. graph.max) in match !prev with | None -> prev := Some(x, y) diff --git a/info/control2011/src/tools/krobot_plot.ml b/info/control2011/src/tools/krobot_plot.ml index cef19f2..e5e4cab 100644 --- a/info/control2011/src/tools/krobot_plot.ml +++ b/info/control2011/src/tools/krobot_plot.ml @@ -10,81 +10,7 @@ open Lwt open Lwt_react open Krobot_message - -(* +-----------------------------------------------------------------+ - | Graphs | - +-----------------------------------------------------------------+ *) - -let graph_duration = 10.0 - (* Which amount of data to keep in graphs. *) - -(* Type of graphs. *) -type graph = { - points : (float * int) Queue.t array; - (* Queue of points with their time. They are ordered by increasing - date. *) - mutable max : int; - (* The maximum reached. *) -} - -(* Remove old points. *) -let update_graph graph time = - Array.iter - (fun q -> - while not (Queue.is_empty q) && fst (Queue.top q) +. graph_duration < time do - ignore (Queue.take q) - done) - graph.points - -(* +-----------------------------------------------------------------+ - | Plotting | - +-----------------------------------------------------------------+ *) - -let rec colors = (1., 0., 0.) :: (0., 1., 0.) :: (0., 0., 1.) :: (1., 1., 0.) :: colors - -let plot ctx width height graph time = - Cairo.set_source_rgb ctx 1. 1. 1.; - Cairo.rectangle ctx 0. 0. width height; - Cairo.fill ctx; - let colors = ref colors in - Array.iter - (fun q -> - let r, g, b = List.hd !colors in - colors := List.tl !colors; - Cairo.set_source_rgb ctx r g b; - let prev = ref None in - Queue.iter - (fun (date, position) -> - let x = (date -. (time -. graph_duration)) /. graph_duration *. width - and y = height -. height *. (float position /. float graph.max) in - match !prev with - | None -> - prev := Some(x, y) - | Some(x', y') -> - prev := Some(x, y); - Cairo.move_to ctx x' y'; - Cairo.line_to ctx x y; - Cairo.stroke ctx) - q) - graph.points - -(* +-----------------------------------------------------------------+ - | Drawing | - +-----------------------------------------------------------------+ *) - -let draw window graph = - while true do - let { Gtk.width; Gtk.height } = window#misc#allocation in - let surface = Cairo.image_surface_create Cairo.FORMAT_ARGB32 width height in - let ctx = Cairo.create surface in - plot ctx (float width) (float height) graph (Unix.gettimeofday ()); - let ctx = Cairo_lablgtk.create window#misc#window in - Cairo.set_source_surface ctx surface 0. 0.; - Cairo.rectangle ctx 0. 0. (float width) (float height); - Cairo.fill ctx; - Cairo.surface_finish surface; - ignore (Unix.select [] [] [] (1. /. 25.)) - done +open Krobot_graph (* +-----------------------------------------------------------------+ | Main-loop | @@ -103,16 +29,13 @@ lwt () = window#show (); (* Create the graph. *) - let graph = { points = Array.init 2 (fun _ -> Queue.create ()); max = 1 } in - - (* Draw in a separate thread. *) - ignore (Thread.create (fun () -> draw window graph) ()); - + let graph = { points = Array.init 2 (fun _ -> Queue.create ()); max = 1. } in E.keep (E.map (fun (timestamp, msg) -> match msg with | Encoder_position_direction_3_4(pos3, dir3, pos4, dir4) -> + let pos3 = float pos3 and pos4 = float pos4 in graph.max <- max graph.max (max pos3 pos4); Queue.push (timestamp, pos3) graph.points.(0); Queue.push (timestamp, pos4) graph.points.(1); @@ -121,4 +44,10 @@ lwt () = ()) (Krobot_message.recv bus)); - waiter + pick [ + waiter; + while_lwt true do + Krobot_graph.draw window graph; + Lwt_unix.sleep (1. /. 25.) + done; + ] diff --git a/info/control2011/src/tools/krobot_plot_battery.ml b/info/control2011/src/tools/krobot_plot_battery.ml index fa79f9b..3bbcad9 100644 --- a/info/control2011/src/tools/krobot_plot_battery.ml +++ b/info/control2011/src/tools/krobot_plot_battery.ml @@ -25,19 +25,19 @@ lwt () = (* Create the graph. *) let graph = { Krobot_graph.points = Array.init 2 (fun _ -> Queue.create ()); - Krobot_graph.max = 1 } in + Krobot_graph.max = 14. } in E.keep (E.map (fun (timestamp, msg) -> match msg with | Battery1_voltages(x1, x2, x3, x4) -> - let s = int_of_float ((x1 +. x2 +. x3 +. x4) *. 1000.) in + let s = x1 +. x2 +. x3 +. x4 in graph.Krobot_graph.max <- max graph.Krobot_graph.max s; Queue.push (timestamp, s) graph.Krobot_graph.points.(0); Krobot_graph.update_graph graph timestamp | Battery2_voltages(x1, x2, x3, x4) -> - let s = int_of_float ((x1 +. x2 +. x3 +. x4) *. 1000.) in + let s = x1 +. x2 +. x3 +. x4 in graph.Krobot_graph.max <- max graph.Krobot_graph.max s; Queue.push (timestamp, s) graph.Krobot_graph.points.(1); Krobot_graph.update_graph graph timestamp diff --git a/info/control2011/src/tools/krobot_viewer.ml b/info/control2011/src/tools/krobot_viewer.ml index 00bb54c..22a5c20 100644 --- a/info/control2011/src/tools/krobot_viewer.ml +++ b/info/control2011/src/tools/krobot_viewer.ml @@ -435,6 +435,7 @@ module Board = struct let clear board = board.points <- []; + board.bezier <- []; queue_draw board let rec last = function @@ -477,20 +478,18 @@ module Board = struct in let result = List.tl (loop [0; Array.length points - 1]); in board.points <- List.map (fun i -> points.(i)) result; -(* - let speed = board.ui#moving_speed#adjustment#value - and acceleration = board.ui#moving_acceleration#adjustment#value in (* Compute cubic bezier curves. *) let rec loop = function | p :: (q :: r :: s :: _ as rest) -> - (* Compute the speed vectors. *) - let v1 = tangent p q r and v2 = tangent q r s in - let v1 = { vx = -. v1.vy; vy = v1.vx } *| speed - and v2 = { vx = v2.vy; vy = -. v2.vx } *| speed in + (* 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 (* Create the bezier curve. *) - let curve = Bezier.make ~p:q ~s:r ~vp:v1 ~vs:v2 ~a:acceleration ~error_max:0.1 in + let curve = Bezier.of_vertices q (translate q v1) (translate r v2) r in (* Create vertices. *) let vertices = Array.create 101 origin in @@ -502,8 +501,8 @@ module Board = struct | _ -> [] in - board.bezier <- [||] :: loop board.points; -*) + board.bezier <- [||] :: loop ({ x = board.state.pos.x; y = board.state.pos.y } :: board.points); + queue_draw board let wait_done board = hooks/post-receive -- krobot |