paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [6166] when using unit and alt_unit, alt_unit_coef i


From: Gautier Hattenberger
Subject: [paparazzi-commits] [6166] when using unit and alt_unit, alt_unit_coef is not required for some basic conversions like rad<->deg
Date: Mon, 18 Oct 2010 15:46:25 +0000

Revision: 6166
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=6166
Author:   gautier
Date:     2010-10-18 15:46:25 +0000 (Mon, 18 Oct 2010)
Log Message:
-----------
when using unit and alt_unit, alt_unit_coef is not required for some basic 
conversions like rad<->deg

Modified Paths:
--------------
    paparazzi3/trunk/sw/ground_segment/cockpit/page_settings.ml
    paparazzi3/trunk/sw/ground_segment/tmtc/messages.ml
    paparazzi3/trunk/sw/lib/ocaml/ocaml_tools.ml
    paparazzi3/trunk/sw/lib/ocaml/pprz.ml

Modified: paparazzi3/trunk/sw/ground_segment/cockpit/page_settings.ml
===================================================================
--- paparazzi3/trunk/sw/ground_segment/cockpit/page_settings.ml 2010-10-18 
15:34:40 UTC (rev 6165)
+++ paparazzi3/trunk/sw/ground_segment/cockpit/page_settings.ml 2010-10-18 
15:46:25 UTC (rev 6166)
@@ -34,7 +34,7 @@
     method index = i
     method xml = xml
     method current_value =
