It seems like there's a tradeoff between how we choose to set the max power of the motors. Previously, I had set the motors' max power (torque) to follow their target speed, meaning they accelerated smoothly, but also lost their torque. Then in the following commit I changed the max power to 100 which means maximum torque to achieve the target speed, which resulted in very abrupt accelerations and erratic motor movement when changing speeds:

873b56c985

In the following commit I changed the functionality so that we add a fixed amount (10) more power than the target speed, e.g. for speed 50 it would provide power 60. This is fine for high speeds, but for low speeds it provides poor torque:

e3cdbffa2a

I assume it would be possible to design some sort of calculation that enabled high torque for low speeds, and vice versa. I will discuss with the team.
This commit is contained in:
Kevin Andersen 2019-04-08 17:56:54 -04:00
parent e24ace83a0
commit ecbbacd4c0
2 changed files with 22 additions and 8 deletions

View file

@ -365,17 +365,17 @@ class BoostMotor {
} }
/** /**
* @param {int} value - this motor's new power level, in the range [0,100]. * @param {int} value - this motor's new power level, in the range [10,100].
*/ */
set power (value) { set power (value) {
const p = Math.max(0, Math.min(value, 100)); /**
// The Boost motors barely move at speed 1 - solution is to step up to 2. * Scale the motor power to a range between 10 and 100,
if (p === 1) { * to make sure the motors will run with something built onto them.
this._power = 2; */
} else { const p = MathUtil.scale(value, 0, 100, 10, 100);
this._power = p; this._power = p;
} }
}
/** /**
* @return {int} - this motor's current position, in the range of [-MIN_INT32,MAX_INT32] * @return {int} - this motor's current position, in the range of [-MIN_INT32,MAX_INT32]

View file

@ -77,6 +77,20 @@ class MathUtil {
const sorted = elts.slice(0).sort((a, b) => a - b); const sorted = elts.slice(0).sort((a, b) => a - b);
return elts.map(e => sorted.indexOf(e)); return elts.map(e => sorted.indexOf(e));
} }
/**
* Scales a number from one range to another.
* @param {number} i number to be scaled
* @param {number} iMin input range minimum
* @param {number} iMax input range maximum
* @param {number} oMin output range minimum
* @param {number} oMax output range maximum
* @return {number} scaled number
*/
static scale (i, iMin, iMax, oMin, oMax) {
const p = (i - iMin) / (iMax - iMin);
return (p * (oMax - oMin)) + oMin;
}
} }
module.exports = MathUtil; module.exports = MathUtil;