27 #if defined(BOARD_maple) || defined(BOARD_maple_native) || defined(BOARD_maple_mini)
29 #include "./../PID_Beta6/PID_Beta6.h"
30 #include "ext_interrupts.h"
53 #define DIR_ADVANCE HIGH
54 #define DIR_BACKOFF LOW
56 #define PIN_UNDEFINED 255
59 #if defined(BOARD_maple) || defined(BOARD_maple_native) || defined(BOARD_maple_mini)
69 #define TRIGGER CHANGE
72 #define REDUCTION_RATIO 80
74 #define TRIGGER CHANGE
77 #define REDUCTION_RATIO 64
80 #define MAX_SPEEDRPM 8000
85 #define SEC_PER_MIN 60
86 #define MICROS_PER_SEC 1000000
88 #define SPEEDPPS2SPEEDRPM(freq) ((unsigned long)(freq)*(SEC_PER_MIN)/(CPR))
98 #define Baudrate 19200
106 if(!Serial.available()) Serial.begin(Baudrate); \
107 Serial.println(__func__);}
114 #define irqISR(y,x) \
116 struct ISRVars y={x}; \
118 static bool first_pulse=true; \
119 y.pulseEndMicros=micros(); \
120 if(first_pulse==false && y.pulseEndMicros>y.pulseStartMicros) { \
121 y.speedPPS=MICROS_PER_SEC/(y.pulseEndMicros-y.pulseStartMicros); \
123 } else first_pulse=false; \
124 y.pulseStartMicros=y.pulseEndMicros; \
126 if(y.pinIRQB!=PIN_UNDEFINED) \
127 y.currDirection=DIR_INVERSE(digitalRead(y.pinIRQ)^digitalRead(y.pinIRQB)); \
128 y.currDirection==DIR_ADVANCE?++y.pulses:--y.pulses; \
147 Motor(
unsigned char _pinPWM,
unsigned char _pinDir,
148 unsigned char _pinIRQ,
unsigned char _pinIRQB,
158 unsigned int runPWM(
unsigned int PWM,
bool dir,
bool saveDir=
true);
159 unsigned int getPWM()
const;
180 bool PIDSetup(
float kc=
KC,
float taui=
TAUI,
float taud=
TAUD,
unsigned int sampleTime=1000);
201 unsigned char pinPWM;
202 unsigned char pinDir;
207 bool desiredDirection;
208 unsigned int speedPWM;
214 float speed2DutyCycle;
230 #ifndef REDUCTION_RATIO
231 #define REDUCTION_RATIO 64
235 GearedMotor(
unsigned char _pinPWM,
unsigned char _pinDir,
236 unsigned char _pinIRQ,
unsigned char _pinIRQB,
261 MotorWheel(
unsigned char _pinPWM,
unsigned char _pinDir,
262 unsigned char _pinIRQ,
unsigned char _pinIRQB,
#define REDUCTION_RATIO
Definition: MotorWheel.h:77
#define CIRMM
Definition: MotorWheel.h:258
#define KC
Definition: MotorWheel.h:93
#define TAUI
Definition: MotorWheel.h:94
#define TAUD
Definition: MotorWheel.h:95
#define debug()
Definition: MotorWheel.h:109
Definition: MotorWheel.h:233
float setGearedSpeedRPM(float gearedSpeedRPM, bool dir)
Definition: MotorWheel.cpp:309
float getGearedSpeedRPM() const
Definition: MotorWheel.cpp:303
unsigned int setRatio(unsigned int ratio=REDUCTION_RATIO)
Definition: MotorWheel.cpp:293
float getPosition()
Definition: MotorWheel.cpp:323
GearedMotor(unsigned char _pinPWM, unsigned char _pinDir, unsigned char _pinIRQ, unsigned char _pinIRQB, struct ISRVars *_isr, unsigned int _ratio=REDUCTION_RATIO)
Definition: MotorWheel.cpp:284
unsigned int getRatio() const
Definition: MotorWheel.cpp:290
Definition: MotorWheel.h:259
void setGearedRPM(float rpm, bool dir)
Definition: MotorWheel.cpp:364
int setSpeedMMPS(unsigned int mm, bool dir)
Definition: MotorWheel.cpp:375
MotorWheel(unsigned char _pinPWM, unsigned char _pinDir, unsigned char _pinIRQ, unsigned char _pinIRQB, struct ISRVars *_isr, unsigned int ratio=REDUCTION_RATIO, unsigned int cirMM=CIRMM)
Definition: MotorWheel.cpp:329
int getSpeedMMPS() const
Definition: MotorWheel.cpp:370
unsigned int setCirMM(unsigned int cirMM=CIRMM)
Definition: MotorWheel.cpp:340
int getSpeedCMPM() const
Definition: MotorWheel.cpp:345
int setSpeedCMPM(unsigned int cm, bool dir)
Definition: MotorWheel.cpp:350
unsigned int getCirMM() const
Definition: MotorWheel.cpp:337
Definition: MotorWheel.h:145
bool PIDSetup(float kc=KC, float taui=TAUI, float taud=TAUD, unsigned int sampleTime=1000)
Definition: MotorWheel.cpp:171
void delayMS(unsigned int ms, bool debug=false)
Definition: MotorWheel.cpp:230
unsigned int advancePWM(unsigned int PWM)
Definition: MotorWheel.cpp:80
long resetCurrPulse()
Definition: MotorWheel.cpp:226
bool PIDGetStatus() const
Definition: MotorWheel.cpp:149
bool setDesiredDir(bool dir)
Definition: MotorWheel.cpp:92
unsigned int PIDSetSpeedRPMDesired(unsigned int speedRPM)
Definition: MotorWheel.cpp:180
unsigned char getPinIRQB() const
Definition: MotorWheel.cpp:67
long getCurrPulse() const
Definition: MotorWheel.cpp:219
void debugger() const
Definition: MotorWheel.cpp:240
int getSpeedPPS() const
Definition: MotorWheel.cpp:216
bool PIDDisable()
Definition: MotorWheel.cpp:159
long setCurrPulse(long _pulse)
Definition: MotorWheel.cpp:222
unsigned char getPinIRQ() const
Definition: MotorWheel.cpp:63
void setupInterrupt()
Definition: MotorWheel.cpp:33
unsigned int setSpeedRPM(int speedRPM, bool dir)
Definition: MotorWheel.cpp:129
bool setCurrDir()
Definition: MotorWheel.cpp:111
unsigned int PIDGetSpeedRPMDesired() const
Definition: MotorWheel.cpp:186
unsigned int getPWM() const
Definition: MotorWheel.cpp:88
bool PIDRegulate(bool doRegulate=true)
Definition: MotorWheel.cpp:191
bool getDesiredDir() const
Definition: MotorWheel.cpp:98
bool getCurrDir() const
Definition: MotorWheel.cpp:108
struct ISRVars * isr
Definition: MotorWheel.h:198
unsigned char getPinPWM() const
Definition: MotorWheel.cpp:55
unsigned int runPWM(unsigned int PWM, bool dir, bool saveDir=true)
Definition: MotorWheel.cpp:72
bool PIDEnable(float kc=KC, float taui=TAUI, float taud=TAUD, unsigned int sampleTime=1000)
Definition: MotorWheel.cpp:153
int getSpeedRPM() const
Definition: MotorWheel.cpp:136
bool PIDReset()
Definition: MotorWheel.cpp:164
bool reverseDesiredDir()
Definition: MotorWheel.cpp:102
unsigned int backoffPWM(unsigned int PWM)
Definition: MotorWheel.cpp:84
unsigned char getPinDir() const
Definition: MotorWheel.cpp:59
Definition: PID_Beta6.h:5
Definition: MotorWheel.h:131
unsigned char pinIRQB
Definition: MotorWheel.h:141
void(* ISRfunc)()
Definition: MotorWheel.h:132
volatile long pulses
Definition: MotorWheel.h:134
volatile unsigned long pulseEndMicros
Definition: MotorWheel.h:136
volatile bool currDirection
Definition: MotorWheel.h:140
volatile unsigned long pulseStartMicros
Definition: MotorWheel.h:135
unsigned char pinIRQ
Definition: MotorWheel.h:142
volatile unsigned int speedPPS
Definition: MotorWheel.h:137