-      let auc = try Xml.attrib xml "alt_unit_coef" with _ -> "" in
+      let auc = Pprz.alt_unit_coef_of_xml xml in 
       let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
       (float_of_string current_value#text -. alt_b) /. alt_a
     method update = fun s ->
@@ -78,7 +78,7 @@
   let page_incr = step_incr
   and page_size = step_incr
   and show_auto = try ExtXml.attrib dl_setting "auto" = "true" with _ -> false 
in
-  let auc = try Xml.attrib dl_setting "alt_unit_coef" with _ -> "" in
+  let auc = Pprz.alt_unit_coef_of_xml dl_setting in
   let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
   
   let hbox = GPack.hbox ~packing () in
@@ -275,7 +275,7 @@
     method set = fun i v ->
       if visible self#widget then
        let setting = variables.(i) in
-       let auc = ExtXml.attrib_or_default setting#xml "alt_unit_coef" "" in
+       let auc = Pprz.alt_unit_coef_of_xml setting#xml in
        let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
        let v = alt_a *. v +. alt_b in
        let s = string_of_float v in

Modified: paparazzi3/trunk/sw/ground_segment/tmtc/messages.ml
===================================================================
--- paparazzi3/trunk/sw/ground_segment/tmtc/messages.ml 2010-10-18 15:34:40 UTC 
(rev 6165)
+++ paparazzi3/trunk/sw/ground_segment/tmtc/messages.ml 2010-10-18 15:46:25 UTC 
(rev 6166)
@@ -86,7 +86,7 @@
          (* box dragger *)
          field_label#drag#source_set dnd_targets ~modi:[`BUTTON1] 
~actions:[`COPY];
          let data_get = fun _ (sel:GObj.selection_context) ~info ~time ->
-           let scale =  ExtXml.attrib_or_default f "alt_unit_coef" "1" in
+      let scale = Pprz.alt_unit_coef_of_xml f in
            let field_descr =
              if Pprz.is_array_type type_ then
                match GToolbox.input_string ~title:"Index of value to drag" 
~text:"0" "Index in the array ?" with

Modified: paparazzi3/trunk/sw/lib/ocaml/ocaml_tools.ml
===================================================================
--- paparazzi3/trunk/sw/lib/ocaml/ocaml_tools.ml        2010-10-18 15:34:40 UTC 
(rev 6165)
+++ paparazzi3/trunk/sw/lib/ocaml/ocaml_tools.ml        2010-10-18 15:46:25 UTC 
(rev 6166)
@@ -48,11 +48,14 @@
        loop_ext extensions in
   loop_path path
 
-let regexp_plus = Str.regexp "\\+" 
+let regexp_plus_less = Str.regexp "[+-]" 
 let affine_transform = fun format ->
-  match Str.split regexp_plus format with
-    [a;b] -> float_of_string a, float_of_string b
-  | [a] -> float_of_string a, 0.
+  (* Split after removing blank spaces *)
+  match Str.full_split regexp_plus_less (Str.global_replace (Str.regexp "[ 
\t]+") "" format) with
+    [Str.Text a; Str.Delim "+" ; Str.Text b] -> float_of_string a, 
float_of_string b
+  | [Str.Text a; Str.Delim "-" ; Str.Text b] -> float_of_string a, -. 
float_of_string b
+  | [Str.Text a; Str.Delim "+"; Str.Delim "-" ; Str.Text b] -> float_of_string 
a, -. float_of_string b
+  | [Str.Text a] -> float_of_string a, 0.
   | _ -> 1., 0.
 
 (* Box-Muller transform to generate a normal distribution from a uniform one

Modified: paparazzi3/trunk/sw/lib/ocaml/pprz.ml
===================================================================
--- paparazzi3/trunk/sw/lib/ocaml/pprz.ml       2010-10-18 15:34:40 UTC (rev 
6165)
+++ paparazzi3/trunk/sw/lib/ocaml/pprz.ml       2010-10-18 15:46:25 UTC (rev 
6166)
@@ -157,12 +157,26 @@
     message.fields
     2 (** + message id + aircraft id *)
 
+  
+let alt_unit_coef_of_xml = function xml ->
+  try Xml.attrib xml "alt_unit_coef"
+  with _ ->
+    let u = try Xml.attrib xml "unit" with _ -> "" in
+    let au = try Xml.attrib xml "alt_unit" with _ -> "" in
+    match (u, au) with
+      ("deg", "rad") | ("deg/s", "rad/s") -> string_of_float (pi /. 180.)
+    | ("rad", "deg") | ("rad/s", "deg/s") -> string_of_float (180. /. pi)
+    | ("m", "cm") | ("m/s", "cm/s") -> "100."
+    | ("cm", "m") | ("cm/s", "m/s") -> "0.01"
+    | ("decideg", "deg") -> "0.1"
+    | (_, _) -> "1."
+
 let pipe_regexp = Str.regexp "|"
 let field_of_xml = fun xml ->
   let t = ExtXml.attrib xml "type" in
   let t = if is_array_type t then ArrayType (type_of_array_type t) else Scalar 
t in
   let f = try Xml.attrib xml "format" with _ -> default_format t in
-  let auc = try Xml.attrib xml "alt_unit_coef" with _ -> "" in
+  let auc = alt_unit_coef_of_xml xml in
   let values = try Str.split pipe_regexp (Xml.attrib xml "values") with _ -> 
[] in
 
   ( String.lowercase (ExtXml.attrib xml "name"), 
@@ -325,22 +339,8 @@
   | value ->
       failwith (sprintf "Error: expecting array in Pprz.hex_of_int_array, 
found %s" (string_of_value value))
 
-  
-let alt_unit_coef_of_xml = function xml ->
-  try Xml.attrib xml "alt_unit_coef"
-  with _ ->
-    let u = try Xml.attrib xml "unit" with _ -> "" in
-    let au = try Xml.attrib xml "alt_unit" with _ -> "" in
-    match (u, au) with
-      ("deg", "rad") | ("deg/s", "rad/s") -> string_of_float (pi /. 180.)
-    | ("rad", "deg") | ("rad/s", "deg/s") -> string_of_float (180. /. pi)
-    | ("m", "cm") | ("m/s", "cm/s") -> "100."
-    | ("cm", "m") | ("cm/s", "m/s") -> "0.01"
-    | ("decideg", "deg") -> "0.1"
-    | (_, _) -> "1."
 
 
-
 exception Unknown_msg_name of string * string
 
 module type TRANSPORT_TYPE = sig




reply via email to

[Prev in Thread] Current Thread [Next in Thread]