Skip to content

Commit

Permalink
if_calib.[ch] -----> rc_settings.[ch]
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Brisset committed May 17, 2006
1 parent b16a6c4 commit 2a63c57
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Makefile.ac
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $(FLIGHT_PLAN_XML) : $(CONF)/$(FLIGHT_PLAN) $(CONF_XML)
$(Q)$(TOOLS)/gen_flight_plan.out -dump $< > /tmp/fp.xml
$(Q)mv /tmp/fp.xml $@

$(INFLIGHT_CALIB_H) : $(CONF)/$(FLIGHT_PLAN) $(CONF_XML)
$(INFLIGHT_CALIB_H) : $(CONF)/$(FLIGHT_PLAN) $(CONF_XML) $(TOOLS)/gen_calib.out
@echo BUILD $@
$(Q)$(TOOLS)/gen_calib.out $< > /tmp/c.h
$(Q)mv /tmp/c.h $@
Expand Down
2 changes: 1 addition & 1 deletion conf/airframes/flyingtux.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ap.CFLAGS += -DMODEM -DDOWNLINK_AP_DEVICE=Modem
ap.srcs += $(SRC_ARCH)/modem_hw.c

ap.CFLAGS += -DRADIO_CONTROL_CALIB
ap.srcs += if_calib.c
ap.srcs += rc_settings.c

</makefile>
</airframe>
2 changes: 1 addition & 1 deletion conf/airframes/microjet1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ap.CFLAGS += -DMODEM -DDOWNLINK_AP_DEVICE=Modem
ap.srcs += $(SRC_ARCH)/modem_hw.c

ap.CFLAGS += -DRADIO_CONTROL_CALIB
ap.srcs += if_calib.c
ap.srcs += rc_settings.c

# Config for SITL simulation
include $(PAPARAZZI_SRC)/conf/autopilot/sitl.makefile
Expand Down
2 changes: 1 addition & 1 deletion conf/airframes/plaster1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ ap.CFLAGS += -DMODEM -DDOWNLINK_AP_DEVICE=Modem
ap.srcs += $(SRC_ARCH)/modem_hw.c

ap.CFLAGS += -DRADIO_CONTROL_CALIB
ap.srcs += if_calib.c
ap.srcs += rc_settings.c

# Config for SITL simulation
include $(PAPARAZZI_SRC)/conf/autopilot/sitl.makefile
Expand Down
4 changes: 2 additions & 2 deletions conf/airframes/twinstar4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ ap.srcs += pprz_transport.c downlink.c
ap.CFLAGS += -DMODEM -DDOWNLINK_AP_DEVICE=Modem
ap.srcs += $(SRC_ARCH)/modem_hw.c

ap.CFLAGS += -DRADIO_CONTROL_CALIB
ap.srcs += if_calib.c
ap.CFLAGS += -DRADIO_CONTROL_SETTINGS
ap.srcs += rc_settings.c

ap.CFLAGS += -DDATALINK=WAVECARD
ap.srcs += traffic_info.c datalink.c
Expand Down
4 changes: 2 additions & 2 deletions conf/autopilot/sitl.makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ sim.ARCHDIR = $(ARCHI)
sim.ARCH = sitl
sim.TARGET = autopilot
sim.TARGETDIR = autopilot
sim.CFLAGS += -DSITL -DAP -DFBW -DRADIO_CONTROL -DINTER_MCU -DDOWNLINK -DDOWNLINK_TRANSPORT=IvyTransport -DINFRARED -DRADIO_CONTROL_CALIB
sim.srcs = radio_control.c downlink.c commands.c gps.c inter_mcu.c infrared.c pid.c nav.c estimator.c cam.c sys_time.c main_fbw.c main_ap.c if_calib.c $(SRC_ARCH)/ppm_hw.c $(SRC_ARCH)/sim_gps.c $(SRC_ARCH)/sim_ir.c $(SRC_ARCH)/sim_ap.c $(SRC_ARCH)/ivy_transport.c
sim.CFLAGS += -DSITL -DAP -DFBW -DRADIO_CONTROL -DINTER_MCU -DDOWNLINK -DDOWNLINK_TRANSPORT=IvyTransport -DINFRARED -DRADIO_CONTROL_SETTINGS
sim.srcs = radio_control.c downlink.c commands.c gps.c inter_mcu.c infrared.c pid.c nav.c estimator.c cam.c sys_time.c main_fbw.c main_ap.c rc_settings.c $(SRC_ARCH)/ppm_hw.c $(SRC_ARCH)/sim_gps.c $(SRC_ARCH)/sim_ir.c $(SRC_ARCH)/sim_ap.c $(SRC_ARCH)/ivy_transport.c
6 changes: 3 additions & 3 deletions sw/airborne/ap_downlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
DOWNLINK_SEND_ATTITUDE(&phi, &psi, &theta); \
})

