Skip to content

Commit 462e45b

Browse files
committed
removed lock from wheelsaxel
1 parent b67ce85 commit 462e45b

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

coderbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __init__(self, motor_trim_factor=1.0, encoder=True):
132132
sonar.Sonar(self.pi, self.GPIOS.PIN_SONAR_4_TRIGGER, self.GPIOS.PIN_SONAR_4_ECHO)]
133133
self._servos = [self.GPIOS.PIN_SERVO_1, self.GPIOS.PIN_SERVO_2]
134134

135-
#self.stop()
135+
self.stop()
136136
self._is_moving = False
137137

138138
the_bot = None

rotary_encoder/motorencoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def reset_state(self):
136136
# CALLBACK
137137
""" The callback function rotary_callback is called on FALLING_EDGE by the
138138
rotary_decoder with a parameter value of 1 (1 new tick)
139-
139+
140140
- Gearbox ratio: 120:1 (1 wheel revolution = 120 motor revolution)
141141
- Encoder ratio: 16:1 encoder ticks for 1 motor revolution
142142
- 1 wheel revolution = 120 * 16 = 1920 ticks
@@ -145,7 +145,7 @@ def reset_state(self):
145145
- 1 tick = 0.0981mm
146146
- 1 tick : 0.0981mm = x : 1000mm -> x = 10193 ticks approximately
147147
So 0.0981 is the ticks->distance(mm) conversion coefficient
148-
148+
149149
The callback function calculates current velocity by taking groups of
150150
ticks_threshold ticks"""
151151

rotary_encoder/wheelsaxel.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pigpio
22
import threading
33
from time import sleep
4+
import logging
45

56
from 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

Comments
 (0)