Skip to content

Commit

Permalink
rotorcraft: handle_periodic_tasks to check all sys_time timer
Browse files Browse the repository at this point in the history
- nps: use new systime
- nps: renamed nps_autopilot_booz to nps_autopilot_rotorcraft
  • Loading branch information
flixr committed Feb 13, 2012
1 parent cc07ac8 commit ef76c8a
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 32 deletions.
7 changes: 1 addition & 6 deletions conf/Makefile.sim
Expand Up @@ -56,16 +56,11 @@ CFLAGS += $(INCLUDES)
CFLAGS += $($(TARGET).CFLAGS)
CFLAGS += $(LOCAL_CFLAGS)
CFLAGS += -O2
CFLAGS += -std=gnu99

# meschach prototypes trigger numerous warnings
ifneq ($(SIM_TYPE),BOOZ)
ifneq ($(SIM_TYPE),JSBSIM)
CFLAGS += -Wstrict-prototypes
endif
CFLAGS += -std=gnu99
endif


LDFLAGS = -lm

ifeq ($(SIM_TYPE),BOOZ)
Expand Down
4 changes: 2 additions & 2 deletions conf/autopilot/rotorcraft.makefile
Expand Up @@ -50,7 +50,7 @@ ap.srcs += $(SRC_ARCH)/mcu_arch.c
#
# Math functions
#
$(TARGET).srcs += math/pprz_geodetic_int.c math/pprz_geodetic_float.c math/pprz_geodetic_double.c math/pprz_trig_int.c
ap.srcs += math/pprz_geodetic_int.c math/pprz_geodetic_float.c math/pprz_geodetic_double.c math/pprz_trig_int.c

ifeq ($(ARCH), stm32)
ap.srcs += lisa/plug_sys.c
Expand All @@ -77,7 +77,7 @@ endif
ifndef PERIODIC_FREQUENCY
PERIODIC_FREQUENCY = 512
endif
$(TARGET).CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
ap.CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
#
# Systime
#
Expand Down
8 changes: 4 additions & 4 deletions conf/autopilot/subsystems/rotorcraft/fdm_nps.makefile
Expand Up @@ -51,7 +51,7 @@ sim.srcs += $(NPSDIR)/nps_main.c \
$(NPSDIR)/nps_radio_control.c \
$(NPSDIR)/nps_radio_control_joystick.c \
$(NPSDIR)/nps_radio_control_spektrum.c \
$(NPSDIR)/nps_autopilot_booz.c \
$(NPSDIR)/nps_autopilot_rotorcraft.c \
$(NPSDIR)/nps_ivy.c \
$(NPSDIR)/nps_flightgear.c \

Expand All @@ -68,7 +68,7 @@ ifeq ($(TARGET), sim)
endif


sim.CFLAGS += -DPERIODIC_FREQUENCY='512.'
sim.CFLAGS += -DPERIODIC_FREQUENCY=512
#sim.CFLAGS += -DUSE_LED
sim.srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c

Expand All @@ -85,9 +85,9 @@ sim.srcs += $(SRC_FIRMWARE)/commands.c
sim.srcs += $(SRC_FIRMWARE)/datalink.c

#
# Math functions
#
#

sim.srcs += math/pprz_geodetic_int.c math/pprz_geodetic_float.c math/pprz_geodetic_double.c math/pprz_trig_int.c

sim.CFLAGS += -DROTORCRAFT_BARO_LED=2
sim.srcs += $(SRC_BOARD)/baro_board.c
Expand Down
2 changes: 1 addition & 1 deletion conf/settings/settings_booz2_sim.xml
Expand Up @@ -4,7 +4,7 @@
<dl_settings>

<dl_settings NAME="Sim">
<dl_setting var="nps_bypass_ahrs" min="0" step="1" max="1" module="nps/nps_autopilot_booz" shortname="bypass_ahrs" values="No|Yes"/>
<dl_setting var="nps_bypass_ahrs" min="0" step="1" max="1" module="nps/nps_autopilot_rotorcraft" shortname="bypass_ahrs" values="No|Yes"/>
</dl_settings>

</dl_settings>
Expand Down
31 changes: 17 additions & 14 deletions sw/airborne/firmwares/rotorcraft/main.c
Expand Up @@ -58,7 +58,7 @@
#include "firmwares/rotorcraft/main.h"

#ifdef SITL
#include "nps_autopilot_booz.h"
#include "nps_autopilot_rotorcraft.h"
#endif

#include "generated/modules.h"
Expand All @@ -70,7 +70,6 @@ static inline void on_baro_dif_event( void );
static inline void on_gps_event( void );
static inline void on_mag_event( void );

#ifndef SITL

tid_t main_periodic_tid; ///< id for main_periodic() timer
tid_t failsafe_tid; ///< id for failsafe_check() timer
Expand All @@ -79,22 +78,12 @@ tid_t electrical_tid; ///< id for electrical_periodic() timer
tid_t baro_tid; ///< id for baro_periodic() timer
tid_t telemetry_tid; ///< id for telemetry_periodic() timer

