1
- # Eliobot robot Library
2
- # 2023 ELIO, B3 ROBOTICS
3
- #
4
- # Project home:
5
- # https://eliobot.com
6
- #
7
-
8
- #--------------- LIBRARIES IMPORT ---------------#
9
-
10
1
import time
11
2
import board
12
3
from digitalio import DigitalInOut , Direction , Pull
64
55
#--------------- INTERNAL VOLTAGES ---------------#
65
56
66
57
# Measure the battery voltage
67
- def getBatteryVoltage ():
58
+ def get_battery_voltage ():
68
59
"""Get the approximate battery voltage."""
69
60
# I don't really understand what CP is doing under the hood here for the ADC range & calibration,
70
61
# but the onboard voltage divider for VBAT sense is setup to deliver 1.1V to the ADC based on it's
@@ -76,7 +67,7 @@ def getBatteryVoltage():
76
67
77
68
78
69
# Detect if there is a voltage on the USB connector
79
- def getVbusPresent ():
70
+ def get_vbus_present ():
80
71
"""Detect if VBUS (5V) power source is present"""
81
72
global vbus_sense
82
73
return vbus_sense .value
@@ -86,7 +77,7 @@ def getVbusPresent():
86
77
#--------------- COLORS ---------------#
87
78
88
79
# Let the rainbow shine
89
- def rgbColorWheel (wheel_pos ):
80
+ def rgb_color_wheel (wheel_pos ):
90
81
"""Color wheel to allow for cycling through the rainbow of RGB colors."""
91
82
wheel_pos = wheel_pos % 255
92
83
@@ -197,22 +188,29 @@ def motorSlow():
197
188
def spinLeftWheelForward (speed ):
198
189
pwm_value = setSpeed (speed )
199
190
191
+ BIN1 .duty_cycle = 0
200
192
BIN2 .duty_cycle = pwm_value
201
193
202
194
# Spin the left wheel backward (0 - 100% speed)
203
195
def spinLeftWheelBackward (speed ):
204
196
pwm_value = setSpeed (speed )
197
+
205
198
BIN1 .duty_cycle = pwm_value
206
-
199
+ BIN2 .duty_cycle = 0
200
+
207
201
# Spin the right wheel forward (0 - 100% speed)
208
202
def spinRightWheelForward (speed ):
209
203
pwm_value = setSpeed (speed )
204
+
205
+ AIN1 .duty_cycle = 0
210
206
AIN2 .duty_cycle = pwm_value
211
207
212
208
# Spin the right wheel backward (0 - 100% speed)
213
209
def spinRightWheelBackward (speed ):
214
210
pwm_value = setSpeed (speed )
211
+
215
212
AIN1 .duty_cycle = pwm_value
213
+ AIN2 .duty_cycle = 0
216
214
217
215
218
216
# Move the robot forward one step (= approx. 15cm)
@@ -223,7 +221,7 @@ def moveOneStep(speed):
223
221
BIN1 .duty_cycle = 0
224
222
BIN2 .duty_cycle = pwm_value
225
223
time .sleep (1 )
226
- stop ()
224
+ motorStop ()
227
225
228
226
229
227
@@ -281,30 +279,30 @@ def getLine(line_pos):
281
279
282
280
# Example function to follow a black line on white paper
283
281
def followLine ():
284
- sensor1_value = get_line (0 )
285
- sensor2_value = get_line (2 )
286
- sensor3_value = get_line (4 )
282
+ sensor1_value = getLine (0 )
283
+ sensor2_value = getLine (2 )
284
+ sensor3_value = getLine (4 )
287
285
288
286
# Print sensor values
289
287
print (sensor1_value , sensor2_value , sensor3_value )
290
288
291
289
# Line following logic
292
- if get_line (2 ) < threshold + 1500 :
290
+ if sensor2_value (2 ) < threshold + 1500 :
293
291
# Line detected by middle sensor, move forward
294
292
AIN1 .duty_cycle = 0
295
293
AIN2 .duty_cycle = 65535
296
294
BIN1 .duty_cycle = 0
297
295
BIN2 .duty_cycle = 65535
298
296
299
- elif get_line (0 ) < threshold - 9500 :
297
+ elif sensor1_value (0 ) < threshold - 9500 :
300
298
# Line detected by left sensor, turn left
301
299
AIN1 .duty_cycle = 0
302
300
AIN2 .duty_cycle = 8000
303
301
BIN1 .duty_cycle = 8000
304
302
BIN2 .duty_cycle = 0
305
303
306
304
307
- elif get_line (4 ) < threshold - 9500 :
305
+ elif sensor3_value (4 ) < threshold - 9500 :
308
306
# Line detected by right sensor, turn right
309
307
AIN1 .duty_cycle = 8000
310
308
AIN2 .duty_cycle = 0
@@ -320,3 +318,9 @@ def followLine():
320
318
321
319
time .sleep (0.1 )
322
320
321
+
322
+
323
+
324
+
325
+
326
+
0 commit comments