Skip to content

Commit

Permalink
[generators] flight_plan: fix for longitude > 107deg on 32bit systems
Browse files Browse the repository at this point in the history
In ocaml an int is always signed it has only 31bits on 32bit systems...
So when trying to represent a longitude of more than 107 deg as 1e7deg it is more than the max_int of 1073741823
So always use an Int64 in the convert angle function to fix paparazzi#808
  • Loading branch information
flixr committed Aug 20, 2014
1 parent 075c43e commit 6b6297a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sw/tools/generators/gen_flight_plan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ let print_waypoint = fun default_alt waypoint ->
check_altitude (float_of_string alt) waypoint;
printf " {%.1f, %.1f, %s},\\\n" x y alt

let convert_angle = fun rad -> truncate (1e7 *. (Rad>>Deg)rad)
let convert_angle = fun rad -> Int64.of_float (1e7 *. (Rad>>Deg)rad)

let print_waypoint_lla = fun utm0 default_alt waypoint ->
let x = float_attrib waypoint "x"
and y = float_attrib waypoint "y"
and alt = try Xml.attrib waypoint "alt" with _ -> default_alt in
let wgs84 = Latlong.of_utm Latlong.WGS84 (Latlong.utm_add utm0 (x, y)) in
printf " {%d, %d, %.0f}, /* 1e7deg, 1e7deg, cm (hmsl=%.2fm) */ \\\n" (convert_angle wgs84.posn_lat) (convert_angle wgs84.posn_long) (100. *. float_of_string alt) (Egm96.of_wgs84 wgs84)
printf " {%Ld, %Ld, %.0f}, /* 1e7deg, 1e7deg, cm (hmsl=%.2fm) */ \\\n" (convert_angle wgs84.posn_lat) (convert_angle wgs84.posn_long) (100. *. float_of_string alt) (Egm96.of_wgs84 wgs84)


let get_index_block = fun x ->
Expand Down Expand Up @@ -785,8 +785,8 @@ let () =
Xml2h.define "NAV_UTM_EAST0" (sprintf "%.0f" utm0.utm_x);
Xml2h.define "NAV_UTM_NORTH0" (sprintf "%.0f" utm0.utm_y);
Xml2h.define "NAV_UTM_ZONE0" (sprintf "%d" utm0.utm_zone);
Xml2h.define "NAV_LAT0" (sprintf "%d /* 1e7deg */" (convert_angle wgs84.posn_lat));
Xml2h.define "NAV_LON0" (sprintf "%d /* 1e7deg */" (convert_angle wgs84.posn_long));
Xml2h.define "NAV_LAT0" (sprintf "%Ld /* 1e7deg */" (convert_angle wgs84.posn_lat));
Xml2h.define "NAV_LON0" (sprintf "%Ld /* 1e7deg */" (convert_angle wgs84.posn_long));
Xml2h.define "NAV_ALT0" (sprintf "%.0f /* mm above msl */" (1000. *. !ground_alt));
Xml2h.define "NAV_MSL0" (sprintf "%.0f /* mm, EGM96 geoid-height (msl) over ellipsoid */" (1000. *. Egm96.of_wgs84 wgs84));

Expand Down

0 comments on commit 6b6297a

Please sign in to comment.