#ifndef _STP100_H
#define _STP100_H

/****************************************************************************/
/* Copyright (c) 2000 MBARI.                                                */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  : STP100 Stepper Motor Controller - Function Definitions        */
/* Filename : stp100.h                                                      */
/* Author   : Andrew Pearce                                                 */
/* Project  : Dorado AUV Tailcone                                           */
/* Version  : 1.0                                                           */
/* Created  : 01/19/00                                                      */
/* Modified : 01/19/00                                                      */
/* Archived :                                                               */
/****************************************************************************/

typedef struct
{
  quadSerialChan serialChan;            /* Serial IO channel descriptor     */

  Nat32 controlTick;                    /* Schedule controller at this tick */
  Nat16 controlPeriod;                  /* Controller tick rate             */

  Int16 desiredPosition;                /* Desired position. Input to ctrl  */
  Int16 position;                       /* Measured position feedback       */


  /* The following variables are used to store the coefficients of the      */
  /* linear approximation function f(theta) = #steps .  Where theta is      */
  /* expressed in degrees => F(theta) = C1*theta + C2*theta^2               */ 
  /* there is a further nuance to this. We are actually multiplying the     */
  /* coefficients by 10 in order to express them as integer values and we   */
  /* divide out this gain from the # of steps we actually execute           */ 

  Int16 C1;      /* Linear term coeff. for linear approx (steps/degree)      */
  Int16 C2;      /* Quadradic term coeff. for linear approx (steps/degree^2) */ 
  /***************************************************************************/

  Int16 lastPosition;

} stpStruct;

#define STP100_CMD_DELAY  2             /* 20 msec delay between commands   */
#define STP100_TERM      13             /* Carriage return terminator       */
#define STP100_DELTA_POS 20             /* 20 step minimum position change  */


Int16 stp100OpenSerialChan(stpStruct *stp, Byte *boardAddr, Nat16 chan,
    IBC_BoardEntry *IBC_CardTable[], Int16 cardCount);

Int16 stp100ReadData(stpStruct *stp, Byte *buffer, Int16 maxLen);

Int16 stp100WriteData(stpStruct *stp, char *cmd);

Int16 stp100BoardSelect(stpStruct *stp, Int16 board);

Int16 stp100ReadID(stpStruct *stp);

Int16 stp100ReadAtoD(stpStruct *stp, Int16 chan);

Int16 stp100SmoothHalt(stpStruct *stp);

Int16 stp100PosInSteps(stpStruct *stp);

Void stp100InitializeController(stpStruct *stp, Nat16 controlPeriod);

Void stp100PositionControl(stpStruct *stp);

Void stp100SetStepMode(stpStruct *stp);
#endif



