Você está na página 1de 5

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

Module
Motion.c
Revision
1.0
Description
This is Motion module. Functions to perform different motions.
Notes
Different error <-> different calibration speed?
History
When
Who
What/Why
----------------------02/12/2015
11:22 Sky
Added Shoot
02/11/2015 09:50 Sky
Added CalibrateForward
02/10/2015 10:56
Sky
Initial version
****************************************************************************/
//#define testMotor
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_DeferRecall.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

"inc/hw_memmap.h"
"inc/hw_types.h"
"inc/hw_gpio.h"
"inc/hw_sysctl.h"
"driverlib/sysctl.h"
"driverlib/pin_map.h" // Define PART_TM4C123GH6PM in project
"driverlib/gpio.h"
"inc/hw_ssi.h"
"inc/hw_nvic.h"
"PWM4Wheel.h"
"Motion.h"
"WheelRPMControl.h"
"PWM4ShootMotor.h"

#define LEFTWHEEL 1
#define RIGHTWHEEL 2
#define LEFT
0
#define RIGHT 1
#define
#define
#define
#define

SPEEDLV1 0
SPEEDLV2 1
SPEEDLV3 2
SPEEDLVCLIMB 2

#define FORWARD 0
#define BACKWARD 1
/*****************************Constants**************************************/
static const uint16_t InnerWheelRPM4Turn[3] = {20, 20, 15};
static const uint16_t OuterWheelRPM4Turn[3] = {75, 80, 30};
static const uint16_t LeftWheelRPM4Move[3] = {30, 85, 60};
static const uint16_t RightWheelRPM4Move[3] = {30, 85, 60};
static const uint16_t RotateRPM = 20;
/*************************Module Variables***********************************/

/*******************************Public Functions*****************************/
/********************************************************************
FUNCTION TurnRight
ARGUMENTS: a integer represent the speed level
RETURN: no return
DESCRIPTION: set the motor speed and direction to turn right
********************************************************************/
void TurnRight(uint8_t SpeedLv)
{
//set direction for motors first
SetDirection(FORWARD, LEFTWHEEL);
SetDirection(FORWARD, RIGHTWHEEL);
SetTargetRPMLeft(OuterWheelRPM4Turn[SpeedLv]);
SetTargetRPMRight(InnerWheelRPM4Turn[SpeedLv]);
}
/********************************************************************
FUNCTION TurnLeft
ARGUMENTS: a integer represent the speed level
RETURN: no return
DESCRIPTION: set the motor speed and direction to turn left
********************************************************************/
void TurnLeft(uint8_t SpeedLv)
{
//set direction for motors first
SetDirection(FORWARD, LEFTWHEEL);
SetDirection(FORWARD, RIGHTWHEEL);
SetTargetRPMLeft(InnerWheelRPM4Turn[SpeedLv]);
SetTargetRPMRight(OuterWheelRPM4Turn[SpeedLv]);
}
/********************************************************************
FUNCTION MoveForward
ARGUMENTS: a integer represent the speed level
RETURN: no return
DESCRIPTION: set the motor speed and direction to move forward
********************************************************************/
void MoveForward(uint8_t SpeedLv)
{
//set direction for motors first
printf("Forward!\n\r");
SetDirection(FORWARD, LEFTWHEEL);
SetDirection(FORWARD, RIGHTWHEEL);
SetTargetRPMLeft(LeftWheelRPM4Move[SpeedLv]);
SetTargetRPMRight(RightWheelRPM4Move[SpeedLv]);
}
/********************************************************************
FUNCTION MoveBackward

ARGUMENTS: a integer represent the speed level


RETURN: no return
DESCRIPTION: set the motor speed and direction to move backward
********************************************************************/
void MoveBackward(uint8_t SpeedLv)
{
//set direction for motors first
SetDirection(BACKWARD, LEFTWHEEL);
SetDirection(BACKWARD, RIGHTWHEEL);
SetTargetRPMLeft(LeftWheelRPM4Move[SpeedLv]);
SetTargetRPMRight(RightWheelRPM4Move[SpeedLv]);
}
/********************************************************************
FUNCTION RotateRight
ARGUMENTS: no argument
RETURN: no return
DESCRIPTION: set the motor speed and direction to rotate right
********************************************************************/
void RotateLeft(void)
{
//set direction for motors first
printf("RotateLeft!\n\r");
SetDirection(BACKWARD, LEFTWHEEL);
SetDirection(FORWARD, RIGHTWHEEL);
SetTargetRPMLeft(RotateRPM);
SetTargetRPMRight(RotateRPM);
}
/********************************************************************
FUNCTION RotateLeft
ARGUMENTS: no argument
RETURN: no return
DESCRIPTION: set the motor speed and direction to rotate left
********************************************************************/
void RotateRight(void)
{
printf("RotateRight!\n\r");
//set direction for motors first
SetDirection(FORWARD, LEFTWHEEL);
SetDirection(BACKWARD, RIGHTWHEEL);
SetTargetRPMLeft(RotateRPM);
SetTargetRPMRight(RotateRPM);
}
/********************************************************************
FUNCTION Stop
ARGUMENTS: no argument
RETURN: no return

DESCRIPTION: set the motor speed and direction to turn right


********************************************************************/
void Stop(void)
{
SetTargetRPMLeft(0);
SetTargetRPMRight(0);
//SetDuty(0, LEFTWHEEL);
//SetDuty(0, RIGHTWHEEL);
}
void StopLeftWheel(void)
{
SetTargetRPMLeft(0);
}
void StopRightWheel(void)
{
SetTargetRPMRight(0);
}
/********************************************************************
FUNCTION ClibrateForward
ARGUMENTS: a integer represents the speed level and a integer represents
the direction
RETURN: no return
DESCRIPTION: set the motor speed and direction to turn right
********************************************************************/
void CalibrateForward(uint8_t SpeedLv, uint8_t Direction)
{
if (Direction == LEFT)
{
TurnLeft(SpeedLv);
}
else if (Direction == RIGHT)
{
TurnRight(SpeedLv);
}
}

#ifdef testMotor
#define clrScrn()
#define goHome()
#define clrLine()

printf("\x1b[2J")
printf("\x1b[1,1H")
printf("\x1b[K")

#define LEFTWHEEL 1
#define RIGHTWHEEL 2
int main(void)
{
// Set the clock to run at 40MhZ using the PLL and 16MHz external crysta
l

SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN


| SYSCTL_XTAL_16MHZ);
TERMIO_Init();
clrScrn();
InitMotorControlPin();
InitPWMDemo();
uint8_t Temp = 0;
while (1)
{
getchar();
Temp = ((Temp+10 -1)% 100) +1;
SetDuty(Temp, LEFTWHEEL);
printf("CurrentDuty = %d\n\r", Temp);
}
}
#endif

Você também pode gostar