Beruflich Dokumente
Kultur Dokumente
Module
MotorService.c
Description
This module contains the motor init function and motor helper functions.
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for the framework and this service
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_DeferRecall.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_ssi.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h" // Define PART_TM4C123GH6PM in project
#include "driverlib/gpio.h"
#include "termio.h"
#include "hw_nvic.h"
#include "hw_pwm.h"
#include "hw_timer.h"
#include "hw_ssi.h"
#include "MyPWMLib.h"
#include "MotorEncoders.h"
#include "MasterSM.h"
// define directions TODO: check this, motor should turn CW/CCW when looking at the
wheel, down the axle
#define CW 1
#define CCW 0
Parameters
void
Returns
bool, false if error in initialization, true otherwise
Description
****************************************************************************/
bool InitMotors(void)
{
//init PWM lines
My_PWM_Init_Many(NUM_MOTORS);
return true;
}
//***************DRIVE FUNCTIONS*******************//
//set duty cycle and direction of left drive motor
void SetLeftDrive(uint8_t Duty, bool Dir)
{
//set direction
if (Dir)
{
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) |= LEFT_DRIVE_DIR_PIN;
My_PWM_SetDuty(100 - Duty, LEFT_DRIVE_CHANNEL);
}
else
{
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) &= ~LEFT_DRIVE_DIR_PIN;
My_PWM_SetDuty(Duty, LEFT_DRIVE_CHANNEL);
}
}
//left forward
bool DriveLeftForward(uint8_t Duty)
{
DisableEncoderControl();
SetLeftDrive(Duty, CCW);
SetRightDrive(0, CW);
return true;
}
//right forward
bool DriveRightForward(uint8_t Duty)
{
DisableEncoderControl();
SetLeftDrive(0, CCW);
SetRightDrive(Duty, CW);
return true;
}
//left backward
bool DriveLeftBackward(uint8_t Duty)
{
DisableEncoderControl();
SetLeftDrive(Duty, CW);
SetRightDrive(0, CCW);
return true;
}
//right backward
bool DriveRightBackward(uint8_t Duty)
{
DisableEncoderControl();
SetLeftDrive(0, CW);
SetRightDrive(Duty, CCW);
return true;
}
//left backward
bool SquareMoveRightForward(uint8_t DutyForward, uint8_t DutyBackward)
{
DisableEncoderControl();
SetLeftDrive(DutyBackward, CW);
SetRightDrive(DutyForward, CW);
return true;
}
bool SquareMoveLeftForward(uint8_t DutyForward, uint8_t DutyBackward)
{
DisableEncoderControl();
SetLeftDrive(DutyForward, CCW);
SetRightDrive(DutyBackward, CCW);
return true;
}
// encoder
SetLeftRPM(RPM, CW);
SetRightRPM(RPM, CCW);
SetLeftRPM(RPM, CW);
SetRightRPM(0, CW);
/***************************************************************************
private functions
***************************************************************************/