receive.ml -> server.ml, airprox.ml and aircraft.ml

This commit is contained in:
Pascal Brisset
2005-12-14 15:35:41 +00:00
parent 046e808341
commit 2ef94f58fb
9 changed files with 349 additions and 187 deletions
+1 -2
View File
@@ -108,8 +108,6 @@ visu3d: lib
wind:
cd $(WIND); $(MAKE)
receive: tmtc
$(TMTC)/receive
static_h :
PAPARAZZI_HOME=`pwd` PAPARAZZI_SRC=`pwd` make -f Makefile.gen
@@ -142,6 +140,7 @@ deb :
dpkg-buildpackage -rfakeroot
clean:
rm -fr dox
find . -mindepth 2 -name Makefile -exec sh -c '$(MAKE) -C `dirname {}` $@' \;
find . -name '*~' -exec rm -f {} \;
+5 -5
View File
@@ -20,7 +20,7 @@
</section>
<section name="programs">
<program name="receive" command="sw/ground_segment/tmtc/receive">
<program name="server" command="sw/ground_segment/tmtc/server">
<arg flag="-b" variable="ivy_bus"/>
</program>
<program name="multimon" command="sw/ground_segment/multimon/multimon">
@@ -87,7 +87,7 @@
<session name="Sim 1@Garmisch : 192.168.1">
<variable name="ivy_bus" value="192.168.1:2010"/>
<variable name="map" value="garmisch.xml"/>
<program name="receive"><arg flag="-n"/><arg flag="-http"/></program>
<program name="server"><arg flag="-n"/><arg flag="-http"/></program>
<program name="http server"/>
<program name="sim"><arg flag="-a" constant="Twin1"/></program>
<program name="cockpit"><arg flag="-render" constant="0"/></program>
@@ -98,7 +98,7 @@
<session name="Sim 2@Garmisch">
<variable name="map" value="garmisch.xml"/>
<program name="receive"/>
<program name="server"/>
<program name="gaia"/>
<program name="sim"><arg flag="-a" constant="Twin1"/></program>
<program name="sim"><arg flag="-a" constant="Twin2"/></program>
@@ -116,7 +116,7 @@
<session name="Replay MAV05">
<variable name="map" value="garmisch.xml"/>
<program name="receive"><arg flag="-n"/></program>
<program name="server"><arg flag="-n"/></program>
<program name="cockpit"></program>
<program name="map 2d ml"/>
<program name="play"/>
@@ -129,7 +129,7 @@
<program name="multimon"><arg flag="-p" constant="/tmp/multimon"/></program>
<program name="modem"><arg flag="-d" constant="/tmp/multimon"/></program>
<program name="modem"><arg flag="-d" constant="/dev/ttyUSB0"/></program>
<program name="receive"/>
<program name="server"/>
<program name="messages"><arg flag="-c" constant="telemetry_ap:*"/><arg flag="-c" constant="ground"/></program>
<program name="cockpit"/>
<program name="map 2d ml"/>
-84
View File
@@ -1,84 +0,0 @@
<?xml version="1.0"?>
<control_panel name="paparazzi control panel">
<section name="hosts">
<host name="localhost" ip="127.0.0.1"/>
</section>
<section name="variables">
<variable name="downlink_serial_port" value="/dev/ttyUSB0"/>
<variable name="fbw_serial_port" value="/dev/ttyS1"/>
<variable name="ap_serial_port" value="/dev/ttyS0"/>
<variable name="ivy_bus" value="127.25.255.255:2009"/>
<variable name="map" value="maps/muret_UTM.xml"/>
<variable name="flight_plan" value="flight_plans/muret1.xml"/>
</section>
<section name="programs">
<program name="receive" command="/usr/share/paparazzi/bin/receive.opt">
<arg flag="-b " variable="ivy_bus"/>
</program>
<program name="cockpit" command="/usr/share/paparazzi/bin/cockpit.pl">
<arg flag="-b " variable="ivy_bus"/>
</program>
<program name="map 2d" command="/usr/share/paparazzi/bin/map.pl">
<arg flag="-b " variable="ivy_bus"/>
<arg flag="-m " variable="map"/>
<arg flag="-f " variable="flight_plan"/>
</program>
<program name="map 2d ml" command="/usr/share/paparazzi/bin/map2d.opt">
<arg flag="-b " variable="ivy_bus"/>
<!-- <arg flag="-m" variable="map"/> -->
</program>
<program name="map 3d" command="/usr/share/paparazzi/bin/mapGL.opt">
<arg flag="-b " variable="ivy_bus"/>
<arg flag="-m " variable="map"/>
<arg flag="-f " variable="flight_plan"/>
</program>
<program name="messages" command="/usr/share/paparazzi/bi/messages.opt">
<arg flag="-b " variable="ivy_bus"/>
</program>
<program name="speech" command="/usr/share/paparazzi/bin/paparazzi_speak.pl">
<arg flag="-b " variable="ivy_bus"/>
<arg flag="-t " variable="paparazzi_home"/>
</program>
<program name="wind" command ="/usr/share/paparazzi/bin/wind"/>
<program name="plot" command ="/usr/share/paparazzi/bin/plot.pl"/>
<program name="play" command="/usr/share/paparazzi/bin/play.opt">
<arg flag="-b " variable="ivy_bus"/>
</program>
<program name="sim" command="/usr/share/paparazzi/bin/simsitl.pl">
<arg flag="-b " variable="ivy_bus"/>
<arg flag="-a " constant="Thon1"/>
</program>
<program name="hitl" command="/usr/share/paparazzi/bin/simhitl.out">
<arg flag="-fbw " variable="fbw_serial_port"/>
<arg flag="-ap " variable="ap_serial_port"/>
</program>
<program name="configurator" command="/usr/share/paparazzi/bin/configurator"/>
<program name="medit" command="/usr/share/paparazzi/bin/medit.out"/>
</section>
<section name="sessions">
<session name="soft sim 2">
<variable name="ivy_bus" value="127.25.255.255:3333"/>
<program name="receive"/>
<program name="sim"><arg flag="-a" constant="Thon1"/></program>
<program name="sim"><arg flag="-a" constant="Thon2"/></program>
<program name="cockpit"/>
<program name="map 2d"/>
<program name="map 3d"/>
</session>
<session name="flight">
<program name="receive"/>
<program name="cockpit"/>
<program name="mission"/>
<program name="map2d"/>
</session>
</section>
</control_panel>
+6 -5
View File
@@ -24,11 +24,11 @@ include ../../../conf/Makefile.local
CONF = ../../../conf
VAR = ../../../var
all: hw_modem_listen receive messages wavecard $(VAR)/boa.conf
all: hw_modem_listen server messages wavecard $(VAR)/boa.conf
# stereo_demod
clean:
rm -f hw_modem_listen wavecard_connect receive messages *.bak *~ core *.o .depend *.opt *.out *.cm*
rm -f hw_modem_listen wavecard_connect server messages *.bak *~ core *.o .depend *.opt *.out *.cm*
OCAMLC = ocamlc
OCAMLOPT = ocamlopt
@@ -64,10 +64,10 @@ stereo_demod : ../multimon/multimon.cma stereo_demod.ml ../../lib/ocaml/lib-pprz
@echo 'exec lablgtk2 -I $$PAPARAZZI_SRC/sw/lib/ocaml -I $$PAPARAZZI_SRC/sw/ground_segment/multimon glibivy-ocaml.cma lib-pprz.cma -I $$PAPARAZZI_SRC/sw/ground_segment/tmtc $$PAPARAZZI_SRC/sw/ground_segment/multimon/multimon.cma $$PAPARAZZI_SRC/sw/ground_segment/tmtc/stereo_demod.ml $$*' >> $@
@chmod a+x $@
receive : wind.cmo receive.ml ../../lib/ocaml/lib-pprz.cma
server : aircraft.cmo wind.cmo airprox.cmo server.ml ../../lib/ocaml/lib-pprz.cma
$(OCAMLC) $(INCLUDES) -o $@.out lablgtk.cma glibivy-ocaml.cma lib-pprz.cma $^
@cat ../../../pprz_src_test.sh > $@
@echo 'exec lablgtk2 -I $$PAPARAZZI_SRC/sw/lib/ocaml glibivy-ocaml.cma lib-pprz.cma -I $$PAPARAZZI_SRC/sw/ground_segment/tmtc $$PAPARAZZI_SRC/sw/ground_segment/tmtc/wind.cmo $$PAPARAZZI_SRC/sw/ground_segment/tmtc/receive.ml $$*' >> $@
@echo 'exec lablgtk2 -I $$PAPARAZZI_SRC/sw/lib/ocaml glibivy-ocaml.cma lib-pprz.cma -I $$PAPARAZZI_SRC/sw/ground_segment/tmtc $$PAPARAZZI_SRC/sw/ground_segment/tmtc/aircraft.cmo $$PAPARAZZI_SRC/sw/ground_segment/tmtc/wind.cmo $$PAPARAZZI_SRC/sw/ground_segment/tmtc/airprox.cmo $$PAPARAZZI_SRC/sw/ground_segment/tmtc/server.ml $$*' >> $@
@chmod a+x $@
wavecard : wavecard_connect.ml ../../lib/ocaml/lib-pprz.cma
@@ -85,7 +85,8 @@ modem.cmo : modem.cmi
%.cmi : %.mli
$(OCAMLC) $(INCLUDES) $<
aircraft.cmo : aircraft.cmi
airprox.cmo : airprox.cmi
wavecard_c : wavecard_c.c wavecard_utils_c.c wavecard_foo_c.c
gcc -Wall -o $@ $^ `pkg-config --cflags glib-2.0` `pkg-config --libs glib-2.0`
+113
View File
@@ -0,0 +1,113 @@
(*
* $Id$
*
* Copyright (C) ENAC
*
* 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.
*
*)
type ac_cam = {
mutable phi : float; (* Rad, right = >0 *)
mutable theta : float; (* Rad, front = >0 *)
}
type inflight_calib = {
mutable if_mode : int; (* DOWN|OFF|UP *)
mutable if_val1 : float;
mutable if_val2 : float
}
type contrast_status = string (** DEFAULT|WAITING|SET *)
type infrared = {
mutable gps_hybrid_mode : int;
mutable gps_hybrid_factor : float;
mutable contrast_status : contrast_status;
mutable contrast_value : int
}
type rc_status = string (** OK, LOST, REALLY_LOST *)
type rc_mode = string (** MANUAL, AUTO, FAILSAFE *)
type fbw = {
mutable rc_status : rc_status;
mutable rc_mode : rc_mode;
}
let gps_nb_channels = 16
type svinfo = {
svid : int;
flags : int;
qi : int;
cno : int;
elev : int;
azim : int
}
let svinfo_init = {
svid = 0 ;
flags = 0;
qi = 0;
cno = 0;
elev = 0;
azim = 0;
}
type horiz_mode =
Circle of Latlong.utm * int
| Segment of Latlong.utm * Latlong.utm
| UnknownHorizMode
type aircraft = {
id : string;
mutable pos : Latlong.utm;
mutable roll : float;
mutable pitch : float;
mutable nav_ref : Latlong.utm;
mutable desired_east : float;
mutable desired_north : float;
mutable desired_altitude : float;
mutable desired_course : float;
mutable desired_climb : float;
mutable gspeed : float;
mutable course : float;
mutable alt : float;
mutable climb : float;
mutable cur_block : int;
mutable cur_stage : int;
mutable throttle : float;
mutable throttle_accu : float;
mutable rpm : float;
mutable temp : float;
mutable bat : float;
mutable amp : float;
mutable energy : int;
mutable ap_mode : int;
mutable gaz_mode : int;
mutable lateral_mode : int;
mutable horizontal_mode : int;
cam : ac_cam;
mutable gps_mode : int;
inflight_calib : inflight_calib;
infrared : infrared;
fbw : fbw;
svinfo : svinfo array;
mutable flight_time : int;
mutable stage_time : int;
mutable block_time : int;
mutable horiz_mode : horiz_mode
}
+95
View File
@@ -0,0 +1,95 @@
(*
* $Id$
*
* Copyright (C) ENAC
*
* 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.
*
*)
(** State of an A/C handled by the server *)
type ac_cam = { mutable phi : float; mutable theta : float; }
type inflight_calib = {
mutable if_mode : int;
mutable if_val1 : float;
mutable if_val2 : float;
}
type contrast_status = string
type infrared = {
mutable gps_hybrid_mode : int;
mutable gps_hybrid_factor : float;
mutable contrast_status : contrast_status;
mutable contrast_value : int;
}
type rc_status = string
type rc_mode = string
type fbw = { mutable rc_status : rc_status; mutable rc_mode : rc_mode; }
val gps_nb_channels : int
type svinfo = {
svid : int;
flags : int;
qi : int;
cno : int;
elev : int;
azim : int;
}
val svinfo_init : svinfo
type horiz_mode =
Circle of Latlong.utm * int
| Segment of Latlong.utm * Latlong.utm
| UnknownHorizMode
type aircraft = {
id : string;
mutable pos : Latlong.utm;
mutable roll : float;
mutable pitch : float;
mutable nav_ref : Latlong.utm;
mutable desired_east : float;
mutable desired_north : float;
mutable desired_altitude : float;
mutable desired_course : float;
mutable desired_climb : float;
mutable gspeed : float;
mutable course : float;
mutable alt : float;
mutable climb : float;
mutable cur_block : int;
mutable cur_stage : int;
mutable throttle : float;
mutable throttle_accu : float;
mutable rpm : float;
mutable temp : float;
mutable bat : float;
mutable amp : float;
mutable energy : int;
mutable ap_mode : int;
mutable gaz_mode : int;
mutable lateral_mode : int;
mutable horizontal_mode : int;
cam : ac_cam;
mutable gps_mode : int;
inflight_calib : inflight_calib;
infrared : infrared;
fbw : fbw;
svinfo : svinfo array;
mutable flight_time : int;
mutable stage_time : int;
mutable block_time : int;
mutable horiz_mode : horiz_mode;
}
+73
View File
@@ -0,0 +1,73 @@
(*
* $Id$
*
* Air Proximity Alert Module
*
* Copyright (C) ENAC, Pascal Brisset, Antoine Drouin
*
* 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 Aircraft
open Latlong
module Alerts_Pprz = Pprz.Protocol(struct let name = "alert" end)
(** computes distance between 2d points *)
let distance = fun (x1, y1) (x2, y2) ->
sqrt (((x1 -. x2) **2.) +. ((y1 -. y2)**2.))
(** check if there is an airprox between aircraft1 and aircraft2 *)
(** if the altitude difference is less than 10 meters *)
(** and if the horizontal distance is less than 100 meters (5s between *)
(** 2 aircraft at 10m/s *)
let airprox = fun aircraft1 aircraft2 ->
let x1 = aircraft1.pos.utm_x and x2 = aircraft2.pos.utm_x and
y1 = aircraft1.pos.utm_y and y2 = aircraft2.pos.utm_y and
z1 = aircraft1.alt and z2 = aircraft2.alt in
let alt_difference = abs_float (z1 -. z2) and
dist = distance (x1, y1) (x2, y2) in
((alt_difference < 10.0) && (dist < 100.0))
(** return airprox level *)
(** level is warning if the distance between both aircraft is increasing *)
(** level is crictical otherwise *)
let airprox_level = fun aircraft1 aircraft2 ->
let x1 = aircraft1.pos.utm_x and x2 = aircraft2.pos.utm_x and
y1 = aircraft1.pos.utm_y and y2 = aircraft2.pos.utm_y in
let d0 = distance (x1, y1) (x2, y2) in
let course1 = aircraft1.course and course2 = aircraft2.course and
speed1 = aircraft1.gspeed and speed2 = aircraft2.gspeed in
(** FIXME: must have the real angle and not a course *)
let halfpi = Latlong.pi /. 2. in
let vx1 = speed1 *. (cos (halfpi -. course1)) and
vx2 = speed2 *. (cos (halfpi -. course2)) and
vy1 = speed1 *. (sin (halfpi -. course1)) and
vy2 = speed2 *. (sin (halfpi -. course2)) in
let d1 = distance
(x1+. vx1 *. 0.2, x2+. vx2 *. 0.2)
(y1+. vy1 *. 0.2, y2+. vy2 *. 0.2) in
if d1 < d0 then "CRITICAL" else "WARNING"
(** send a airprox alert on ivy if there is an airprox between ac_name1 and *)
(** ac_name2 *)
type alert_level = string option
let check_airprox = fun ac1 ac2 ->
if airprox ac1 ac2 then Some (airprox_level ac1 ac2) else None
+29
View File
@@ -0,0 +1,29 @@
(*
* $Id$
*
* Air Proximity Alert Module
*
* Copyright (C) ENAC, Pascal Brisset, Antoine Drouin
*
* 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.
*
*)
type alert_level = string option
val check_airprox : Aircraft.aircraft -> Aircraft.aircraft -> alert_level
(** [check_airprox ac1 ac2] Returns airprox level *)
@@ -29,6 +29,7 @@ let gps_mode_3D = 3
open Printf
open Latlong
open Aircraft
module U = Unix
module Tele_Class = struct let name = "telemetry_ap" end
@@ -67,97 +68,7 @@ let check_index = fun i t where ->
i
let get_indexed_value = fun t i ->
if i >= 0 then t.(i) else "UNK"
type ac_cam = {
mutable phi : float; (* Rad, right = >0 *)
mutable theta : float; (* Rad, front = >0 *)
}
type inflight_calib = {
mutable if_mode : int; (* DOWN|OFF|UP *)
mutable if_val1 : float;
mutable if_val2 : float
}
type contrast_status = string (** DEFAULT|WAITING|SET *)
type infrared = {
mutable gps_hybrid_mode : int;
mutable gps_hybrid_factor : float;
mutable contrast_status : contrast_status;
mutable contrast_value : int
}
type rc_status = string (** OK, LOST, REALLY_LOST *)
type rc_mode = string (** MANUAL, AUTO, FAILSAFE *)
type fbw = {
mutable rc_status : rc_status;
mutable rc_mode : rc_mode;
}
let gps_nb_channels = 16
type svinfo = {
svid : int;
flags : int;
qi : int;
cno : int;
elev : int;
azim : int
}
let svinfo_init = {
svid = 0 ;
flags = 0;
qi = 0;
cno = 0;
elev = 0;
azim = 0;
}
type horiz_mode =
Circle of utm * int
| Segment of utm * utm
| UnknownHorizMode
type aircraft = {
id : string;
mutable pos : Latlong.utm;
mutable roll : float;
mutable pitch : float;
mutable nav_ref : Latlong.utm;
mutable desired_east : float;
mutable desired_north : float;
mutable desired_altitude : float;
mutable desired_course : float;
mutable desired_climb : float;
mutable gspeed : float;
mutable course : float;
mutable alt : float;
mutable climb : float;
mutable cur_block : int;
mutable cur_stage : int;
mutable throttle : float;
mutable throttle_accu : float;
mutable rpm : float;
mutable temp : float;
mutable bat : float;
mutable amp : float;
mutable energy : int;
mutable ap_mode : int;
mutable gaz_mode : int;
mutable lateral_mode : int;
mutable horizontal_mode : int;
cam : ac_cam;
mutable gps_mode : int;
inflight_calib : inflight_calib;
infrared : infrared;
fbw : fbw;
svinfo : svinfo array;
mutable flight_time : int;
mutable stage_time : int;
mutable block_time : int;
mutable horiz_mode : horiz_mode
}
if i >= 0 then t.(i) else "UNK"
(** The aircrafts store *)
let aircrafts = Hashtbl.create 3
@@ -541,10 +452,35 @@ let wind_clear = fun _sender vs ->
let periodic = fun period cb ->
ignore (Glib.Timeout.add period (fun () -> cb (); true))
(** add the periodic airprox check for the aircraft (name) on all aircraft *)
(** already known *)
let periodic_airprox_check = fun name ->
let thisac = Hashtbl.find aircrafts name in
let aircrafts2list = fun () ->
let list = ref [] in
Hashtbl.iter (fun name a -> list := name :: !list) aircrafts;
!list in
let ac_names = List.filter (fun a -> a <> name) (aircrafts2list ()) in
let list_ac = List.map (fun name -> Hashtbl.find aircrafts name) ac_names in
let check_airprox = fun ac ->
match Airprox.check_airprox thisac ac with
None -> ()
| Some level ->
let vs =
["ac_id", Pprz.String (thisac.id ^ "," ^ ac.id) ; "level", Pprz.String level; "value", Pprz.String ac.id] in
Alerts_Pprz.message_send my_id "AIR_PROX" vs in
List.iter
(fun ac ->
periodic aircraft_alerts_period (fun () -> check_airprox ac)
) list_ac
let register_aircraft = fun name a ->
Hashtbl.add aircrafts name a;
periodic aircraft_msg_period (fun () -> send_aircraft_msg name);
periodic aircraft_alerts_period (fun () -> check_alerts a);
periodic_airprox_check name;
periodic wind_msg_period (fun () -> send_wind a);
Wind.new_ac name 1000;
ignore(Ground_Pprz.message_bind "WIND_CLEAR" wind_clear)