[units] automatic conversion handles code and display

This commit is contained in:
Gautier Hattenberger
2012-07-18 19:28:54 +02:00
parent c028e7a296
commit 44801a2de6
5 changed files with 15 additions and 15 deletions
+2 -2
View File
@@ -3,8 +3,8 @@
<settings>
<dl_settings>
<dl_settings NAME="ir">
<dl_setting MAX="15" MIN="-15" STEP="0.5" VAR="infrared.roll_neutral" shortname="roll_neutral" param="IR_ROLL_NEUTRAL_DEFAULT" unit="rad" alt_unit="deg"/>
<dl_setting MAX="15" MIN="-15" STEP="0.5" VAR="infrared.pitch_neutral" shortname="pitch_neutral" param="IR_PITCH_NEUTRAL_DEFAULT" unit="rad" alt_unit="deg"/>
<dl_setting MAX="15" MIN="-15" STEP="0.5" VAR="infrared.roll_neutral" shortname="roll_neutral" param="IR_ROLL_NEUTRAL_DEFAULT" alt_unit="deg"/>
<dl_setting MAX="15" MIN="-15" STEP="0.5" VAR="infrared.pitch_neutral" shortname="pitch_neutral" param="IR_PITCH_NEUTRAL_DEFAULT" alt_unit="deg"/>
<dl_setting MAX="1.5" MIN="0." STEP="0.1" VAR="infrared.lateral_correction" shortname="360_lat_corr" module="subsystems/sensors/infrared" param="IR_LATERAL_CORRECTION"/>
<dl_setting MAX="1.5" MIN="0." STEP="0.1" VAR="infrared.longitudinal_correction" shortname="360_log_corr" param="IR_LONGITUDINAL_CORRECTION"/>
+4 -4
View File
@@ -1,10 +1,10 @@
<!-- Table of default units convertion -->
<!-- used to convert from unit to alt_unit (messages) or code_unit (airframe) -->
<units>
<unit from="deg" to="rad" coef="0.0174532925" auto="true"/>
<unit from="rad" to="deg" coef="57.2957795131"/>
<unit from="deg/s" to="rad/s" coef="0.0174532925" auto="true"/>
<unit from="rad/s" to="deg/s" coef="57.2957795131"/>
<unit from="deg" to="rad" coef="0.0174532925" auto="code"/>
<unit from="rad" to="deg" coef="57.2957795131" auto="display"/>
<unit from="deg/s" to="rad/s" coef="0.0174532925" auto="code"/>
<unit from="rad/s" to="deg/s" coef="57.2957795131" auto="display"/>
<unit from="m" to="cm" coef="100."/>
<unit from="cm" to="m" coef="0.01"/>
<unit from="m/s" to="cm/s" coef="100."/>
+2 -2
View File
@@ -137,11 +137,11 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml ->
if uc = us then uc
else invalid_arg (Printf.sprintf "Warning: code unit in airframe (%s) and setting file (%s) are not matching for param %s\n" uc us param) (* raise Invalid_argument *)
| Some u, None | None, Some u -> u
| None, None -> raise Exit
| None, None -> ""
and unit_airframe =
match airframe_unit with
| Some u -> u
| None -> raise Exit
| None -> ""
in
(* Printf.fprintf stderr "param %s: unit_code=%s unit_airframe=%s\n" param unit_code unit_airframe; flush stderr; *)
Pprz.scale_of_units unit_airframe unit_code
+5 -5
View File
@@ -160,7 +160,7 @@ let payload_size_of_message = fun message ->
exception Unit_conversion_error of string
exception Unknown_conversion of string * string
exception No_automatic_conversion of string
exception No_automatic_conversion of string * string
let scale_of_units = fun from_unit to_unit ->
if (from_unit = to_unit) then
@@ -173,8 +173,8 @@ let scale_of_units = fun from_unit to_unit ->
(* will raise Xml.No_attribute if not a valid attribute *)
let f = Xml.attrib u "from"
and t = Xml.attrib u "to"
and a = String.lowercase (ExtXml.attrib_or_default u "auto" "false") in
if f = from_unit && (t = to_unit || a = "true") then true else false
and a = String.lowercase (ExtXml.attrib_or_default u "auto" "") in
if (f = from_unit || a = "display") && (t = to_unit || a = "code") then true else false
) (Xml.children units_xml) in
(* return coef, raise Failure if coef is not a numerical value *)
float_of_string (Xml.attrib _unit "coef")
@@ -182,7 +182,7 @@ let scale_of_units = fun from_unit to_unit ->
| Xml.No_attribute _ | Xml.Not_element _ -> raise (Unit_conversion_error ("File conf/units.xml has errors"))
| Failure "float_of_string" -> raise (Unit_conversion_error ("Unit coef is not numerical value"))
| Not_found ->
if to_unit = "" then raise (No_automatic_conversion from_unit)
if from_unit = "" || to_unit = "" then raise (No_automatic_conversion (from_unit, to_unit))
else raise (Unknown_conversion (from_unit, to_unit))
| _ -> raise (Unknown_conversion (from_unit, to_unit))
@@ -193,7 +193,7 @@ let alt_unit_coef_of_xml = function xml ->
let u = try Xml.attrib xml "unit" with _ -> "" in
let au = try Xml.attrib xml "alt_unit" with _ -> "" in
let coef = try string_of_float (scale_of_units u au) with
Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; exit 1
Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; "1." (* Use coef 1. *)
| Unknown_conversion _ -> "1." (* Use coef 1. *)
| _ -> "1."
in
+2 -2
View File
@@ -90,9 +90,9 @@ exception Unit_conversion_error of string
(** Unit_conversion_error raised when parsing error occurs *)
exception Unknown_conversion of string * string
(** Unknown_conversion raised when conversion fails *)
exception No_automatic_conversion of string
exception No_automatic_conversion of string * string
(** No_automatic_conversion raised when no conversion found
* and to_unit is an empty string
* and from_unit or to_unit are empty string
*)
val scale_of_units : string -> string -> float