<airframe name="TwistedLogic">

  <servos>
    <servo name="AILERON"  no="2" min="900" neutral="1500" max="2100"/>
    <servo name="ELEVATOR" no="1" min="900" neutral="1500" max="2100"/>
    <servo name="MOTOR_RIGHT"   no="6" min="1250" neutral="1250" max="1810"/>

    <servo name="MOTOR_LEFT"   no="3" min="1250" neutral="1250" max="1810"/>
    <servo name="CAM" no="0" min="900" neutral="1500" max="2100"/>
   </servos>

  <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"/>
    <axis name="CAM"    failsafe_value="0"/>
   </commands>

  <command_laws>
          <let var="roll"     value="1.0 * @ROLL"/>
          <let var="pitch"    value="1.0 * @PITCH"/>
          <let var="yaw"      value="1.0 * @YAW"/>
          <let var="throttle" value="1.0 * @THROTTLE"/>
          <let var="right" value="$throttle + $yaw"/><!-- add trim term for Right -->
          <let var="left" value="$throttle - $yaw"/><!-- .06*thrsubtract trim term for Right -->
          <set servo="AILERON" value="$roll"/>
          <set servo="ELEVATOR"  value="$pitch"/>
          <set servo="MOTOR_LEFT"  value="$left - Max(0, $right - MAX_PPRZ)"/>
          <set servo="MOTOR_RIGHT" value="$right - Max(0, $left - MAX_PPRZ)"/>
          <set servo="CAM" value="@CAM"/>
   </command_laws>

  <rc_commands>
    <set command="THROTTLE" value="@THROTTLE"/>
    <set command="ROLL" value="@ROLL"/>
    <set command="PITCH" value="@PITCH"/>
    <set command="YAW" value="@YAW"/>
    <set command="CAM"    value="@GAIN1"/>
   </rc_commands>


  <section name="MICROMAG">

    <define name="MM_SS_PIN" value="20"/>
    <define name="MM_SS_IODIR" value="IO0DIR"/>
    <define name="MM_SS_IOSET" value="IO0SET"/>
    <define name="MM_SS_IOCLR" value="IO0CLR"/>

    <define name="MM_RESET_PIN" value="29"/>
    <define name="MM_RESET_IODIR" value="IO0DIR"/>
    <define name="MM_RESET_IOSET" value="IO0SET"/>
    <define name="MM_RESET_IOCLR" value="IO0CLR"/>

    <define name="MM_DRDY_PINSEL" value="PINSEL1"/>
    <define name="MM_DRDY_PINSEL_BIT" value="28"/>
    <define name="MM_DRDY_PINSEL_VAL" value="2"/>
    <define name="MM_DRDY_EINT" value="3"/>
    <define name="MM_DRDY_VIC_IT" value="VIC_EINT3"/>

  </section>

  <section name="BARO">
    <define name="TL_BARO_W1" value="0xABDC"/>
    <define name="TL_BARO_W2" value="0x849A"/>
    <define name="TL_BARO_W3" value="0X939E"/>
    <define name="TL_BARO_W4" value="0xB259"/>
  </section>



  <section name="horizontal_control">
    <define name="NAV_GOTO_H_PGAIN" value="-1000" unit="pprz/m"/>
    <define name="NAV_GOTO_H_DGAIN" value="-500" unit="pprz/m/s"/>
  </section>


  <makefile>
ARCHI=arm7
TL=coaxial

FLASH_MODE = IAP

ap.ARCHDIR = $(ARCHI)

ap.CFLAGS += -DBOARD_CONFIG=\"tiny_1_1.h\" -DPERIODIC_TASK_PERIOD='CPU_TICKS_OF_SEC(16.666e-3)' -I$(TL)
ap.srcs = $(TL)/tl_main.c sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c

ap.CFLAGS += -DUSE_LED  -DUSE_LED -DTIME_LED=1

ap.CFLAGS += -DADC
ap.srcs += $(SRC_ARCH)/adc_hw.c $(TL)/tl_bat.c

ap.srcs += commands.c

ap.CFLAGS += -DACTUATORS=\"servos_4015_MAT_hw.h\" -DSERVOS_4015_MAT
ap.srcs += $(SRC_ARCH)/servos_4015_MAT_hw.c actuators.c

