diff --git a/sw/lib/ocaml/Makefile b/sw/lib/ocaml/Makefile index 507a27e377..87a8077532 100644 --- a/sw/lib/ocaml/Makefile +++ b/sw/lib/ocaml/Makefile @@ -29,7 +29,7 @@ OCAMLOPT=ocamlopt OCAMLLIBDIR=$(shell ocamlc -where) -SRC = debug.ml base64.ml serial.ml ocaml_tools.ml extXml.ml env.ml xml2h.ml latlong.ml srtm.ml http.ml gm.ml iGN.ml geometry_2d.ml cserial.o convert.o ubx.ml pprz.ml xbee.ml logpprz.ml xmlCom.ml editAirframe.ml +SRC = debug.ml base64.ml serial.ml ocaml_tools.ml extXml.ml env.ml xml2h.ml latlong.ml egm96.ml srtm.ml http.ml gm.ml iGN.ml geometry_2d.ml cserial.o convert.o ubx.ml pprz.ml xbee.ml logpprz.ml xmlCom.ml editAirframe.ml CMO = $(SRC:.ml=.cmo) CMX = $(SRC:.ml=.cmx) diff --git a/sw/lib/ocaml/egm96.ml b/sw/lib/ocaml/egm96.ml new file mode 100644 index 0000000000..91aec35049 --- /dev/null +++ b/sw/lib/ocaml/egm96.ml @@ -0,0 +1,56 @@ +(* + * $Id$ + * + * EGM96 geoid model + * + * Copyright (C) 2009 ENAC, Pascal Brisset + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +open Latlong + +let (//) = Filename.concat + +let ncols = 1440 +let nrows = 721 +let data = + lazy ( + let path = [Env.paparazzi_home // "data" // "srtm"] in + let f = Ocaml_tools.open_compress (Ocaml_tools.find_file path "WW15MGH.DAC") in + let n = ncols * nrows * 2 in + let buf = String.create n in + really_input f buf 0 n; + buf) + + +(* http://earth-info.nima.mil/GandG/wgs84/gravitymod/egm96/binary/binarygeoid.html *) +let of_wgs84 = fun geo -> + let egm96_data = Lazy.force data in + + let lat = truncate ((Rad>>Deg) (norm_angle geo.posn_lat)) + and lon = truncate ((Rad>>Deg) (norm_angle geo.posn_long)) in + let ilat = (90-lat)*4 (* 15' == 4 entries per degree *) + and ilon = (lon+if lon < 0 then 360 else 0)*4 in + + let i = (2*(ilat*ncols+ilon)) in + + let x = Char.code egm96_data.[i] lsl 8 + Char.code egm96_data.[i+1] in + + float ((x lsl 16) asr 16) /. 100. diff --git a/sw/lib/ocaml/egm96.mli b/sw/lib/ocaml/egm96.mli new file mode 100644 index 0000000000..37daa1520f --- /dev/null +++ b/sw/lib/ocaml/egm96.mli @@ -0,0 +1,28 @@ +(* + * $Id$ + * + * EGM96 geoid model + * + * Copyright (C) 2009 ENAC, Pascal Brisset + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +val of_wgs84 : Latlong.geographic -> Latlong.fmeter +(** Return geoid height from 15' precomputed file *) diff --git a/sw/lib/ocaml/latlong.ml b/sw/lib/ocaml/latlong.ml index 59d11542e6..fde345cb11 100644 --- a/sw/lib/ocaml/latlong.ml +++ b/sw/lib/ocaml/latlong.ml @@ -714,32 +714,3 @@ let wgs84_hmsl = fun geo -> (float geoid_data.(ilat1).(ilon2)) (float geoid_data.(ilat2).(ilon1)) (float geoid_data.(ilat2).(ilon2)) - - - -let egm96_ncols = 1440 -let egm96_nrows = 721 -let egm96_data = - lazy ( - let path = [Env.paparazzi_home // "data" // "srtm"] in - let f = Ocaml_tools.open_compress (Ocaml_tools.find_file path "WW15MGH.DAC") in - let n = egm96_ncols * egm96_nrows * 2 in - let buf = String.create n in - really_input f buf 0 n; - buf) - - -(* http://earth-info.nima.mil/GandG/wgs84/gravitymod/egm96/binary/binarygeoid.html *) -let egm96 = fun geo -> - let egm96_data = Lazy.force egm96_data in - - let lat = truncate ((Rad>>Deg) (norm_angle geo.posn_lat)) - and lon = truncate ((Rad>>Deg) (norm_angle geo.posn_long)) in - let ilat = (90-lat)*4 (* 15' == 4 entries per degree *) - and ilon = (lon+if lon < 0 then 360 else 0)*4 in - - let i = (2*(ilat*egm96_ncols+ilon)) in - - let x = Char.code egm96_data.[i] lsl 8 + Char.code egm96_data.[i+1] in - - float ((x lsl 16) asr 16) /. 100. diff --git a/sw/lib/ocaml/latlong.mli b/sw/lib/ocaml/latlong.mli index 7f1db70726..5d7279423a 100644 --- a/sw/lib/ocaml/latlong.mli +++ b/sw/lib/ocaml/latlong.mli @@ -199,6 +199,3 @@ val geo_of_ecef : geodesic -> ecef -> geographic * float (** [geo_of_ecef ellipsoid geo ecef] Returns llh *) val wgs84_hmsl : geographic -> fmeter - -val egm96 : geographic -> fmeter -(** Return geoid height from 15' precomputed file *)