Skip to content

Commit a086d9f

Browse files
committed
Merge branch 'motor-variation' into pre-kickstart
2 parents 2e93c39 + a2e7123 commit a086d9f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

simulator/modules/sbot_interface/devices/motor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def set_power(self, value: int) -> None:
119119
else:
120120
# Apply a small amount of variation to the power setting to simulate
121121
# inaccuracies in the motor
122-
value = int(add_jitter(value, (MIN_POWER, MAX_POWER)))
122+
value = int(add_jitter(value, (MIN_POWER, MAX_POWER), std_dev_percent=1))
123123

124124
self._device.setVelocity(map_to_range(
125125
value,

simulator/protos/robot/MotorAssembly.proto

+18-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,24 @@ PROTO MotorAssembly [
4949
device [
5050
RotationalMotor {
5151
name IS name
52-
maxVelocity IS maxVelocity
52+
%<
53+
import * as wbrandom from 'wbrandom.js';
54+
const motorVariation = 0.015;
55+
// equivalent to Java's String.hashCode()
56+
// https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0
57+
function hashCode(s) {
58+
var h = 0, l = s.length, i = 0;
59+
if ( l > 0 )
60+
while (i < l)
61+
h = (h << 5) - h + s.charCodeAt(i++) | 0;
62+
return h;
63+
};
64+
wbrandom.seed(hashCode(fields.name.value));
65+
let motorCoeff = 1 + wbrandom.real() * motorVariation;
66+
>%
67+
# seed the random number generator with the name of the motor
68+
# Add 1.5% variation between motors
69+
maxVelocity %<= fields.maxVelocity.value * motorCoeff >%
5370
sound ""
5471
}
5572
PositionSensor {

0 commit comments

Comments
 (0)