ap.CFLAGS += -DRADIO_CONTROL
ap.srcs += radio_control.c $(SRC_ARCH)/ppm_hw.c

# transparent
ap.CFLAGS += -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_AP_DEVICE=Uart0 -DPPRZ_UART=Uart0 -DDATALINK=PPRZ -DUART0_BAUD=B57600
ap.srcs += subsystems/datalink/downlink.c $(SRC_ARCH)/mcu_periph/uart_arch.c subsystems/datalink/pprz_transport.c $(TL)/tl_telemetry.c datalink.c

ap.CFLAGS += -DTL_AP_MODE_AUTO=TL_AP_MODE_NAV -DDT_VFILTER="(1./60.)"
ap.srcs += $(TL)/tl_autopilot.c $(TL)/tl_control.c $(TL)/tl_estimator.c $(TL)/tl_vfilter.c

ap.CFLAGS += -DUSE_GPS -DUBX -DUSE_UART1 -DGPS_LINK=Uart1 -DUART1_BAUD=B38400 -DDOWNLINK_GPS_DEVICE=DOWNLINK_AP_DEVICE -DGPS_CONFIGURE -DUSER_GPS_CONFIGURE=\"$(TL)/tl_gps_configure.h\" -DGPS_BAUD=38400
ap.srcs += gps_ubx.c gps.c latlong.c

ap.srcs += $(TL)/tl_imu.c

ap.CFLAGS += -DADC -DUSE_ADC_5 -DADC_CHANNEL_GR=ADC_5 -DUSE_ADC_6 -DADC_CHANNEL_RM=ADC_6 -DUSE_ADC_7 -DADC_CHANNEL_ACCEL=ADC_7

ap.srcs += $(TL)/tl_baro.c

ap.srcs += micromag.c $(SRC_ARCH)/micromag_hw.c

ap.CFLAGS += -DNAV
ap.srcs += subsystems/navigation/common_nav.c $(TL)/tl_nav.c


#ap.CFLAGS += -D TL_BARO_W1=0xABDC -D TL_BARO_W2=0x849A -D TL_BARO_W3=0X939E -D TL_BARO_W4=0xB259


#
#
#

tmm.ARCHDIR = $(ARCHI)

tmm.CFLAGS += -DBOARD_CONFIG=\"tiny_1_1.h\" -DPERIODIC_TASK_PERIOD='CPU_TICKS_OF_SEC(16.666e-3)'
tmm.srcs = $(TL)/tl_test_mm_main.c sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c

tmm.CFLAGS += -DUSE_LED  -DUSE_LED -DTIME_LED=1
tmm.CFLAGS += -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_DEVICE=Uart0 -DPPRZ_UART=Uart0 -DUART0_BAUD=B57600
tmm.srcs += subsystems/datalink/downlink.c $(SRC_ARCH)/mcu_periph/uart_arch.c subsystems/datalink/pprz_transport.c

tmm.srcs += micromag.c $(SRC_ARCH)/micromag_hw.c

#
#
#

timu.ARCHDIR = $(ARCHI)

timu.CFLAGS += -DBOARD_CONFIG=\"tiny_1_1.h\" -DPERIODIC_TASK_PERIOD='CPU_TICKS_OF_SEC(16.666e-3)'
timu.srcs = $(TL)/tl_test_imu_main.c sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c

timu.CFLAGS += -DUSE_LED  -DUSE_LED -DTIME_LED=1
timu.CFLAGS += -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_DEVICE=Uart0 -DPPRZ_UART=Uart0 -DUART0_BAUD=B57600
timu.srcs += subsystems/datalink/downlink.c $(SRC_ARCH)/mcu_periph/uart_arch.c subsystems/datalink/pprz_transport.c

timu.srcs += $(TL)/tl_imu.c
timu.CFLAGS += -DADC -DUSE_ADC_5 -DADC_CHANNEL_GR=ADC_5 -DUSE_ADC_6 -DADC_CHANNEL_RM=ADC_6 -DUSE_ADC_7 -DADC_CHANNEL_ACCEL=ADC_7
timu.srcs += $(SRC_ARCH)/adc_hw.c
timu.srcs += $(TL)/tl_baro.c
timu.srcs += micromag.c $(SRC_ARCH)/micromag_hw.c



  </makefile>

</airframe>
