/**************************************************************************

Motors.h

ME 218B Project Hats Off

Team Firefox

March 7, 2010

The robot uses 2 DC motors. Implements PWM

 

Requirements:

Timer1 --> /32 = 87.3 [ms] rollover with 1.34 [us] resolution

 

***************************************************************************/

#ifndef Motors_h

#define Motors_h

/*-------------------------- Include Files -----------------------------*/

#include <stdio.h>

#include <termio.h>

 

#include <hidef.h>

#include <mc9s12e128.h>

#include <bitdefs.h>

#include <S12E128bits.h>

#include "S12eVec.h"

 

#include "ADS12.h"

#include "ME218_E128.h"

#include "PWM01.h"

#include "myTimer.h"

 

//included with main.c for E128

/* common defines and macros */

/* derivative information */

#pragma LINK_INFO DERIVATIVE "SampleS12"

 

/*-------------------------- Public Type Def -----------------------------*/

typedef enum      {     CCW = 0,

                        CW = 1

                  } MOTOR_TurnDir_t;

 

typedef enum      {     MOTORS_MOVING,

                        MOTORS_STOPPING,

                        MOTORS_STOPPED

                  } MOTOR_State_t;

/*-------------------------- Public Functions -----------------------------*/

void Motors_Init(void);             //call only once

 

//these functions will NOT reset position integration

void Motors_moveStraight(int spd); //spd = [-100, 100]

void Motors_moveDiff(int spd1, int spd0);

void Motors_turn(MOTOR_TurnDir_t dir, int spd);

 

//these functions WILL reset position integration

void Motors_moveStraightStop(int spd, float inches); //inches must be positive!

void Motors_turnStop(MOTOR_TurnDir_t dir, int spd, unsigned int degree);

 

//explicit reset of integrated positions

void Motors_resetPosition(void);

 

//determine if bot is currently MOVING, STOPPING, or STOPPED

MOTOR_State_t Motors_getState(void);

 

//determine linear distance traversed in inches since last position reset (should be zero for turns)

float Motors_getNetDistance(void);

float Motors_getDegreesTurned(void);

long Motors_getEncoderCount(int motorNum);

 

//dubug funtions

void Motors_debugMove(int duty1, int duty0);     //sets motors duty cycles

void Motors_debugPrint(char motorNum);           //prints motor one

void Motors_checkNegDuty(void);

 

#endif