1
1
import pigpio
2
2
import threading
3
3
from time import sleep
4
+ import logging
4
5
5
6
from rotary_encoder .motorencoder import MotorEncoder
6
7
@@ -36,7 +37,7 @@ def __init__(self, pi, enable_pin,
36
37
right_encoder_feedback_pin_B )
37
38
38
39
# other
39
- self ._wheelsAxle_lock = threading .Condition () # race condition lock
40
+ # self._wheelsAxle_lock = threading.RLock () # race condition lock
40
41
41
42
# STATE GETTERS
42
43
""" 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
78
79
""" Motor time control allows the motors
79
80
to run for a certain amount of time """
80
81
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
82
83
83
84
# applying tension to motors
84
85
self ._left_motor .control (power_left )
@@ -93,7 +94,7 @@ def control_time(self, power_left=100, power_right=100, time_elapse=0):
93
94
""" Motor distance control allows the motors
94
95
to run for a certain amount of distance (mm) """
95
96
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
97
98
self ._is_moving = True
98
99
99
100
# applying tension to motors
@@ -103,7 +104,8 @@ def control_distance(self, power_left=100, power_right=100, target_distance=0):
103
104
# moving for certaing amount of distance
104
105
# threshold value avoid to stop it after
105
106
while (abs (self .distance ()) < target_distance ):
106
- pass # busy waiting
107
+ sleep (0.01 )
108
+ #pass # busy waiting
107
109
108
110
# robot arrived
109
111
self .stop ()
@@ -124,17 +126,18 @@ def stop(self):
124
126
125
127
# trying to fix distance different than zero after
126
128
# wheels has stopped by re-resetting state after 0.5s
127
- sleep (0.5 )
129
+ # sleep(0.5)
128
130
self ._left_motor .reset_state ()
129
131
self ._right_motor .reset_state ()
130
132
131
133
# updating state
132
134
self ._is_moving = False
133
135
# 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
138
141
139
142
# CALLBACK
140
143
def cancel_callback (self ):
0 commit comments