Skip to content

Commit 4bab48e

Browse files
author
Romain Boutrois
committed
[FIX] wheel spin function
1 parent 4242b9d commit 4bab48e

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

elio.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
# Eliobot robot Library
2-
# 2023 ELIO, B3 ROBOTICS
3-
#
4-
# Project home:
5-
# https://eliobot.com
6-
#
7-
8-
#--------------- LIBRARIES IMPORT ---------------#
9-
101
import time
112
import board
123
from digitalio import DigitalInOut, Direction, Pull
@@ -64,7 +55,7 @@
6455
#--------------- INTERNAL VOLTAGES ---------------#
6556

6657
# Measure the battery voltage
67-
def getBatteryVoltage():
58+
def get_battery_voltage():
6859
"""Get the approximate battery voltage."""
6960
# I don't really understand what CP is doing under the hood here for the ADC range & calibration,
7061
# 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():
7667

7768

7869
# Detect if there is a voltage on the USB connector
79-
def getVbusPresent():
70+
def get_vbus_present():
8071
"""Detect if VBUS (5V) power source is present"""
8172
global vbus_sense
8273
return vbus_sense.value
@@ -86,7 +77,7 @@ def getVbusPresent():
8677
#--------------- COLORS ---------------#
8778

8879
# Let the rainbow shine
89-
def rgbColorWheel(wheel_pos):
80+
def rgb_color_wheel(wheel_pos):
9081
"""Color wheel to allow for cycling through the rainbow of RGB colors."""
9182
wheel_pos = wheel_pos % 255
9283

@@ -197,22 +188,29 @@ def motorSlow():
197188
def spinLeftWheelForward(speed):
198189
pwm_value = setSpeed(speed)
199190

191+
BIN1.duty_cycle = 0
200192
BIN2.duty_cycle = pwm_value
201193

202194
# Spin the left wheel backward (0 - 100% speed)
203195
def spinLeftWheelBackward(speed):
204196
pwm_value = setSpeed(speed)
197+
205198
BIN1.duty_cycle = pwm_value
206-
199+
BIN2.duty_cycle = 0
200+
207201
# Spin the right wheel forward (0 - 100% speed)
208202
def spinRightWheelForward(speed):
209203
pwm_value = setSpeed(speed)
204+
205+
AIN1.duty_cycle = 0
210206
AIN2.duty_cycle = pwm_value
211207

212208
# Spin the right wheel backward (0 - 100% speed)
213209
def spinRightWheelBackward(speed):
214210
pwm_value = setSpeed(speed)
211+
215212
AIN1.duty_cycle = pwm_value
213+
AIN2.duty_cycle = 0
216214

217215

218216
# Move the robot forward one step (= approx. 15cm)
@@ -223,7 +221,7 @@ def moveOneStep(speed):
223221
BIN1.duty_cycle = 0
224222
BIN2.duty_cycle = pwm_value
225223
time.sleep(1)
226-
stop()
224+
motorStop()
227225

228226

229227

@@ -281,30 +279,30 @@ def getLine(line_pos):
281279

282280
# Example function to follow a black line on white paper
283281
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)
287285

288286
# Print sensor values
289287
print(sensor1_value, sensor2_value, sensor3_value)
290288

291289
# Line following logic
292-
if get_line(2) < threshold + 1500:
290+
if sensor2_value(2) < threshold + 1500:
293291
# Line detected by middle sensor, move forward
294292
AIN1.duty_cycle = 0
295293
AIN2.duty_cycle = 65535
296294
BIN1.duty_cycle = 0
297295
BIN2.duty_cycle = 65535
298296

299-
elif get_line(0) < threshold - 9500:
297+
elif sensor1_value(0) < threshold - 9500:
300298
# Line detected by left sensor, turn left
301299
AIN1.duty_cycle = 0
302300
AIN2.duty_cycle = 8000
303301
BIN1.duty_cycle = 8000
304302
BIN2.duty_cycle = 0
305303

306304

307-
elif get_line(4) < threshold - 9500:
305+
elif sensor3_value(4) < threshold - 9500:
308306
# Line detected by right sensor, turn right
309307
AIN1.duty_cycle = 8000
310308
AIN2.duty_cycle = 0
@@ -320,3 +318,9 @@ def followLine():
320318

321319
time.sleep(0.1)
322320

321+
322+
323+
324+
325+
326+

0 commit comments

Comments
 (0)