#define PERIODIC_SEND_PPRZ_MODE() DOWNLINK_SEND_PPRZ_MODE(&pprz_mode, &vertical_mode, &lateral_mode, &horizontal_mode, &inflight_calib_mode, &mcu1_status, &ir_estim_mode);
#define PERIODIC_SEND_PPRZ_MODE() DOWNLINK_SEND_PPRZ_MODE(&pprz_mode, &vertical_mode, &lateral_mode, &horizontal_mode, &rc_settings_mode, &mcu1_status, &ir_estim_mode);
#define PERIODIC_SEND_DESIRED() DOWNLINK_SEND_DESIRED(&desired_roll, &desired_pitch, &desired_x, &desired_y, &desired_altitude, &desired_climb);

#define PERIODIC_SEND_NAVIGATION_REF() DOWNLINK_SEND_NAVIGATION_REF(&nav_utm_east0, &nav_utm_north0, &nav_utm_zone0);
Expand Down Expand Up @@ -96,8 +96,8 @@
} \
}

#ifdef RADIO_CONTROL_CALIB
#define PERIODIC_SEND_SETTINGS() if (inflight_calib_mode != IF_CALIB_MODE_NONE) DOWNLINK_SEND_SETTINGS(&slider_1_val, &slider_2_val);
#ifdef RADIO_CONTROL_SETTINGS
#define PERIODIC_SEND_SETTINGS() if (!RcSettingsOff()) DOWNLINK_SEND_SETTINGS(&slider_1_val, &slider_2_val);
#else
#define PERIODIC_SEND_SETTINGS() {}
#endif
Expand Down
10 changes: 5 additions & 5 deletions sw/airborne/autopilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ extern float slider_1_val, slider_2_val;

extern bool_t launch;


#define ModeUpdate(_mode, _value) { \
/** Assignment, returning _old_value != _value
* Using GCC expression statements */
#define ModeUpdate(_mode, _value) ({ \
uint8_t new_mode = _value; \
if (_mode != new_mode) { _mode = new_mode; return TRUE; } \
return FALSE; \
}
(_mode != new_mode ? _mode = new_mode, TRUE : FALSE); \
})

#define CheckEvent(_event) (_event ? _event = FALSE, TRUE : FALSE)

Expand Down
17 changes: 0 additions & 17 deletions sw/airborne/if_calib.h

This file was deleted.

40 changes: 13 additions & 27 deletions sw/airborne/main_ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "nav.h"
#include "autopilot.h"
#include "estimator.h"
#include "if_calib.h"
#include "rc_settings.h"
#include "cam.h"
#include "traffic_info.h"
#include "link_mcu.h"
Expand All @@ -64,7 +64,8 @@
#define LOW_BATTERY_DECIVOLT (LOW_BATTERY*10)


uint8_t inflight_calib_mode = IF_CALIB_MODE_NONE;
/** FIXME: should be in rc_settings but required by telemetry (ap_downlink.h)*/
uint8_t rc_settings_mode = RC_SETTINGS_MODE_NONE;


