<!DOCTYPE airframe SYSTEM "airframe.dtd">

<airframe name="HITL for Olimex">

<!-- commands section -->
  <commands>
	<axis name="THROTTLE" failsafe_value="0"/>
	<axis name="ROLL" failsafe_value="0"/>
	<axis name="PITCH" failsafe_value="0"/>
	<axis name="YAW" failsafe_value="0"/>
  </commands>

  <section name="INFRARED" prefix="IR_">
	<define name="LATERAL_CORRECTION" value="0.75"/>
	<define name="LONGITUDINAL_CORRECTION" value="0.75"/>
	<define name="VERTICAL_CORRECTION" value="1.5"/>

	<define name="ROLL_NEUTRAL_DEFAULT" value="0." unit="deg"/>
	<define name="PITCH_NEUTRAL_DEFAULT" value="2" unit="deg"/>

	<define name="CORRECTION_UP" value="1.0"/>
	<define name="CORRECTION_DOWN" value="1.0"/>
	<define name="CORRECTION_LEFT" value="1.0"/>
	<define name="CORRECTION_RIGHT" value="1.0"/>
  </section>

  <section name="BAT">
	<define name="CATASTROPHIC_BAT_LEVEL" value="0" unit="V"/>
	<define name="LOW_BAT_LEVEL" value="3.5" unit="V"/>
	<define name="CRITIC_BAT_LEVEL" value="4" unit="V"/>
	<define name="MAX_BAT_LEVEL" value="4.3" unit="V"/>
  </section>

  <section name="MISC">
	<define name="NOMINAL_AIRSPEED" value="13." unit="m/s"/>
	<define name="CARROT" value="5." unit="s"/>
	<define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
	<define name="CONTROL_FREQUENCY" value="60" unit="Hz"/>
	<define name="ALT_KALMAN_ENABLED" value="TRUE"/>

	<define name="DEFAULT_CIRCLE_RADIUS" value="80."/>

  </section>

  <section name="VERTICAL CONTROL" prefix="V_CTL_">

	<define name="POWER_CTL_BAT_NOMINAL" value="11.1" unit="volt"/>
	<!-- outer loop proportional gain -->
	<define name="ALTITUDE_PGAIN" value="0.03"/>
	<!-- outer loop saturation -->
	<define name="ALTITUDE_MAX_CLIMB" value="2."/>

	<!-- auto throttle inner loop -->
	<define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.5"/>
	<define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
	<define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.85"/>
	<define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
	<define name="AUTO_THROTTLE_DASH_TRIM" value="-4000"/>
	<define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
	<define name="AUTO_THROTTLE_PGAIN" value="0.01"/>
	<define name="AUTO_THROTTLE_IGAIN" value="0.1"/>
	<define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.05"/>

	<define name="THROTTLE_SLEW_LIMITER" value="2" unit="s"/>
  </section>

  <section name="HORIZONTAL CONTROL" prefix="H_CTL_">
	<define name="COURSE_PGAIN" value="1.10800004005"/>

	<define name="ROLL_MAX_SETPOINT" value="0.6" unit="rad"/>
	<define name="PITCH_MAX_SETPOINT" value="0.5" unit="rad"/>
	<define name="PITCH_MIN_SETPOINT" value="-0.5" unit="rad"/>

	<define name="PITCH_PGAIN" value="15184.5644531"/>
	<define name="PITCH_DGAIN" value="1.5"/>

	<define name="ELEVATOR_OF_ROLL" value="1250"/>

	<define name="ROLL_SLEW" value="0.1"/>

	<define name="ROLL_ATTITUDE_GAIN" value="7500"/>
	<define name="ROLL_RATE_GAIN" value="1500"/>
   </section>

  <section name="NAV">
	<define name="NAV_GLIDE_PITCH_TRIM" value="0"/>
  </section>

  <section name="AGGRESSIVE" prefix="AGR_">
	<define name="BLEND_START" value="20"/><!-- Altitude Error to Initiate Aggressive Climb CANNOT BE ZERO!!-->
	<define name="BLEND_END" value="10"/><!-- Altitude Error to Blend Aggressive to Regular Climb Modes  CANNOT BE ZERO!!-->
	<define name="CLIMB_THROTTLE" value="1.00"/><!-- Gaz for Aggressive Climb -->
	<define name="CLIMB_PITCH" value="0.3"/><!-- Pitch for Aggressive Climb -->
	<define name="DESCENT_THROTTLE" value="0.1"/><!-- Gaz for Aggressive Decent -->
	<define name="DESCENT_PITCH" value="-0.25"/><!-- Pitch for Aggressive Decent -->
	<define name="CLIMB_NAV_RATIO" value="0.8"/><!-- Percent Navigation for Altitude Error Equal to Start Altitude -->
	<define name="DESCENT_NAV_RATIO" value="1.0"/>
	</section>

  <section name="FAILSAFE" prefix="FAILSAFE_">
	<define name="DELAY_WITHOUT_GPS" value="2" unit="s"/>
	<define name="DEFAULT_THROTTLE" value="0.3" unit="%"/>
	<define name="DEFAULT_ROLL" value="0.3" unit="rad"/>
	<define name="DEFAULT_PITCH" value="0.5" unit="rad"/>
  </section>

 <makefile>
