File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11python-ev3dev2 (2.0.0~beta3) stable; urgency=medium
22
3+ * GyroSensor wait_until_angle_changed_by added direction_sensitive option
34 * Added MoveDifferential
45 * Sound: removed play() in favor of play_file()
56 * suppress unittest ResourceWarning messages
Original file line number Diff line number Diff line change @@ -626,16 +626,32 @@ def reset(self):
626626 self ._ensure_mode (self .MODE_GYRO_ANG )
627627 self ._direct = self .set_attr_raw (self ._direct , 'direct' , 17 )
628628
629- def wait_until_angle_changed_by (self , delta ):
629+ def wait_until_angle_changed_by (self , delta , direction_sensitive = False ):
630630 """
631631 Wait until angle has changed by specified amount.
632+
633+ If ``direction_sensitive`` is True we will wait until angle has changed
634+ by ``delta`` and with the correct sign.
635+
636+ If ``direction_sensitive`` is False (default) we will wait until angle has changed
637+ by ``delta`` in either direction.
632638 """
633639 assert self .mode in (self .MODE_GYRO_G_A , self .MODE_GYRO_ANG ,
634640 self .MODE_TILT_ANG ),\
635641 'Gyro mode should be MODE_GYRO_ANG, MODE_GYRO_G_A or MODE_TILT_ANG'
636642 start_angle = self .value (0 )
637- while abs (start_angle - self .value (0 )) < delta :
638- time .sleep (0.01 )
643+
644+ if direction_sensitive :
645+ if delta > 0 :
646+ while (self .value (0 ) - start_angle ) < delta :
647+ time .sleep (0.01 )
648+ else :
649+ delta *= - 1
650+ while (start_angle - self .value (0 )) < delta :
651+ time .sleep (0.01 )
652+ else :
653+ while abs (start_angle - self .value (0 )) < delta :
654+ time .sleep (0.01 )
639655
640656
641657class InfraredSensor (Sensor , ButtonBase ):
You can’t perform that action at this time.
0 commit comments