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 )
@@ -93,7 +94,7 @@ def control_time(self, power_left=100, power_right=100, time_elapse=0):
9394 """ Motor distance control allows the motors
9495 to run for a certain amount of distance (mm) """
9596 def control_distance (self , power_left = 100 , power_right = 100 , target_distance = 0 ):
96- self ._wheelsAxle_lock .acquire () # wheelsAxle lock acquire
97+ # self._wheelsAxle_lock.acquire() # wheelsAxle lock acquire
9798 self ._is_moving = True
9899
99100 # applying tension to motors
@@ -103,7 +104,8 @@ def control_distance(self, power_left=100, power_right=100, target_distance=0):
103104 # moving for certaing amount of distance
104105 # threshold value avoid to stop it after
105106 while (abs (self .distance ()) < target_distance ):
106- pass # busy waiting
107+ sleep (0.01 )
108+ #pass # busy waiting
107109
108110 # robot arrived
109111 self .stop ()
@@ -124,17 +126,18 @@ def stop(self):
124126
125127 # trying to fix distance different than zero after
126128 # wheels has stopped by re-resetting state after 0.5s
127- sleep (0.5 )
129+ # sleep(0.5)
128130 self ._left_motor .reset_state ()
129131 self ._right_motor .reset_state ()
130132
131133 # updating state
132134 self ._is_moving = False
133135 # restoring callback
134- try :
135- self ._wheelsAxle_lock .release ()
136- except RuntimeError :
137- pass
136+ #try:
137+ # self._wheelsAxle_lock.release()
138+ #except RuntimeError as e:
139+ # logging.error("error: " + str(e))
140+ # pass
138141
139142 # CALLBACK
140143 def cancel_callback (self ):
0 commit comments