[autopilot] AP is generated when autopilot node exists in airframe

This commit is contained in:
Gautier Hattenberger
2012-11-14 14:09:32 +01:00
parent 6cc88ba260
commit 1cde58928b
8 changed files with 53 additions and 39 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ SETTINGS_TELEMETRY=$(ACINCLUDE)/settings_telemetry.xml
MAKEFILE_AC=$(ACINCLUDE)/Makefile.ac
MODULES_H=$(AC_GENERATED)/modules.h
MODULES_DIR=$(PAPARAZZI_HOME)/conf/modules/
AUTOPILOT_H=$(AC_GENERATED)/autopilot.h
AUTOPILOT_H=$(AC_GENERATED)/autopilot_core.h
AIRCRAFT_MD5=$(AIRCRAFT_CONF_DIR)/aircraft.md5
# "make Q=''" to get full echo
@@ -8,6 +8,8 @@
<airframe name="Weasel">
<autopilot name="fixedwing_autopilot.xml"/>
<modules>
<!--load name="airspeed_ads1114.xml"/-->
<!--load name="mcp355x.xml"/-->
+6 -1
View File
@@ -1,6 +1,6 @@
<!-- Paparazzi airframe DTD -->
<!ELEMENT airframe (include|servos|commands|rc_commands|auto_rc_commands|ap_only_commands|command_laws|section|makefile|modules|firmware)*>
<!ELEMENT airframe (include|servos|commands|rc_commands|auto_rc_commands|ap_only_commands|command_laws|section|makefile|modules|firmware|autopilot)*>
<!ELEMENT include EMPTY>
<!ELEMENT servos (servo)*>
<!ELEMENT commands (axis)*>
@@ -25,6 +25,7 @@
<!ELEMENT firmware (target|subsystem|configure|define)*>
<!ELEMENT target (subsystem|configure|define)*>
<!ELEMENT subsystem (configure|define)*>
<!ELEMENT autopilot EMPTY>
<!ATTLIST include
href CDATA #REQUIRED>
@@ -32,6 +33,10 @@ href CDATA #REQUIRED>
<!ATTLIST firmware
name CDATA #REQUIRED>
<!ATTLIST autopilot
name CDATA #REQUIRED
freq CDATA #IMPLIED>
<!ATTLIST target
name CDATA #REQUIRED
board CDATA #REQUIRED
+17 -14
View File
@@ -1,8 +1,4 @@
(*
* $Id: gen_modules.ml 4538 2010-02-04 09:45:08Z gautier $
*
* XML preprocessing for core autopilot
*
* Copyright (C) 2010 Gautier Hattenberger
*
* This file is part of paparazzi.
@@ -20,10 +16,13 @@
* 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.
* Boston, MA 02111-1307, USA.
*
*)
(*
* XML preprocessing for core autopilot
*)
open Printf
open Xml2h
@@ -131,7 +130,7 @@ let print_test_exception = fun modes out_h ->
lprintf out_h "\nstatic inline uint8_t autopilot_core_mode_exceptions(uint8_t mode) {\n";
right ();
lprintf out_h "switch ( mode ) { \n";
lprintf out_h "switch ( mode ) {\n";
right ();
List.iter (fun m -> (* Test exceptions for all modes *)
lprintf out_h "case %s :\n" (print_mode_name (Xml.attrib m "name"));
@@ -176,12 +175,12 @@ let print_set_mode = fun modes out_h ->
left ();
in
let print_switch = fun var modes t ->
lprintf out_h "switch ( %s ) { \n" var;
lprintf out_h "// switch over %s functions\n" t;
lprintf out_h "switch ( %s ) {\n" var;
right ();
List.iter (fun m ->
try
let stop = Xml.attrib m t in
print_case m stop
print_case m (Xml.attrib m t)
with _ -> ()
) modes;
left ();
@@ -193,10 +192,10 @@ let print_set_mode = fun modes out_h ->
lprintf out_h "if (new_mode == private_autopilot_mode) return;\n\n"; (* set mode if different from current mode *)
(* Print stop functions for each modes *)
print_switch "private_autopilot_mode" modes "stop";
lprintf out_h "\n";
fprintf out_h "\n";
(* Print start functions for each modes *)
print_switch "new_mode" modes "start";
lprintf out_h "\n";
fprintf out_h "\n";
lprintf out_h "last_autopilot_mode = private_autopilot_mode;\n";
lprintf out_h "private_autopilot_mode = new_mode;\n";
lprintf out_h "autopilot_mode = new_mode;\n";
@@ -227,7 +226,7 @@ let print_ap_periodic = fun modes ctrl_block main_freq out_h ->
in
(** Equivalent to the RunOnceEvery macro *)
let print_prescaler = fun pre ctrl ->
lprintf out_h "{ \n";
lprintf out_h "{\n";
right ();
lprintf out_h "static uint16_t prescaler = 0;\n";
lprintf out_h "prescaler++;\n";
@@ -251,7 +250,7 @@ let print_ap_periodic = fun modes ctrl_block main_freq out_h ->
lprintf out_h "mode = autopilot_core_mode_exceptions(mode);\n"; (* change mode according to exceptions *)
lprintf out_h "mode = autopilot_core_global_exceptions(mode);\n"; (* change mode according to global exceptions *)
lprintf out_h "autopilot_core_set_mode(mode);\n\n"; (* set new mode and call start/stop functions *)
lprintf out_h "switch ( private_autopilot_mode ) { \n";
lprintf out_h "switch ( private_autopilot_mode ) {\n";
right ();
List.iter (fun m -> (* Print control loops for each modes *)
lprintf out_h "case %s :\n" (print_mode_name (Xml.attrib m "name"));
@@ -337,6 +336,10 @@ let () =
| Dtd.Prove_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.prove_error e); exit 1
| Dtd.Check_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.check_error e); exit 1
| Dtd.Parse_error e -> fprintf stderr "%s: DTD error:%s\n%!" xml_file (Dtd.parse_error e); exit 1
| Not_found -> let out_h = open_out h_file in close_out out_h; exit 0
| Not_found ->
let out_h = open_out h_file in
fprintf out_h "/*** Sorry, no autopilot file found ***/\n";
close_out out_h;
exit 0
+26 -22
View File
@@ -65,11 +65,30 @@ let targets_of_field = fun field default ->
with
_ -> []
(** [get_autopilot_of_airframe xml]
* Returns (autopilot xml, main freq) from airframe xml file *)
let get_autopilot_of_airframe = fun xml ->
(* extract all "modules" sections *)
let section = List.filter (fun s -> compare (Xml.tag s) "autopilot" = 0) (Xml.children xml) in
(* Raise error if more than one modules section *)
match section with
[autopilot] ->
let freq = try int_of_string (Xml.attrib autopilot "freq") with _ -> default_freq in
let ap = try Xml.attrib autopilot "name" with _ -> raise Not_found in
(autopilot_dir // ap, freq)
| [] -> raise Not_found
| _ -> failwith "Error: you have more than one 'autopilot' section in your airframe file"
(** [get_modules_of_airframe xml]
* Returns a list of module configuration from airframe file *)
let rec get_modules_of_airframe = fun xml ->
(* extract all "modules" sections *)
let section = List.filter (fun s -> compare (Xml.tag s) "modules" = 0) (Xml.children xml) in
(* get autopilot file if any *)
let ap_file = try
let (ap, _) = get_autopilot_of_airframe xml in
ap
with _ -> "" in
(* Raise error if more than one modules section *)
match section with
[modules] ->
@@ -80,15 +99,14 @@ let rec get_modules_of_airframe = fun xml ->
let targets = singletonize (t @ targets_of_field m "") in
{ xml = ExtXml.parse_file file; file = file; param = Xml.children m; extra_targets = targets }
in
List.flatten (List.map (fun m ->
let modules_list = List.map (fun m ->
if compare (Xml.tag m) "load" <> 0 then Xml2h.xml_error "load";
let airframe_module = [get_module m t_global] in
let ap_module = try
let ap_file = autopilot_dir // ExtXml.attrib m "autopilot" in
get_modules_of_airframe (ExtXml.parse_file ap_file)
with _ -> [] in
List.flatten [airframe_module @ ap_module]
) (Xml.children modules))
get_module m t_global
) (Xml.children modules) in
let ap_modules = try
get_modules_of_airframe (ExtXml.parse_file ap_file)
with _ -> [] in
modules_list @ ap_modules
| [] -> []
| _ -> failwith "Error: you have more than one 'modules' section in your airframe file"
@@ -136,17 +154,3 @@ let get_modules_dir = fun modules ->
let dir = List.map (fun m -> try Xml.attrib m.xml "dir" with _ -> ExtXml.attrib m.xml "name") modules in
singletonize (List.sort compare dir)
(** [get_autopilot_of_airframe xml]
* Returns (autopilot xml, main freq) from airframe xml file *)
let get_autopilot_of_airframe = fun xml ->
(* extract all "modules" sections *)
let section = List.filter (fun s -> compare (Xml.tag s) "modules" = 0) (Xml.children xml) in
(* Raise error if more than one modules section *)
match section with
[modules] ->
let main_freq = try int_of_string (Xml.attrib modules "main_freq") with _ -> default_freq in
let ap = try Xml.attrib modules "autopilot" with _ -> raise Not_found in
(autopilot_dir // ap, main_freq)
| [] -> raise Not_found
| _ -> failwith "Error: you have more than one 'modules' section in your airframe file"
+1 -1
View File
@@ -68,7 +68,7 @@ val get_modules_dir : module_conf list -> string list
(** [get_autopilot_of_airframe xml]
* Returns (autopilot file, main freq) from airframe xml file
* Raise Not_found if no autopilot
* Raise Not_found if no autopilot
* Fail if more than one *)
val get_autopilot_of_airframe : Xml.xml -> (string * int)