diff --git a/conf/airframes/twinstar2.xml b/conf/airframes/twinstar2.xml index 3e8bd4e91a..0f231a5897 100644 --- a/conf/airframes/twinstar2.xml +++ b/conf/airframes/twinstar2.xml @@ -18,8 +18,6 @@ - - diff --git a/sw/airborne/autopilot.h b/sw/airborne/autopilot.h index ba7948b8bd..c1bcd69f73 100644 --- a/sw/airborne/autopilot.h +++ b/sw/airborne/autopilot.h @@ -38,7 +38,7 @@ #define TRESHOLD_MANUAL_PPRZ (MIN_PPRZ / 2) #define TRESHOLD1 TRESHOLD_MANUAL_PPRZ -#define TRESHOLD2 SYS_TICS_OF_USEC(200) +#define TRESHOLD2 (MAX_PPRZ/2) #define PPRZ_MODE_MANUAL 0 @@ -49,7 +49,7 @@ #define PPRZ_MODE_NB 5 #define PPRZ_MODE_OF_PULSE(pprz, mega8_status) \ - ((uint16_t)pprz > TRESHOLD2 ? PPRZ_MODE_AUTO2 : \ + (pprz > TRESHOLD2 ? PPRZ_MODE_AUTO2 : \ (pprz > TRESHOLD1 ? PPRZ_MODE_AUTO1 : PPRZ_MODE_MANUAL)) extern uint8_t pprz_mode; diff --git a/sw/simulator/Makefile b/sw/simulator/Makefile index b8fcceee15..66f3a5b38e 100644 --- a/sw/simulator/Makefile +++ b/sw/simulator/Makefile @@ -32,7 +32,7 @@ SIMHCMO=$(SIMHML:%.ml=%.cmo) SIMSML = stdlib.ml data.ml flightModel.ml gps.ml sitl.ml sim.ml SIMSCMO=$(SIMSML:%.ml=%.cmo) SIMSCMX=$(SIMSML:%.ml=%.cmx) -SIMSC = sim_ir.c sim_gps.c sim_ap.c sys_time.c estimator.c infrared.c gps.c pid.c nav.c main_ap.c cam.c traffic_info.c +SIMSC = sim_ir.c sim_gps.c sim_ap.c sys_time.c estimator.c infrared.c gps.c pid.c nav.c radio_control.c main_ap.c cam.c traffic_info.c SIMSO=$(SIMSC:%.c=$(OBJDIR)/%.o) SIMSA=sims.cma diff --git a/sw/simulator/sim_ap.c b/sw/simulator/sim_ap.c index fa56818530..52bf2b3dfa 100644 --- a/sw/simulator/sim_ap.c +++ b/sw/simulator/sim_ap.c @@ -32,7 +32,7 @@ struct inter_mcu_msg from_fbw, from_ap; static int16_t values_from_ap[RADIO_CTL_NB]; -void inflight_calib(void) { } +uint16_t ppm_pulses[ PPM_NB_PULSES ]; /** From ppm_hw.c */ value sim_periodic_task(value _unit) { periodic_task(); @@ -55,6 +55,12 @@ value set_really_lost(value on) { } value sim_rc_task(value _unit) { + NormalizePpm(); /** -> rc_values */ + /*** printf("update: %d : %f (%d)\n", Int_val(c), Double_val(v), rc_values[COMMAND_GAIN1]); ***/ + int i; + for(i = 0; i < COMMANDS_NB; i++) + from_fbw.channels[i] = rc_values[i]; + from_fbw.status = (radio_status << STATUS_RADIO_OK) | (radio_really_lost << RADIO_REALLY_LOST) | (1 << AVERAGED_CHANNELS_SENT); link_fbw_receive_valid = TRUE; telecommand_task(); @@ -83,7 +89,7 @@ value update_bat(value bat) { } value update_rc_channel(value c, value v) { - from_fbw.channels[Int_val(c)] = Double_val(v)*MAX_PPRZ; + ppm_pulses[Int_val(c)] = Double_val(v); return Val_unit; } @@ -107,6 +113,7 @@ value set_servos(value servos) { /** Get values computed by the autopilot */ for(i = 0; i < RADIO_CTL_NB; i++) { values_from_ap[i] = US_OF_CLOCK(from_ap.channels[i]); + /***printf("%d:%d\n", i, values_from_ap[i]); ***/ } diff --git a/sw/simulator/sitl.ml b/sw/simulator/sitl.ml index c1609e3878..e36a39ccc1 100644 --- a/sw/simulator/sitl.ml +++ b/sw/simulator/sitl.ml @@ -85,15 +85,21 @@ module Make(A:Data.MISSION) = struct let vbox = GPack.vbox ~height:10 ~spacing: 1 ~border_width: 1 ~packing:window#add () in let on_off = GButton.check_button ~label:"On" ~active:true ~packing:vbox#pack () in let sliders = GPack.vbox ~packing:vbox#add () in + let float_attrib = fun a x -> float_of_string (ExtXml.attrib x a) in Array.iteri (fun i c -> - let adj = GData.adjustment ~value:0. ~lower:(-100.) ~upper:110. ~step_incr:1.0 () in + let mi = float_attrib "min" c + and ma = float_attrib "max" c + and value = float_attrib "neutral" c in + let lower = min mi ma + and upper = max mi ma in + let adj = GData.adjustment ~value ~lower ~upper ~step_incr:1.0 () in let hbox = GPack.hbox ~packing:sliders#add () in let f = (ExtXml.attrib c "function") in let l = GMisc.label ~width:75 ~text:f ~packing:hbox#pack () in - let inv = List.mem f inverted in + let inv = not ((List.mem f inverted) == (ma < mi)) in let _scale = GRange.scale `HORIZONTAL ~inverted:inv ~adjustment:adj ~packing:hbox#add () in - let update = fun () -> update_channel i (adj#value /. 100.) in + let update = fun () -> update_channel i adj#value in ignore (adj#connect#value_changed update); update ()) diff --git a/sw/simulator/sys_time_hw.h b/sw/simulator/sys_time_hw.h index a193503ec7..e9480b55ef 100644 --- a/sw/simulator/sys_time_hw.h +++ b/sw/simulator/sys_time_hw.h @@ -1,3 +1,4 @@ -#define SYS_TICS_OF_USEC(x) (x) -#define US_OF_CLOCK(x) (x) +#define SYS_TICS_OF_USEC(x) ((x)) +#define SIGNED_SYS_TICS_OF_USEC(x) ((x)) +#define US_OF_CLOCK(x) ((x)) #define SERVOS_TICS_OF_USEC(s) SYS_TICS_OF_USEC(s)