/** Define minimal speed for takeoff in m/s */
Expand Down Expand Up @@ -108,7 +109,7 @@ static inline uint8_t pprz_mode_update( void ) {
if ((pprz_mode != PPRZ_MODE_HOME &&
pprz_mode != PPRZ_MODE_GPS_OUT_OF_ORDER)
|| CheckEvent(rc_event_1)) {
ModeUpdate(pprz_mode, PPRZ_MODE_OF_PULSE(fbw_state->channels[RADIO_MODE], fbw_state->status));
return ModeUpdate(pprz_mode, PPRZ_MODE_OF_PULSE(fbw_state->channels[RADIO_MODE], fbw_state->status));
} else
return FALSE;
}
Expand All @@ -118,7 +119,7 @@ static inline uint8_t pprz_mode_update( void ) {
* \brief update ir estimation if RADIO_LLS is true \n
*/
inline uint8_t ir_estim_mode_update( void ) {
ModeUpdate(ir_estim_mode, IR_ESTIM_MODE_OF_PULSE(fbw_state->channels[RADIO_LLS]));
return ModeUpdate(ir_estim_mode, IR_ESTIM_MODE_OF_PULSE(fbw_state->channels[RADIO_LLS]));
}
#endif

Expand All @@ -133,12 +134,9 @@ static inline uint8_t mcu1_status_update( void ) {
return FALSE;
}

/** Delay between @@@@@ A FIXER @@@@@ */
/** Minimum delay before an event is enabled */
#define EVENT_DELAY 20

/** \def EventUpdate(_cpt, _cond, _event)
* @@@@@ A FIXER @@@@@
*/
#define EventUpdate(_cpt, _cond, _event) \
if (_cond) { \
if (_cpt < EVENT_DELAY) { \
Expand All @@ -151,26 +149,14 @@ static inline uint8_t mcu1_status_update( void ) {
}


#if defined RADIO_CALIB && defined RADIO_CONTROL_CALIB
static inline uint8_t inflight_calib_mode_update ( void ) {
ModeUpdate(inflight_calib_mode, IF_CALIB_MODE_OF_PULSE(fbw_state->channels[RADIO_CALIB]));
}
#define EventPos(_cpt, _channel, _event) \
EventUpdate(_cpt, (inflight_calib_mode==IF_CALIB_MODE_NONE && fbw_state->channels[_channel]>(int)(0.75*MAX_PPRZ)), _event)

#define EventNeg(_cpt, _channel, _event) \
EventUpdate(_cpt, (inflight_calib_mode==IF_CALIB_MODE_NONE && fbw_state->channels[_channel]<(int)(-0.75*MAX_PPRZ)), _event)

#else // RADIO_CALIB && defined RADIO_CONTROL_CALIB
#define Event(_cpt, _channel, _event, _cond) \
EventUpdate(_cpt, (RcSettingsOff() && fbw_state->channels[_channel] _cond), _event)

#define EventPos(_cpt, _channel, _event) \
EventUpdate(_cpt, (fbw_state->channels[_channel]>(int)(0.75*MAX_PPRZ)), _event)
Event(_cpt, _channel, _event, >(int)(0.75*MAX_PPRZ))

#define EventNeg(_cpt, _channel, _event) \
EventUpdate(_cpt, (fbw_state->channels[_channel]<(int)(-0.75*MAX_PPRZ)), _event)

#endif // RADIO_CALIB && defined RADIO_CONTROL_CALIB

Event(_cpt, _channel, _event, <(int)(-0.75*MAX_PPRZ))



Expand Down Expand Up @@ -235,9 +221,9 @@ inline void telecommand_task( void ) {
#ifdef RADIO_LLS
mode_changed |= ir_estim_mode_update();
#endif
#if defined RADIO_CALIB && defined RADIO_CONTROL_CALIB
bool_t calib_mode_changed = inflight_calib_mode_update();
inflight_calib(calib_mode_changed || pprz_mode_changed);
#if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
bool_t calib_mode_changed = RcSettingsModeUpdate(fbw_state->channels);
rc_settings(calib_mode_changed || pprz_mode_changed);
mode_changed |= calib_mode_changed;
#endif
}
Expand Down
7 changes: 2 additions & 5 deletions sw/airborne/if_calib.c → sw/airborne/rc_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@


#include <inttypes.h>
#include "rc_settings.h"
#include "radio.h"
#include "autopilot.h"
#include "if_calib.h"
#include "infrared.h"
#include "pid.h"
#include "nav.h"
#include "estimator.h"


#define ParamValInt16(param_init_val, param_travel, cur_pulse, init_pulse) \
Expand All @@ -39,10 +40,6 @@
#define ParamValFloat(param_init_val, param_travel, cur_pulse, init_pulse) \
(param_init_val + ((float)(cur_pulse - init_pulse)) * param_travel / (float)MAX_PPRZ)



#include "estimator.h"

#define RcChannel(x) (fbw_state->channels[x])

/** Includes generated code from airframe.xml */
Expand Down
43 changes: 43 additions & 0 deletions sw/airborne/rc_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** \file rc_settings.h
* \brief Variable setting though the radio control
*
* The <rc_control> section of a XML flight plan allows the user to change the
* value of an autopilot internal variable through the rc transmitter.
* C code is generated from this XML code (var/AC/inflight_calib.h). This
* module handles the control of this setting mode.
*
* Note that this functionnality is deprecated since datalink use is a lot more
* easier (<dl_settings> section)
*/

#ifndef RC_SETTINGS_H

#include "std.h"
#include "radio.h"

#define RC_SETTINGS_MODE_NONE 0
#define RC_SETTINGS_MODE_DOWN 1
#define RC_SETTINGS_MODE_UP 2

#if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS

#define RcSettingsOff() (rc_settings_mode==RC_SETTINGS_MODE_NONE)

#define RC_SETTINGS_MODE_OF_PULSE(pprz) (pprz < TRESHOLD1 ? RC_SETTINGS_MODE_UP : \
(pprz < TRESHOLD2 ? RC_SETTINGS_MODE_NONE : \
RC_SETTINGS_MODE_DOWN))

#define RcSettingsModeUpdate(_rc_channels) \
ModeUpdate(rc_settings_mode, RC_SETTINGS_MODE_OF_PULSE(_rc_channels[RADIO_CALIB]))

extern uint8_t rc_settings_mode;
void rc_settings(bool_t mode_changed);


#else /* RADIO_CALIB && defined RADIO_CONTROL_SETTINGS */

#define RcSettingsOff() TRUE

#endif /* ! (RADIO_CALIB && defined RADIO_CONTROL_SETTINGS) */

#endif // RC_SETTINGS_H
6 changes: 3 additions & 3 deletions sw/tools/gen_calib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* XML preprocessing for in flight calibration
*
* Copyright (C) 2003 Pascal Brisset, Antoine Drouin
* Copyright (C) 2003-2006 Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
Expand Down Expand Up @@ -60,7 +60,7 @@ let parse_setting = fun xml ->
let param_macro = param_macro_of_type t in
let var_init = var ^ "_init" in

lprintf "if (inflight_calib_mode == IF_CALIB_MODE_%s) {\n" (String.uppercase cm);
lprintf "if (rc_settings_mode == RC_SETTINGS_MODE_%s) {\n" (String.uppercase cm);
right ();
lprintf "static %s %s;\n" (inttype t) var_init;
lprintf "static int16_t slider%d_init;\n" cursor;
Expand Down Expand Up @@ -93,7 +93,7 @@ let _ =
let xml = start_and_begin xml_file h_name in

let rc_control = try ExtXml.child xml "rc_control" with Not_found -> failwith (sprintf "Error: 'rc_control' child expected in %s" (Xml.to_string xml)) in
lprintf "void inflight_calib(bool_t mode_changed) {\n";
lprintf "void rc_settings(bool_t mode_changed) {\n";
right ();
parse_modes rc_control;
left (); lprintf "}\n";
Expand Down

0 comments on commit 2a63c57

Please sign in to comment.