You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1003 B
C++

// AccurateMotor.h
/*
* 精确的电机驱动类,通过定时器中断的形式规避内置码盘不可靠的问题
*/
#ifndef _ACCURATEMOTOR_h
#define _ACCURATEMOTOR_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include <DCMotor.h>
#include <MsTimer2.h>
class AccurateMotorClass
{
private:
bool car_running;
const uint16_t car_speed = 50;
const uint16_t car_slow_speed = 10;
//const uint16_t car_turn_speed = 100;
const uint16_t car_turn_speed = 97;
const uint16_t turn_multplyer = 7;
const uint16_t run_multplyer = 100;
private:
static void SetCarRunning();
static void SetCarNotRunning();
public:
void Init();
bool IsCarRunning();
void DelayUntilCarStop();
public:
void ForceStop();
void TurnLeft(uint8_t degree);
void TurnRight(uint8_t degree);
void RunForward(uint8_t distence);
void RunBackward(uint8_t distence);
void RunForwardSlow(uint8_t distence);
void RunBackwardSlow(uint8_t distence);
};
extern AccurateMotorClass AccurateMotor;
#endif