/* 
 * File:   config.h
 * Author: hamilton
 *
 * Created on January 15, 2014, 4:29 PM
 */

#ifndef CONFIG_H
#define	CONFIG_H

//#define DEBUG  //This includes various DEBUG features
//#define ALLOW_CALIBRATION  //This allows the controller to be put into calibration mode and displays raw counts for the AIO on the serial port.

#define CODE_VERSION 0
#define CODE_SUBVERSION 9

#define HEADING_CONTROL_MODE 0  // Mode 0 is heading control
#define RUDDERPOSITION_CONTROL_MODE 1  // Mode 1 is rudder position mode
#define BANGBANG_CONTROL_MODE 2  // Mode 2 is bang-bang heading control mode

#define DEFAULT_POWERUP_MODE HEADING_CONTROL_MODE


#define BANGBANG_DEADBAND 20

#define RUDDER_DEADBAND 1

#define COMPASS_OFFSET 180  //This is the angle the IMU outputs when the FFD is pointed north.  (i.e. 180 degrees means it's mounted pointed at the stern)

/******** Configure Default Behavior Here *********/
#define DEFAULT_HEADING 250  //degrees:  Default heading is NW, controller steers to this in the absence of a heading update
#define HEADING_TIMEOUT 600   //Heading update timeout, after this many seconds without a heading update, the controller steers to the default, defined above.
                 
#define DEFAULT_HEADING_FILTER_TIME_CONSTANT 0  //Specified in seconds.  Converted to filter divisor based on CAN Update rate at startup.  Value of zero turns off filtering.
#define DEFAULT_CONTROL_UPDATE_PERIOD 0  //Specified in tenths of seconds.  Converted to CAN Update periods at startup.  Value of zero causes control loop to run at CAN update rate.

#define DEFAULT_PROP_GAIN 0.4
#define DEFAULT_INT_GAIN 0.005 // 0.01
#define DEFAULT_DER_GAIN 0.2 // 0.01


#define EXTEND_LIMITSWITCH_INPUT _RE0
#define RETRACT_LIMITSWITCH_INPUT _RE3

/******** Configure CAN Bus identifier and speed *********/
//  CAN ID field width definitions, from least sig to most sig.
#define SEQ_WIDTH  9
#define ID_WIDTH  5
#define SRC_WIDTH 4

#define CAN_SRCID 3  //Specific ID identifying messages that originate from this hardware.

/* number of ECAN message buffers in DMA memory (must be greater or equal to the number of buffers used. */
#define ECAN1_MSG_BUF_LENGTH 16   /* 8 transmit buffers  8 recieve buffers */
#define ECAN1_NUM_TX_BUFFERS 8

#define CAN_PACKET_RATE 10  //Must be 10 or 25

/******** Configure Analog IO here  *********/

//#define NUMAIO 2
#define NUMAIO 2

#define FILTERSAMPLES 32  //Must be 1,2,4,8,16,32,64,128.  Must match FIR filter length

#define AIOMASK_H 0xffff  //
//#define AIOMASK_L 0xf3ff  //Select AN10,AN11 to be sampled and scanned, total must match NUMAIO
#define AIOMASK_L 0xf7ef  //Select AN4,AN11 to be sampled and scanned, total must match NUMAIO

#define MAXHEADINGFILTERSAMPLES 2*60*CAN_PACKET_RATE
#define DEFAULTHEADINGFILTERSAMPLES 10*CAN_PACKET_RATE



#endif	/* CONFIG_H */

