11import pigpio
22import threading
33from time import sleep
4+ import logging
45
56from rotary_encoder .motorencoder import MotorEncoder
67
@@ -36,7 +37,7 @@ def __init__(self, pi, enable_pin,
3637 right_encoder_feedback_pin_B )
3738
3839 # other
39- self ._wheelsAxle_lock = threading .Condition () # race condition lock
40+ # self._wheelsAxle_lock = threading.RLock () # race condition lock
4041
4142 # STATE GETTERS
4243 """ Distance and speed are calculated by a mean of the feedback
@@ -78,7 +79,7 @@ def control(self, power_left=100, power_right=100, time_elapse=0, target_distanc
7879 """ Motor time control allows the motors
7980 to run for a certain amount of time """
8081 def control_time (self , power_left = 100 , power_right = 100 , time_elapse = 0 ):
81- self ._wheelsAxle_lock .acquire () # wheelsAxle lock acquire
82+ # self._wheelsAxle_lock.acquire() # wheelsAxle lock acquire
8283
8384 # applying tension to motors
8485 self ._left_motor .control (power_left )
@@ -94,7 +95,7 @@ def control_time(self, power_left=100, power_right=100, time_elapse=0):
9495 """ Motor distance control allows the motors
9596 to run for a certain amount of distance (mm) """
9697 def control_distance (self , power_left = 100 , power_right = 100 , target_distance = 0 ):
97- self ._wheelsAxle_lock .acquire () # wheelsAxle lock acquire
98+ # self._wheelsAxle_lock.acquire() # wheelsAxle lock acquire
9899 self ._is_moving = True
99100
100101 # applying tension to motors
@@ -192,17 +193,18 @@ def stop(self):
192193
193194 # trying to fix distance different than zero after
194195 # wheels has stopped by re-resetting state after 0.5s
195- sleep ( 0.1 )
196+
196197 self ._left_motor .reset_state ()
197198 self ._right_motor .reset_state ()
198199
199200 # updating state
200201 self ._is_moving = False
201202 # restoring callback
202- try :
203- self ._wheelsAxle_lock .release ()
204- except RuntimeError :
205- pass
203+ #try:
204+ # self._wheelsAxle_lock.release()
205+ #except RuntimeError as e:
206+ # logging.error("error: " + str(e))
207+ # pass
206208
207209 # CALLBACK
208210 def cancel_callback (self ):
0 commit comments