Skip to content

Commit

Permalink
Merge branch 'motor-variation' into pre-kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Sep 1, 2024
2 parents 2e93c39 + a2e7123 commit a086d9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion simulator/modules/sbot_interface/devices/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def set_power(self, value: int) -> None:
else:
# Apply a small amount of variation to the power setting to simulate
# inaccuracies in the motor
value = int(add_jitter(value, (MIN_POWER, MAX_POWER)))
value = int(add_jitter(value, (MIN_POWER, MAX_POWER), std_dev_percent=1))

self._device.setVelocity(map_to_range(
value,
Expand Down
19 changes: 18 additions & 1 deletion simulator/protos/robot/MotorAssembly.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@ PROTO MotorAssembly [
device [
RotationalMotor {
name IS name
maxVelocity IS maxVelocity
%<
import * as wbrandom from 'wbrandom.js';
const motorVariation = 0.015;
// equivalent to Java's String.hashCode()
// https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0
function hashCode(s) {
var h = 0, l = s.length, i = 0;
if ( l > 0 )
while (i < l)
h = (h << 5) - h + s.charCodeAt(i++) | 0;
return h;
};
wbrandom.seed(hashCode(fields.name.value));
let motorCoeff = 1 + wbrandom.real() * motorVariation;
>%
# seed the random number generator with the name of the motor
# Add 1.5% variation between motors
maxVelocity %<= fields.maxVelocity.value * motorCoeff >%
sound ""
}
PositionSensor {
Expand Down

0 comments on commit a086d9f

Please sign in to comment.