Skip to content

Commit 7a045ee

Browse files
committed
merge develop
2 parents 002c60a + 462e45b commit 7a045ee

File tree

7 files changed

+84
-36
lines changed

7 files changed

+84
-36
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

cv/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Image():
5151
_aruco_parameters = cv2.aruco.DetectorParameters_create()
5252

5353
#_face_cascade = cv2.CascadeClassifier('/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml')
54-
_face_cascade = cv2.CascadeClassifier('/usr/local/share/OpenCV/lbpcascades/lbpcascade_frontalface.xml')
54+
_face_cascade = cv2.CascadeClassifier('/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml')
5555

5656
def __init__(self, array):
5757
self._data = array
@@ -161,7 +161,7 @@ def get_average(self):
161161
def find_blobs(self, minsize=0, maxsize=10000000):
162162
blobs = []
163163
image = contours = hyerarchy = None
164-
image, contours, hyerarchy = cv2.findContours(self._data, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
164+
contours, hyerarchy = cv2.findContours(self._data, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
165165

166166
for c in contours:
167167
area = cv2.contourArea(c)

requirements_stub.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# Basic set of required packages. If you need to run on a real system (NOT in STUB mode)
22
# install the packages in `requirements.txt` too.
33

4-
absl-py==0.8.1
5-
apiai==1.2.3
6-
astor==0.7.1
7-
Babel==2.5.3
4+
absl-py==0.9.0
5+
astor==0.8.1
6+
Babel==2.8.0
87
certifi==2018.4.16
98
chardet==3.0.4
10-
click==6.7
9+
click==7.0
1110
clickclick==1.2.2
1211
connexion==1.4.2
1312
Flask==1.1.1
1413
Flask-Babel==0.12.2
1514
Flask-Cors==3.0.8
16-
gast==0.2.0
17-
grpcio==1.25.0
18-
idna==2.6
15+
gast==0.2.2
16+
grpcio==1.26.0
17+
idna==2.8
18+
pybind11==2.4.3
1919
inflection==0.3.1
2020
itsdangerous==0.24
21-
Jinja2==2.10.3
21+
Jinja2==2.11.1
2222
jsonschema==2.6.0
23-
Markdown==2.6.11
24-
MarkupSafe==1.0
23+
Markdown==3.1.1
24+
MarkupSafe==1.1.1
2525
numpy==1.17.4
26-
opencv-contrib-python==3.4.3.18
27-
pigpio==1.44
26+
opencv-contrib-python==4.1.1.26
27+
pigpio==1.45
2828
Pillow==7.0.0
29-
protobuf==3.6.1
29+
protobuf==3.11.3
3030
Pypubsub==4.0.0
3131
pytz==2018.4
3232
pyyaml>=4.2b1
3333
pyzbar==0.1.7
34-
requests==2.20.0
35-
six==1.11.0
34+
requests==2.22.0
35+
six==1.14.0
3636
swagger-spec-validator==2.3.1
3737
termcolor==1.1.0
3838
tinydb==3.12.1
39-
tensorflow>=2.0.0
39+
tensorflow==2.1.0
4040
tensorflow_hub>=0.7.0
4141
urllib3==1.24.2
4242
Werkzeug==0.15.3

rotary_encoder/motorencoder.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,50 @@ def adjust_power(self, power):
149149
# releasing lock on motor
150150
self._motor_lock.release()
151151

152+
# CALLBACK
153+
""" The callback function rotary_callback is called on FALLING_EDGE by the
154+
rotary_decoder with a parameter value of 1 (1 new tick)
155+
156+
- Gearbox ratio: 120:1 (1 wheel revolution = 120 motor revolution)
157+
- Encoder ratio: 16:1 encoder ticks for 1 motor revolution
158+
- 1 wheel revolution = 120 * 16 = 1920 ticks
159+
- R = 30mm - 1 wheel revolution = 2πR = 2 * π * 30mm = 188.5mm
160+
- 1920 ticks = 188.5mm
161+
- 1 tick = 0.0981mm
162+
- 1 tick : 0.0981mm = x : 1000mm -> x = 10193 ticks approximately
163+
So 0.0981 is the ticks->distance(mm) conversion coefficient
164+
165+
The callback function calculates current velocity by taking groups of
166+
ticks_threshold ticks"""
167+
168+
# callback function
169+
# it calculates velocity via approssimation
170+
# it doeas a mean on current time passed and actual distance travelled
171+
# NOT USEFUL FOR VELOCITY REGULATION since we need to know the current
172+
# velocity updated each time
173+
def rotary_callback(self, tick):
174+
self._motor_lock.acquire()
175+
176+
# on first movement
177+
if(self._distance == 0):
178+
self._start_timer = time() # clock started
179+
180+
181+
self._ticks += tick # updating ticks
182+
self._distance = self._ticks * 0.0981 # (mm) travelled
183+
184+
self._power = power # setting current power
185+
186+
# adjusting power forward
187+
if (self._direction == 1):
188+
self._pi.set_PWM_dutycycle(self._forward_pin, abs(power))
189+
# adjusting power bacakward
190+
else:
191+
self._pi.set_PWM_dutycycle(self._backward_pin, abs(power))
192+
193+
# releasing lock on motor
194+
self._motor_lock.release()
195+
152196
# CALLBACK
153197
""" The callback function rotary_callback is called on FALLING_EDGE by the
154198
rotary_decoder with a parameter value of 1 (1 new tick)

rotary_encoder/wheelsaxel.py

Lines changed: 10 additions & 8 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)
@@ -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):

start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0 python3 init.py

test/coderbot_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def test_motor_right(self):
3232
self.bot.left(speed=100, elapse=0.1)
3333

3434
def test_motor_move(self):
35-
self.bot.move(speed=100, elapse=0.1, steps=-1)
36-
self.bot.move(speed=-100, elapse=0.1, steps=-1)
35+
self.bot.move(speed=100, elapse=0.1)
36+
self.bot.move(speed=-100, elapse=0.1)
3737

3838
def test_motor_turn(self):
39-
self.bot.turn(speed=100, elapse=0.1, steps=-1)
40-
self.bot.turn(speed=-100, elapse=0.1, steps=-1)
39+
self.bot.turn(speed=100, elapse=0.1)
40+
self.bot.turn(speed=-100, elapse=0.1)
4141

4242
class CoderBotServoMotorTestCase(unittest.TestCase):
4343
def setUp(self):
@@ -58,12 +58,12 @@ def test_motor_right(self):
5858
self.bot.left(speed=100, elapse=0.1)
5959

6060
def test_motor_move(self):
61-
self.bot.move(speed=100, elapse=0.1, steps=-1)
62-
self.bot.move(speed=-100, elapse=0.1, steps=-1)
61+
self.bot.move(speed=100, elapse=0.1)
62+
self.bot.move(speed=-100, elapse=0.1)
6363

6464
def test_motor_turn(self):
65-
self.bot.turn(speed=100, elapse=0.1, steps=-1)
66-
self.bot.turn(speed=-100, elapse=0.1, steps=-1)
65+
self.bot.turn(speed=100, elapse=0.1)
66+
self.bot.turn(speed=-100, elapse=0.1)
6767

6868

6969
class CoderBotSonarTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)