Skip to content

Commit

Permalink
[modules] add baro_sim
Browse files Browse the repository at this point in the history
as a temporary workaround to get baro simulation in ocaml sim
  • Loading branch information
flixr committed Oct 8, 2013
1 parent 1734b1d commit 3c4f223
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 4 deletions.
1 change: 1 addition & 0 deletions conf/airframes/examples/Twinstar_energyadaptive.xml
Expand Up @@ -54,6 +54,7 @@ twog_1.0 + aspirin + ETS baro + ETS speed
<define name="BARO_ETS_ALT_SCALE" value="0.3"/>
<define name="BARO_ETS_SYNC_SEND"/>
</load>
<load name="baro_sim.xml"/>
<load name="digital_cam.xml">
<define name="DC_SHUTTER_LED" value="5"/><!-- led4:aux led5:camsw-->
</load>
Expand Down
5 changes: 3 additions & 2 deletions conf/firmwares/subsystems/shared/baro_board.makefile
Expand Up @@ -125,8 +125,9 @@ endif
#
# add it for simulators
#
sim.srcs += $(SRC_BOARD)/baro_board.c
jsbsim.srcs += $(SRC_BOARD)/baro_board.c
# only NPS for now...
#sim.srcs += $(SRC_BOARD)/baro_board.c
#jsbsim.srcs += $(SRC_BOARD)/baro_board.c
nps.srcs += $(SRC_BOARD)/baro_board.c


Expand Down
22 changes: 22 additions & 0 deletions conf/modules/baro_sim.xml
@@ -0,0 +1,22 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="baro_sim" dir="sensors">
<doc>
<description>
Simulated barometer.
Sends the BARO_ABS ABI message with gps.hmsl converted to absolute pressure.
</description>
</doc>

<header>
<file name="baro_sim.h"/>
</header>
<init fun="baro_sim_init()"/>
<periodic fun="baro_sim_periodic()" freq="10."/>

<makefile target="sim|jsbsim">
<file name="baro_sim.c"/>
<define name="USE_BARO_BOARD" value="FALSE"/>
</makefile>

</module>
3 changes: 2 additions & 1 deletion sw/airborne/boards/pc_sim.h
Expand Up @@ -11,7 +11,8 @@

#define DefaultVoltageOfAdc(adc) (1.0*adc)


#ifndef USE_BARO_BOARD
#define USE_BARO_BOARD 1
#endif

#endif /* CONFIG_PC_SIM_H */
44 changes: 44 additions & 0 deletions sw/airborne/modules/sensors/baro_sim.c
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/

/**
* @file baro_sim.c
*
* Simulate barometer pressure measurement using gps.hmsl
*/

#include "math/pprz_isa.h"
#include "subsystems/gps.h"
#include "subsystems/abi.h"

#ifndef BARO_SIM_SENDER_ID
#define BARO_SIM_SENDER_ID 1
#endif
PRINT_CONFIG_VAR(BARO_SIM_SENDER_ID)

void baro_sim_init(void) {

}

void baro_sim_periodic(void) {
float pressure = pprz_isa_pressure_of_altitude(gps.hmsl / 1000.0);
AbiSendMsgBARO_ABS(BARO_SIM_SENDER_ID, &pressure);
}
37 changes: 37 additions & 0 deletions sw/airborne/modules/sensors/baro_sim.h
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/

/**
* @file baro_sim.h
*
* Simulate barometer pressure measurement using gps.hmsl
*/

#ifndef BARO_SIM_H
#define BARO_SIM_H

/// new measurement every baro_sim_periodic
#define BARO_SIM_DT BARO_SIM_PERIODIC_PERIOD

extern void baro_sim_init(void);
extern void baro_sim_periodic(void);

#endif
6 changes: 5 additions & 1 deletion sw/airborne/subsystems/ins/ins_alt_float.c
Expand Up @@ -193,7 +193,11 @@ void alt_kalman(float z_meas) {
float SIGMA2;

#if USE_BAROMETER
#if USE_BARO_MS5534A
#ifdef SITL
DT = BARO_SIM_DT;
R = 0.5;
SIGMA2 = 0.1;
#elif USE_BARO_MS5534A
if (alt_baro_enabled) {
DT = BARO_DT;
R = baro_MS5534A_r;
Expand Down

0 comments on commit 3c4f223

Please sign in to comment.