Skip to content

Commit

Permalink
Merge pull request #80 from Svol0/master
Browse files Browse the repository at this point in the history
avoid negative base value for pow() function caused by offset
  • Loading branch information
greymfm authored Jul 4, 2022
2 parents a44bdbc + aaf1e92 commit b94033d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions sunray/src/driver/AmRobotDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void AmMotorDriver::begin(){
// example: mowDriverChip.minPwmSpeed = 40;

#ifdef MOTOR_DRIVER_BRUSHLESS_MOW_DRV8308
mowDriverChip = DRV8308;
mowDriverChip = DRV8308;
#elif MOTOR_DRIVER_BRUSHLESS_MOW_A4931
mowDriverChip = A4931;
mowDriverChip.minPwmSpeed = 40;
Expand Down Expand Up @@ -503,15 +503,24 @@ void AmMotorDriver::resetMotorFaults(){

void AmMotorDriver::getMotorCurrent(float &leftCurrent, float &rightCurrent, float &mowCurrent){
// current (amps)= ((ADCvoltage + ofs)^pow) * scale
float ValuePosCheck = 0;
ValuePosCheck = (((float)ADC2voltage(analogRead(pinMotorLeftSense))) + gearsDriverChip.adcVoltToAmpOfs);
if (ValuePosCheck < 0) ValuePosCheck = 0; // avoid negativ numbers
leftCurrent = pow(
((float)ADC2voltage(analogRead(pinMotorLeftSense))) + gearsDriverChip.adcVoltToAmpOfs, gearsDriverChip.adcVoltToAmpPow
ValuePosCheck, gearsDriverChip.adcVoltToAmpPow
) * gearsDriverChip.adcVoltToAmpScale;

ValuePosCheck = (((float)ADC2voltage(analogRead(pinMotorRightSense))) + gearsDriverChip.adcVoltToAmpOfs);
if (ValuePosCheck < 0) ValuePosCheck = 0; // avoid negativ numbers
rightCurrent = pow(
((float)ADC2voltage(analogRead(pinMotorRightSense))) + gearsDriverChip.adcVoltToAmpOfs, gearsDriverChip.adcVoltToAmpPow
ValuePosCheck, gearsDriverChip.adcVoltToAmpPow
) * gearsDriverChip.adcVoltToAmpScale;

ValuePosCheck = (((float)ADC2voltage(analogRead(pinMotorMowSense))) + gearsDriverChip.adcVoltToAmpOfs);
if (ValuePosCheck < 0) ValuePosCheck = 0; // avoid negativ numbers
mowCurrent = pow(
((float)ADC2voltage(analogRead(pinMotorMowSense))) + mowDriverChip.adcVoltToAmpOfs, mowDriverChip.adcVoltToAmpPow
) * mowDriverChip.adcVoltToAmpScale;
ValuePosCheck, mowDriverChip.adcVoltToAmpPow
) * mowDriverChip.adcVoltToAmpScale;
}

void AmMotorDriver::getMotorEncoderTicks(int &leftTicks, int &rightTicks, int &mowTicks){
Expand Down

0 comments on commit b94033d

Please sign in to comment.