CONFIG=\"tiny_2_1_1_usb.h\"
include $(PAPARAZZI_SRC)/conf/firmwares/tiny.makefile

FLASH_MODE=IAP

ap.CFLAGS +=  -DFBW -DAP -DBOARD_CONFIG=$(CONFIG) -DUSE_LED -DTIME_LED=1
ap.srcs = sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c main_fbw.c main_ap.c main.c

ap.srcs += commands.c

# Through USB
ap.CFLAGS += -DDOWNLINK -DDOWNLINK_TRANSPORT=PprzTransport -DUSE_USB_SERIAL
ap.CFLAGS += -DDOWNLINK_FBW_DEVICE=UsbS -DDOWNLINK_AP_DEVICE=UsbS -DPPRZ_UART=UsbS -DDATALINK=PPRZ
ap.srcs += subsystems/datalink/pprz_transport.c

#XBEE ap.CFLAGS += -DDOWNLINK -DDOWNLINK_TRANSPORT=XBeeTransport -DUSE_USB_SERIAL
#XBEE ap.CFLAGS += -DDOWNLINK_FBW_DEVICE=UsbS -DDOWNLINK_AP_DEVICE=UsbS -DXBEE_UART=UsbS -DDATALINK=XBEE
#XBEE ap.srcs += subsystems/datalink/xbee.c


ap.srcs += subsystems/datalink/downlink.c $(SRC_ARCH)/mcu_periph/uart_arch.c $(SRC_ARCH)/usb_ser_hw.c datalink.c
ap.srcs += $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbcontrol.c
ap.srcs += $(SRC_ARCH)/lpcusb/usbstdreq.c $(SRC_ARCH)/lpcusb/usbinit.c

ap.CFLAGS += -DINTER_MCU
ap.srcs += inter_mcu.c

ap.CFLAGS += -DUSE_GPS -DUBX

ap.srcs += gps_ubx.c gps.c latlong.c

ap.CFLAGS += -DUSE_INFRARED
ap.srcs += infrared.c estimator.c

ap.CFLAGS += -DNAV -DAGR_CLIMB -DLOITER_TRIM -DALT_KALMAN -DWIND_INFO
ap.srcs += subsystems/nav.c fw_h_ctl.c fw_v_ctl.c

ap.srcs += subsystems/navigation/nav_line.c subsystems/navigation/nav_survey_rectangle.c

# Configuration for Hardware In The Loop
ap.CFLAGS += -DHITL
ap.CFLAGS += -DGPS_USE_LATLONG # simulating LEA 5H

# Config for SITL simulation
sim.ARCHDIR = $(ARCH)
sim.CFLAGS += -DSITL -DAP -DFBW -DINTER_MCU -DDOWNLINK -DDOWNLINK_TRANSPORT=IvyTransport -DUSE_INFRARED -DNAV -DUSE_LED
sim.srcs = latlong.c subsystems/datalink/downlink.c commands.c gps.c inter_mcu.c infrared.c fw_h_ctl.c fw_v_ctl.c subsystems/nav.c estimator.c sys_time.c main_fbw.c main_ap.c datalink.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 $(SRC_ARCH)/sim_adc_generic.c $(SRC_ARCH)/led_hw.c
sim.CFLAGS += -DBOARD_CONFIG=\"tiny.h\" -DAGR_CLIMB -DLOITER_TRIM -DALT_KALMAN
sim.srcs += subsystems/navigation/nav_survey_rectangle.c subsystems/navigation/nav_line.c subsystems/navigation/traffic_info.c

  </makefile>
</airframe>
