Repository navigation
GyroSensor wait_until_angle_changed_by added direction_sensitive option - #551
Conversation
|
Tested via |
| self._direct = self.set_attr_raw(self._direct, 'direct', 17) | ||
|
|
||
| def wait_until_angle_changed_by(self, delta): | ||
| def wait_until_angle_changed_by(self, delta, honor_direction=False): |
There was a problem hiding this comment.
I think "honor" might be confusing to non-native English speakers; could we call it something else? Maybe direction_sensitive? specific_direction?
There was a problem hiding this comment.
direction_sensitive sounds good
| time.sleep(0.01) | ||
|
|
||
| if honor_direction: | ||
| if delta > 0: |
There was a problem hiding this comment.
This feels like a lot of duplicated code. Can we combine this to be one loop? I think this condition might work:
while (
(abs(self.value(0) - start_angle) < delta) # the sensor still hasn't moved far enough...
or (honor_direction and copysign(delta, 1) == copysign(self.value(0) - start_angle, 1))) # … or, it has moved in the wrong directionI'm not entirely sure my line break structure will fly with the Python interpreter, but you get the gist.
There was a problem hiding this comment.
Personally I find the expanded/verbose model a little easier to follow :)
There was a problem hiding this comment.
I just want to remove the duplicated loop code... whether that's with a more clever loop condition or something else doesn't matter to me.
For issue #534