Merge remote-tracking branch 'origin/main' into galactic-adjustments
This commit is contained in:
commit
6210895df4
@ -1,5 +1,10 @@
|
|||||||
#include<MotorWheel.h>
|
#include<MotorWheel.h>
|
||||||
|
|
||||||
|
inline int modulo(int a, int b) {
|
||||||
|
const int result = a % b;
|
||||||
|
return result >= 0 ? result : result + b;
|
||||||
|
}
|
||||||
|
|
||||||
Motor::Motor(unsigned char _pinPWM,unsigned char _pinDir,
|
Motor::Motor(unsigned char _pinPWM,unsigned char _pinDir,
|
||||||
unsigned char _pinIRQ,unsigned char _pinIRQB,
|
unsigned char _pinIRQ,unsigned char _pinIRQB,
|
||||||
struct ISRVars* _isr)
|
struct ISRVars* _isr)
|
||||||
@ -323,7 +328,7 @@ float GearedMotor::setGearedSpeedRPM(float gearedSpeedRPM) {
|
|||||||
float GearedMotor::getPosition() {
|
float GearedMotor::getPosition() {
|
||||||
debug();
|
debug();
|
||||||
int ticks_per_rev = getRatio() * CPR;
|
int ticks_per_rev = getRatio() * CPR;
|
||||||
return (float)(Motor::getCurrPulse() % ticks_per_rev)/ticks_per_rev;
|
return ((float)modulo(Motor::getCurrPulse(), ticks_per_rev))/ticks_per_rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
MotorWheel::MotorWheel(unsigned char _pinPWM,unsigned char _pinDir,
|
MotorWheel::MotorWheel(unsigned char _pinPWM,unsigned char _pinDir,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user