diff --git a/Makefile b/Makefile index 3f979175ee..ebb93d68b5 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,7 @@ XSENS_XML = $(CONF)/xsens_MTi-G.xml TOOLS=$(PAPARAZZI_SRC)/sw/tools OCAML=$(shell which ocaml) OCAMLRUN=$(shell which ocamlrun) +BUILD_DATETIME:=$(shell date +%Y%m%d-%H%M%S) # try to find the paparazzi multilib toolchain TOOLCHAIN=$(shell find -L /opt/paparazzi/arm-multilib ~/sat -maxdepth 1 -type d -name arm-none-eabi 2>/dev/null | head -n 1) @@ -264,9 +265,12 @@ ab_clean: find sw/airborne -name '*~' -exec rm -f {} \; replace_current_conf_xml: - test conf/conf.xml || mv conf/conf.xml conf/conf.xml.backup.`date +%Y%m%d-%H%M%s` + test conf/conf.xml && mv conf/conf.xml conf/conf.xml.backup.$(BUILD_DATETIME) cp conf/conf.xml.example conf/conf.xml +restore_conf_xml: + test conf/conf.xml.backup.$(BUILD_DATETIME) && mv conf/conf.xml.backup.$(BUILD_DATETIME) conf/conf.xml + commands: paparazzi sw/simulator/launchsitl paparazzi: @@ -277,6 +281,8 @@ sw/simulator/launchsitl: cat src/$(@F) | sed s#OCAMLRUN#$(OCAMLRUN)# | sed s#OCAML#$(OCAML)# > $@ chmod a+x $@ -test: all replace_current_conf_xml +run_tests: cd tests; $(MAKE) test +test: all replace_current_conf_xml run_tests restore_conf_xml + diff --git a/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_overo_fw.xml b/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_fw.xml similarity index 95% rename from conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_overo_fw.xml rename to conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_fw.xml index 5d15f79490..ed43bd8e61 100644 --- a/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_overo_fw.xml +++ b/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_fw.xml @@ -5,7 +5,7 @@ Lisa/L v1.1 board XBee connected to UART2 configured at 38400 Aspirin v1.5 - overo + GPS connected to UART1 (Since this is inside in a metal box it won't ever get a solution) --> @@ -14,12 +14,15 @@ - + - + + + + @@ -138,7 +141,7 @@ - + diff --git a/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_overo_rc.xml b/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_rc.xml similarity index 92% rename from conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_overo_rc.xml rename to conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_rc.xml index 847289e905..3aed8ead28 100644 --- a/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_overo_rc.xml +++ b/conf/airframes/TestHardware/LisaL_v1.1_aspirin_v1.5_rc.xml @@ -3,9 +3,8 @@ The hardware configuration is Powered via a plug 12V pack Lisa/L v1.1 board - XBee connected to UART2 configured at 38400 + XBee connected to UART2 configured at 38400 (Configured for XBee API Booz2 v1.2 - GPS connected to UART1 (Since this is inside in a metal box it won't ever get a solution) --> @@ -22,7 +21,9 @@ - + + + @@ -185,25 +186,6 @@ - - diff --git a/conf/airframes/TestHardware/LisaL_v1.1_b2_v1.2_fw.xml b/conf/airframes/TestHardware/LisaL_v1.1_b2_v1.2_fw.xml index d5e3f0200c..f14704c046 100644 --- a/conf/airframes/TestHardware/LisaL_v1.1_b2_v1.2_fw.xml +++ b/conf/airframes/TestHardware/LisaL_v1.1_b2_v1.2_fw.xml @@ -10,14 +10,20 @@ - + + + - + - + + + + + @@ -26,24 +32,24 @@ - + - + - +
- + @@ -51,10 +57,139 @@ - +
- + +
+ + + +
+ +
+ + + + + +
+ +
+ + + + + + + +
+ + +
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + +
+
diff --git a/conf/conf.xml.example b/conf/conf.xml.example index bdf772c3da..3933edcd1d 100644 --- a/conf/conf.xml.example +++ b/conf/conf.xml.example @@ -97,14 +97,34 @@ settings="settings/rotorcraft_basic.xml settings/control/rotorcraft_guidance.xml settings/control/stabilization_att_int.xml" gui_color="white" /> - + + diff --git a/conf/firmwares/subsystems/shared/imu_b2_v1.2.makefile b/conf/firmwares/subsystems/shared/imu_b2_v1.2.makefile index 78d426536f..c0d27c4026 100644 --- a/conf/firmwares/subsystems/shared/imu_b2_v1.2.makefile +++ b/conf/firmwares/subsystems/shared/imu_b2_v1.2.makefile @@ -48,7 +48,7 @@ imu_CFLAGS += -DIMU_B2_VERSION_1_2 ifeq ($(ARCH), lpc21) imu_CFLAGS += -DIMU_B2_MAG_TYPE=IMU_B2_MAG_HMC58XX -imu_CFLAGS += -DHMC58XX_I2C_DEVICE=i2c1 -DUSE_I2C1 +imu_CFLAGS += -DHMC58XX_I2C_DEVICE=i2c1 -DUSE_I2C1 -DI2C1_VIC_SLOT=12 imu_srcs += peripherals/hmc58xx.c else ifeq ($(ARCH), stm32) imu_CFLAGS += -DIMU_B2_MAG_TYPE=IMU_B2_MAG_HMC5843 diff --git a/conf/settings/control/rotorcraft_guidance.xml b/conf/settings/control/rotorcraft_guidance.xml index 73e03f6d80..833deae011 100644 --- a/conf/settings/control/rotorcraft_guidance.xml +++ b/conf/settings/control/rotorcraft_guidance.xml @@ -7,7 +7,7 @@ - + diff --git a/conf/settings/estimation/infrared.xml b/conf/settings/estimation/infrared.xml index 9ebd483cd4..629ea2419d 100644 --- a/conf/settings/estimation/infrared.xml +++ b/conf/settings/estimation/infrared.xml @@ -3,8 +3,8 @@ - - + + diff --git a/conf/units.xml b/conf/units.xml index 022537d529..559f2e1a2d 100644 --- a/conf/units.xml +++ b/conf/units.xml @@ -1,10 +1,10 @@ - - - - + + + + diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c index 33a826ebde..308cf016f6 100644 --- a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c +++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c @@ -59,7 +59,7 @@ int32_t guidance_v_ff_cmd; int32_t guidance_v_fb_cmd; int32_t guidance_v_delta_t; -int16_t guidance_v_nominal_throttle; +float guidance_v_nominal_throttle; /** Direct throttle from radio control. @@ -108,7 +108,7 @@ void guidance_v_init(void) { guidance_v_z_sum_err = 0; #ifdef GUIDANCE_V_NOMINAL_HOVER_THROTTLE - guidance_v_nominal_throttle = GUIDANCE_V_NOMINAL_HOVER_THROTTLE * MAX_PPRZ; + guidance_v_nominal_throttle = GUIDANCE_V_NOMINAL_HOVER_THROTTLE; #endif gv_adapt_init(); @@ -275,7 +275,7 @@ __attribute__ ((always_inline)) static inline void run_hover_loop(bool_t in_flig /* our nominal command : (g + zdd)*m */ #ifdef GUIDANCE_V_NOMINAL_HOVER_THROTTLE - const int32_t inv_m = BFP_OF_REAL(9.81/guidance_v_nominal_throttle, FF_CMD_FRAC); + const int32_t inv_m = BFP_OF_REAL(9.81/(guidance_v_nominal_throttle*MAX_PPRZ), FF_CMD_FRAC); #else const int32_t inv_m = gv_adapt_X>>(GV_ADAPT_X_FRAC - FF_CMD_FRAC); #endif diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h index 7a2c7e5872..28b887eb9b 100644 --- a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h +++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h @@ -95,9 +95,10 @@ extern int32_t guidance_v_fb_cmd; ///< feed-back command extern int32_t guidance_v_delta_t; /** nominal throttle for hover. - * range: 0 : #MAX_PPRZ + * This is only used if #"GUIDANCE_V_NOMINAL_HOVER_THROTTLE is defined! + * Unit: factor of #MAX_PPRZ with range 0.1 : 0.9 */ -extern int16_t guidance_v_nominal_throttle; +extern float guidance_v_nominal_throttle; extern int32_t guidance_v_kp; ///< vertical control P-gain extern int32_t guidance_v_kd; ///< vertical control D-gain @@ -114,10 +115,4 @@ extern void guidance_v_run(bool_t in_flight); guidance_v_z_sum_err = 0; \ } -#define guidance_v_SetNominalHoverThrottle(_throttle) { \ - guidance_v_nominal_throttle = _throttle; \ - Bound(guidance_v_nominal_throttle, 0.1*MAX_PPRZ, 0.9*MAX_PPRZ); \ - } - - #endif /* GUIDANCE_V */ diff --git a/sw/airborne/subsystems/imu/imu_aspirin2.c b/sw/airborne/subsystems/imu/imu_aspirin2.c index a57b64c688..1485ff1369 100644 --- a/sw/airborne/subsystems/imu/imu_aspirin2.c +++ b/sw/airborne/subsystems/imu/imu_aspirin2.c @@ -42,11 +42,11 @@ static void mpu_configure(void); void imu_impl_init(void) { imu_aspirin2.status = Aspirin2StatusUninit; - imu_aspirin2.imu_available = FALSE; + imu_aspirin2.imu_spi_data_received = FALSE; aspirin2_mpu60x0.mosi_buf = imu_aspirin2.imu_tx_buf; aspirin2_mpu60x0.miso_buf = imu_aspirin2.imu_rx_buf; - aspirin2_mpu60x0.ready = &(imu_aspirin2.imu_available); + aspirin2_mpu60x0.ready = &(imu_aspirin2.imu_spi_data_received); aspirin2_mpu60x0.length = 2; } diff --git a/sw/airborne/subsystems/imu/imu_aspirin2.h b/sw/airborne/subsystems/imu/imu_aspirin2.h index b00f37ca89..8a367fbb32 100644 --- a/sw/airborne/subsystems/imu/imu_aspirin2.h +++ b/sw/airborne/subsystems/imu/imu_aspirin2.h @@ -98,7 +98,7 @@ enum Aspirin2Status struct ImuAspirin2 { volatile enum Aspirin2Status status; - volatile uint8_t imu_available; + volatile uint8_t imu_spi_data_received; volatile uint8_t imu_tx_buf[64]; volatile uint8_t imu_rx_buf[64]; }; @@ -106,10 +106,14 @@ struct ImuAspirin2 { extern struct ImuAspirin2 imu_aspirin2; -static inline void imu_from_buff(void) +static inline uint8_t imu_from_buff(void) { int32_t x, y, z, p, q, r, Mx, My, Mz; +#define MPU_OFFSET_STATUS 1 + if (!(imu_aspirin2.imu_rx_buf[MPU_OFFSET_STATUS] & 0x01)) { + return 0; + } // If the itg3200 I2C transaction has succeeded: convert the data #define MPU_OFFSET_GYRO 10 @@ -137,18 +141,7 @@ static inline void imu_from_buff(void) VECT3_ASSIGN(imu.mag_unscaled, Mz, -Mx, My); #endif - - //FIXME, remove it or use it... -#if 0 - // Is this is new data -#define MPU_OFFSET_STATUS 1 - if (imu_aspirin2.imu_rx_buf[MPU_OFFSET_STATUS] & 0x01) { - //gyr_valid = TRUE; - //acc_valid = TRUE; - } - else { - } -#endif + return 1; } @@ -156,13 +149,14 @@ static inline void imu_aspirin2_event(void (* _gyro_handler)(void), void (* _acc { if (imu_aspirin2.status == Aspirin2StatusUninit) return; - if (imu_aspirin2.imu_available) { - imu_aspirin2.imu_available = FALSE; - imu_from_buff(); - - _gyro_handler(); - _accel_handler(); - _mag_handler(); + if (imu_aspirin2.imu_spi_data_received) { + imu_aspirin2.imu_spi_data_received = FALSE; + if (imu_from_buff()) + { + _gyro_handler(); + _accel_handler(); + _mag_handler(); + } } } diff --git a/sw/ground_segment/cockpit/saveSettings.ml b/sw/ground_segment/cockpit/saveSettings.ml index 7c06daa0b1..add02f68a0 100644 --- a/sw/ground_segment/cockpit/saveSettings.ml +++ b/sw/ground_segment/cockpit/saveSettings.ml @@ -1,6 +1,4 @@ (* - * $Id$ - * * GUI to save settings in the airframe file * * Copyright (C) 2008, Cyril Allignol, Pascal Brisset @@ -32,7 +30,8 @@ let col_index = cols#add Gobject.Data.int let col_param = cols#add Gobject.Data.string and col_airframe_value = cols#add Gobject.Data.float and col_settings_value = cols#add Gobject.Data.float -and col_settings_scaled_value = cols#add Gobject.Data.float +and col_airframe_value_new = cols#add Gobject.Data.float +and col_code_value = cols#add Gobject.Data.float and col_to_save = cols#add Gobject.Data.boolean let (//) = Filename.concat @@ -93,7 +92,7 @@ let write_xml = fun (model:GTree.tree_store) old_file airframe_xml file -> let new_xml = ref airframe_xml in model#foreach (fun _path row -> if model#get ~row ~column:col_to_save then begin - let new_value = model#get ~row ~column:col_settings_scaled_value + let new_value = model#get ~row ~column:col_airframe_value_new and param = model#get ~row ~column:col_param in new_xml := EditAirframe.set !new_xml param (string_of_float new_value) end; @@ -111,8 +110,8 @@ let send_airframe_values = fun (model:GTree.tree_store) send_value -> model#foreach (fun _path row -> if model#get ~row ~column:col_to_save then begin let index = model#get ~row ~column:col_index - and airframe_value = model#get ~row ~column:col_airframe_value in - send_value index airframe_value + and code_value = model#get ~row ~column:col_code_value in + send_value index code_value end; false) @@ -124,15 +123,37 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml -> let attrib = fun a -> Xml.attrib dl_setting a in try let param = attrib "param" in - let (airframe_value, unit) = EditAirframe.get airframe_xml param in - let scale = + let (airframe_value, airframe_unit, code_unit) = EditAirframe.get airframe_xml param in + (* + * Get the scaling between the unit set in the airframe file to the real unit used (code_unit) + * Print error and use a factor of 1 when code_unit (in airframe file) and unit (in settings file) not equal + *) + let unit_setting = try Some (attrib "unit") with _ -> None in + let airframe_scale = try - let unit_setting = attrib "unit" + let unit_code = + match code_unit, unit_setting with + | Some uc, Some us -> + 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 -> "" and unit_airframe = - match unit with Some u -> u | None -> raise Exit in - Pprz.scale_of_units unit_setting unit_airframe + match airframe_unit with + | Some u -> u + | 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 with - _ -> 1. in + | Invalid_argument s -> prerr_endline s; flush stderr; raise Exit + | _ -> 1. + in + (* + * settings are displayed in alt_unit specified in settings file + * first try the alt_coef, otherwise try to convert the units + *) + let display_scale = float_of_string (Pprz.alt_unit_coef_of_xml dl_setting) in let val_list = Str.split (Str.regexp "[ ()]+") airframe_value in let (scale_macros, str_val) = List.partition (fun x -> Str.string_match (Str.regexp "RadOfDeg\\|DegOfRad") x 0) val_list in let extra_scale = @@ -143,22 +164,24 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml -> | _ -> 1. with _ -> 1. in - let scaled_value = + let airframe_value_scaled = try - float_of_string (List.hd str_val) *. scale *. extra_scale + float_of_string (List.hd str_val) *. airframe_scale *. extra_scale with Failure "float_of_string" -> raise (EditAirframe.No_param param) in - + let airframe_value_new = value /. airframe_scale in + (* Printf.fprintf stderr "param %s: airframe_scale=%f display_scale=%f extra_scale=%f\n" param airframe_scale display_scale extra_scale; flush stderr; *) let row = model#append () in model#set ~row ~column:col_index index; model#set ~row ~column:col_param param; - model#set ~row ~column:col_airframe_value scaled_value; - model#set ~row ~column:col_settings_value value; - model#set ~row ~column:col_settings_scaled_value (value /. scale); - model#set ~row ~column:col_to_save (floats_not_equal scaled_value value) + model#set ~row ~column:col_airframe_value (airframe_value_scaled *. display_scale); + model#set ~row ~column:col_settings_value (value *. display_scale); + model#set ~row ~column:col_airframe_value_new airframe_value_new; + model#set ~row ~column:col_code_value value; + model#set ~row ~column:col_to_save (floats_not_equal airframe_value_scaled value) with - Xml.No_attribute _ -> () + Xml.No_attribute _ | Exit -> () | EditAirframe.No_param param -> not_in_airframe_file := param :: !not_in_airframe_file ) (* Not savable *) settings; diff --git a/sw/ground_segment/tmtc/server.ml b/sw/ground_segment/tmtc/server.ml index 6ead1895f7..c5f559df42 100644 --- a/sw/ground_segment/tmtc/server.ml +++ b/sw/ground_segment/tmtc/server.ml @@ -639,20 +639,20 @@ let move_wp = fun logging _sender vs -> let f = fun a -> List.assoc a vs and ac_id = Pprz.string_assoc "ac_id" vs and deg7 = fun f -> Pprz.Int32 (Int32.of_float (Pprz.float_assoc f vs *. 1e7)) in - let vs = [ "ac_id", Pprz.String ac_id; - "wp_id", f "wp_id"; - "lat", deg7 "lat"; - "lon", deg7 "long"; - "alt", cm_of_m (Pprz.float_assoc "alt" vs) ] in + let vs = [ "wp_id", f "wp_id"; + "ac_id", Pprz.String ac_id; + "lat", deg7 "lat"; + "lon", deg7 "long"; + "alt", cm_of_m (Pprz.float_assoc "alt" vs) ] in Dl_Pprz.message_send dl_id "MOVE_WP" vs; log logging ac_id "MOVE_WP" vs (** Got a DL_SETTING, and send an SETTING *) let setting = fun logging _sender vs -> let ac_id = Pprz.string_assoc "ac_id" vs in - let vs = ["ac_id", Pprz.String ac_id; - "index", List.assoc "index" vs; - "value", List.assoc "value" vs] in + let vs = [ "index", List.assoc "index" vs; + "ac_id", Pprz.String ac_id; + "value", List.assoc "value" vs] in Dl_Pprz.message_send dl_id "SETTING" vs; log logging ac_id "SETTING" vs @@ -660,8 +660,8 @@ let setting = fun logging _sender vs -> (** Got a GET_DL_SETTING, and send an GET_SETTING *) let get_setting = fun logging _sender vs -> let ac_id = Pprz.string_assoc "ac_id" vs in - let vs = ["ac_id", Pprz.String ac_id; - "index", List.assoc "index" vs] in + let vs = [ "index", List.assoc "index" vs; + "ac_id", Pprz.String ac_id ] in Dl_Pprz.message_send dl_id "GET_SETTING" vs; log logging ac_id "GET_SETTING" vs @@ -669,7 +669,7 @@ let get_setting = fun logging _sender vs -> (** Got a JUMP_TO_BLOCK, and send an BLOCK *) let jump_block = fun logging _sender vs -> let ac_id = Pprz.string_assoc "ac_id" vs in - let vs = ["ac_id", Pprz.String ac_id; "block_id", List.assoc "block_id" vs] in + let vs = ["block_id", List.assoc "block_id" vs; "ac_id", Pprz.String ac_id] in Dl_Pprz.message_send dl_id "BLOCK" vs; log logging ac_id "BLOCK" vs diff --git a/sw/lib/ocaml/editAirframe.ml b/sw/lib/ocaml/editAirframe.ml index 08c885343e..aa45700e82 100644 --- a/sw/lib/ocaml/editAirframe.ml +++ b/sw/lib/ocaml/editAirframe.ml @@ -25,7 +25,7 @@ *) type units = string option -type data = string * units +type data = string * units * units exception Got_it of data exception No_param of string @@ -39,8 +39,11 @@ let get = fun xml param -> and units = try Some (snd (List.find (fun (p, v) -> p = "unit") params)) with Not_found -> None + and code_units = + try Some (snd (List.find (fun (p, v) -> p = "code_unit") params)) + with Not_found -> None in - raise (Got_it (old_val, units)) + raise (Got_it (old_val, units, code_units)) | Nethtml.Element (block, params, children) -> let new_prefix = List.fold_left (fun acc (p, v) -> if p = "prefix" then v^acc else acc) prefix params in diff --git a/sw/lib/ocaml/editAirframe.mli b/sw/lib/ocaml/editAirframe.mli index 0da259a7a4..744e9d531d 100644 --- a/sw/lib/ocaml/editAirframe.mli +++ b/sw/lib/ocaml/editAirframe.mli @@ -25,7 +25,7 @@ *) type units = string option -type data = string * units +type data = string * units * units val get : Nethtml.document -> string -> data (** [get xml param] Returns the associated value in a [define] element *) diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index 28b1c33039..1302dc4167 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -160,6 +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 * string let scale_of_units = fun from_unit to_unit -> if (from_unit = to_unit) then @@ -171,15 +172,18 @@ let scale_of_units = fun from_unit to_unit -> let _unit = List.find (fun u -> (* will raise Xml.No_attribute if not a valid attribute *) let f = Xml.attrib u "from" - and t = Xml.attrib u "to" in - if from_unit = f && to_unit = t then true else false + and t = Xml.attrib u "to" + 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") with Xml.File_not_found _ -> raise (Unit_conversion_error ("Parse error of conf/units.xml")) | 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 -> raise (Unknown_conversion (from_unit, to_unit)) + | Not_found -> + 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)) @@ -189,12 +193,13 @@ 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 coef + let pipe_regexp = Str.regexp "|" let field_of_xml = fun xml -> let t = ExtXml.attrib xml "type" in diff --git a/sw/lib/ocaml/pprz.mli b/sw/lib/ocaml/pprz.mli index 7dad2be584..b7ec04c53f 100644 --- a/sw/lib/ocaml/pprz.mli +++ b/sw/lib/ocaml/pprz.mli @@ -90,6 +90,10 @@ 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 * string +(** No_automatic_conversion raised when no conversion found + * and from_unit or to_unit are empty string + *) val scale_of_units : string -> string -> float (** scale_of_units from to diff --git a/sw/tools/gen_airframe.ml b/sw/tools/gen_airframe.ml index a1d2e8a7fb..aa58e5ad54 100644 --- a/sw/tools/gen_airframe.ml +++ b/sw/tools/gen_airframe.ml @@ -80,21 +80,15 @@ let define_integer name v n = in continious_frac (truncate v) v (1, (truncate v)) (0, 1) -let code_unit_scale_of_tag = function t -> +let code_unit_coef_of_xml = function xml -> (* if unit attribute is not specified don't even attempt to convert the units *) - let u = try ExtXml.attrib t "unit" with _ -> failwith "Unit conversion error" in - let cu = try ExtXml.attrib t "code_unit" with _ -> "" in + let u = try Xml.attrib xml "unit" with _ -> failwith "Unit conversion error" in + let cu = ExtXml.attrib_or_default xml "code_unit" "" in (* default value for code_unit is rad[/s] when unit is deg[/s] *) - try match (u, cu) with - ("deg", "") -> Pprz.scale_of_units u "rad" (* implicit conversion to rad *) - | ("deg/s", "") -> Pprz.scale_of_units u "rad/s" (* implicit conversion to rad/s *) - | (_, "") -> failwith "Unit conversion error" (* code unit is not defined and no implicit conversion *) - | (_,_) -> Pprz.scale_of_units u cu (* try to convert *) - with - Pprz.Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; exit 1 - | Pprz.Unknown_conversion (su, scu) -> prerr_endline (sprintf "Warning: unknown unit conversion: from %s to %s" su scu); flush stderr; failwith "Unknown unit conversion" - | _ -> failwith "Unit conversion error" - + try Pprz.scale_of_units u cu with + | Pprz.Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; exit 1 + | Pprz.Unknown_conversion (su, scu) -> prerr_endline (sprintf "Warning: unknown unit conversion: from %s to %s" su scu); flush stderr; failwith "Unknown unit conversion" + | Pprz.No_automatic_conversion _ | _ -> failwith "Unit conversion error" let parse_element = fun prefix s -> match Xml.tag s with @@ -104,7 +98,7 @@ let parse_element = fun prefix s -> (* fail if units conversion is not found and just copy value instead, this is important for integer values, you can't just multiply them with 1.0 *) try - let value = (ExtXml.float_attrib s "value") *. (code_unit_scale_of_tag s) in + let value = (ExtXml.float_attrib s "value") *. (code_unit_coef_of_xml s) in define (prefix^ExtXml.attrib s "name") (string_of_float value); with _ -> define (prefix^ExtXml.attrib s "name") (ExtXml.display_entities (ExtXml.attrib s "value")); diff --git a/tests/LisaL/01_With_b2_v1.2.t b/tests/LisaL/01_With_b2_v1.2.t index 4dc034fdf8..765efcdc26 100644 --- a/tests/LisaL/01_With_b2_v1.2.t +++ b/tests/LisaL/01_With_b2_v1.2.t @@ -40,7 +40,7 @@ ok($server->alive(), "The server process started successfully"); # Start the link process my $link_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/link"; -my @link_options = qw(-d /dev/tty.usbserial-000013FD -s 57600 -transport xbee -xbee_addr 123); +my @link_options = qw(-d /dev/ttyUSB0 -s 57600 -transport xbee -xbee_addr 123); sleep 2; # The service should die in this time if there's an error my $link = Proc::Background->new($link_command, @link_options); ok($link->alive(), "The link process started successfully"); diff --git a/tests/LisaL/02_With_aspirin_v1.5_and_overo.t b/tests/LisaL/02_With_aspirin_v1.5.t similarity index 87% rename from tests/LisaL/02_With_aspirin_v1.5_and_overo.t rename to tests/LisaL/02_With_aspirin_v1.5.t index f03b7cb164..be2db4ebad 100644 --- a/tests/LisaL/02_With_aspirin_v1.5_and_overo.t +++ b/tests/LisaL/02_With_aspirin_v1.5.t @@ -9,18 +9,18 @@ $|++; #################### # Make the airframe -my $make_compile_options = "AIRCRAFT=LisaLv11_Aspirinv15_Overo_RC clean_ac ap.compile"; +my $make_compile_options = "AIRCRAFT=LisaLv11_Aspirinv15_RC clean_ac ap.compile"; my $compile_output = run_program( "Attempting to build the firmware.", $ENV{'PAPARAZZI_SRC'}, "make $make_compile_options", 0,1); -unlike($compile_output, '/Aircraft \'LisaLv11_Aspirinv15_Overo_RC\' not found in/', "The compile output does not contain the message \"Aircraft \'LisaLv11_Aspirinv15_Overo_RC\' not found in\""); +unlike($compile_output, '/Aircraft \'LisaLv11_Aspirinv15_RC\' not found in/', "The compile output does not contain the message \"Aircraft \'LisaLv11_Aspirinv15_RC\' not found in\""); unlike($compile_output, '/\bError\b/i', "The compile output does not contain the word \"Error\""); #################### # Upload the airframe -my $make_upload_options = "AIRCRAFT=LisaLv11_Aspirinv15_Overo_RC BOARD_SERIAL=LISA-L-000154 ap.upload"; +my $make_upload_options = "AIRCRAFT=LisaLv11_Aspirinv15_RC BOARD_SERIAL=LISA-L-000154 ap.upload"; my $upload_output = run_program( "Attempting to build and upload the firmware.", $ENV{'PAPARAZZI_SRC'}, @@ -40,7 +40,7 @@ ok($server->alive(), "The server process started successfully"); # Start the link process my $link_command = "$ENV{'PAPARAZZI_HOME'}/sw/ground_segment/tmtc/link"; -my @link_options = qw(-d /dev/tty.usbserial-000013FD -s 57600 -transport xbee -xbee_addr 123); +my @link_options = qw(-d /dev/ttyUSB0 -s 57600 -transport xbee -xbee_addr 123); sleep 2; # The service should die in this time if there's an error my $link = Proc::Background->new($link_command, @link_options); ok($link->alive(), "The link process started successfully");