#ifndef SITL
int main( void ) {
main_init();

while(1) {
if (sys_time_check_and_ack_timer(main_periodic_tid))
main_periodic();
if (sys_time_check_and_ack_timer(radio_control_tid))
radio_control_periodic_task();
if (sys_time_check_and_ack_timer(failsafe_tid))
failsafe_check();
if (sys_time_check_and_ack_timer(electrical_tid))
electrical_periodic();
if (sys_time_check_and_ack_timer(baro_tid))
baro_periodic();
if (sys_time_check_and_ack_timer(telemetry_tid))
telemetry_periodic();
handle_periodic_tasks();
main_event();
}
return 0;
Expand Down Expand Up @@ -146,6 +135,20 @@ STATIC_INLINE void main_init( void ) {
telemetry_tid = sys_time_register_timer((1./60.), NULL);
}

STATIC_INLINE void handle_periodic_tasks( void ) {
if (sys_time_check_and_ack_timer(main_periodic_tid))
main_periodic();
if (sys_time_check_and_ack_timer(radio_control_tid))
radio_control_periodic_task();
if (sys_time_check_and_ack_timer(failsafe_tid))
failsafe_check();
if (sys_time_check_and_ack_timer(electrical_tid))
electrical_periodic();
if (sys_time_check_and_ack_timer(baro_tid))
baro_periodic();
if (sys_time_check_and_ack_timer(telemetry_tid))
telemetry_periodic();
}

STATIC_INLINE void main_periodic( void ) {

Expand Down
3 changes: 2 additions & 1 deletion sw/airborne/firmwares/rotorcraft/main.h
Expand Up @@ -31,9 +31,10 @@
#endif

STATIC_INLINE void main_init( void );
STATIC_INLINE void main_periodic( void );
STATIC_INLINE void main_event( void );
STATIC_INLINE void handle_periodic_tasks( void );

STATIC_INLINE void main_periodic( void );
STATIC_INLINE void telemetry_periodic(void);
STATIC_INLINE void failsafe_check( void );

Expand Down
1 change: 1 addition & 0 deletions sw/simulator/nps/nps_autopilot.h
Expand Up @@ -13,6 +13,7 @@ extern struct NpsAutopilot autopilot;

extern void nps_autopilot_init(enum NpsRadioControlType type, int num_script, char* js_dev);
extern void nps_autopilot_run_step(double time);
extern void nps_autopilot_run_systime_step(void);

#endif /* NPS_AUTOPILOT_H */

Expand Down
@@ -1,4 +1,4 @@
#include "nps_autopilot_booz.h"
#include "nps_autopilot_rotorcraft.h"

#include "firmwares/rotorcraft/main.h"
#include "nps_sensors.h"
Expand All @@ -8,6 +8,7 @@
#include "subsystems/sensors/baro.h"
#include "baro_board.h"
#include "subsystems/electrical.h"
#include "mcu_periph/sys_time.h"

#include "actuators/supervision.h"

Expand All @@ -32,6 +33,10 @@ void nps_autopilot_init(enum NpsRadioControlType type_rc, int num_rc_script, cha

}

void nps_autopilot_run_systime_step( void ) {
sys_tick_handler();
}

#include <stdio.h>
#include "subsystems/gps.h"

Expand Down Expand Up @@ -66,7 +71,7 @@ void nps_autopilot_run_step(double time __attribute__ ((unused))) {
sim_overwrite_ahrs();
}

main_periodic();
handle_periodic_tasks();

if (time < 8) { /* start with a little bit of hovering */
int32_t init_cmd[4];
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions sw/simulator/nps/nps_main.c
Expand Up @@ -54,7 +54,7 @@ void cont_hdl (int n __attribute__ ((unused))) {
printf("Press <enter> to continue.\n");
}

double time_to_double(timeval *t) {
double time_to_double(struct timeval *t) {
return ((double)t->tv_sec + (double)(t->tv_usec * 1e-6));
}

Expand All @@ -80,7 +80,7 @@ static void nps_main_init(void) {

nps_main.sim_time = 0.;
nps_main.display_time = 0.;
timeval t;
struct timeval t;
gettimeofday (&t, NULL);
nps_main.scaled_initial_time = time_to_double(&t);
nps_main.host_time_factor = HOST_TIME_FACTOR;
Expand Down Expand Up @@ -114,6 +114,8 @@ static void nps_main_init(void) {
static void nps_main_run_sim_step(void) {
// printf("sim at %f\n", nps_main.sim_time);

nps_autopilot_run_systime_step();

nps_fdm_run_step(autopilot.commands);

nps_sensors_run_step(nps_main.sim_time);
Expand Down

0 comments on commit ef76c8a

Please sign in to comment.