added all the code to use the new laser sensor. Its like 5 lines of code.
This commit is contained in:
parent
11ce0a109b
commit
f3a02c8db3
@ -20,12 +20,8 @@ kit.servo[0].set_pulse_width_range(MIN_PULSE, MAX_PULSE)
|
|||||||
# property angle: float | None
|
# property angle: float | None
|
||||||
# The servo angle in degrees. Must be in the range 0 to actuation_range.
|
# The servo angle in degrees. Must be in the range 0 to actuation_range.
|
||||||
# Is None when servo is disabled.
|
# Is None when servo is disabled.
|
||||||
while True:
|
|
||||||
kit.servo[0].angle = 110
|
kit.servo[0].angle = 90
|
||||||
sleep(1)
|
|
||||||
kit.servo[0].angle = 90
|
|
||||||
sleep(0.1)
|
|
||||||
print("test")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
from csv import excel
|
|
||||||
|
|
||||||
from adafruit_hcsr04 import HCSR04 as hcsr04 # Ultrasound sensor
|
from adafruit_hcsr04 import HCSR04 as hcsr04 # Ultrasound sensor
|
||||||
import board # General board pin mapper
|
import board # General board pin mapper
|
||||||
from adafruit_servokit import ServoKit # Servo libraries for PWM driver board
|
from adafruit_servokit import ServoKit # Servo libraries for PWM driver board
|
||||||
@ -8,10 +6,15 @@ from adafruit_pcf8591.analog_in import AnalogIn # Analogue in pin library
|
|||||||
from adafruit_pcf8591.analog_out import AnalogOut # Analogue out pin library
|
from adafruit_pcf8591.analog_out import AnalogOut # Analogue out pin library
|
||||||
import statistics as st # Mean and median calculations
|
import statistics as st # Mean and median calculations
|
||||||
import csv # CSV handling
|
import csv # CSV handling
|
||||||
from datetime import datetime # Date and time formatting
|
|
||||||
from time import sleep # Sleep/pause
|
from time import sleep # Sleep/pause
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import busio
|
||||||
|
import adafruit_vl6180x
|
||||||
|
|
||||||
|
# laser sensor controls.
|
||||||
|
i2c = busio.I2C(board.SCL, board.SDA)
|
||||||
|
laser = adafruit_vl6180x.VL6180X(i2c)
|
||||||
|
|
||||||
# Variables to control sensor
|
# Variables to control sensor
|
||||||
TRIGGER_PIN = board.D4 # GPIO pin xx
|
TRIGGER_PIN = board.D4 # GPIO pin xx
|
||||||
@ -29,10 +32,10 @@ OFFSET: int = -1
|
|||||||
KIT.servo[0].set_pulse_width_range(MIN_PULSE, MAX_PULSE)
|
KIT.servo[0].set_pulse_width_range(MIN_PULSE, MAX_PULSE)
|
||||||
|
|
||||||
# Variables to control logging.
|
# Variables to control logging.
|
||||||
LOG: bool = True # Log data to files
|
LOG: bool = True # Log data to files
|
||||||
SCREEN: bool = True # Log data to screen
|
SCREEN: bool = True # Log data to screen
|
||||||
DEBUG: bool = False # More data to display
|
DEBUG: bool = False # More data to display
|
||||||
TWIN_MODE: bool = False
|
TWIN_MODE: bool = False # Run in live or twin mode
|
||||||
|
|
||||||
# Control the number of samples for single distance measurement (average from burst)
|
# Control the number of samples for single distance measurement (average from burst)
|
||||||
MAX_SAMPLES: int = 1
|
MAX_SAMPLES: int = 1
|
||||||
@ -114,7 +117,9 @@ def read_distance_sensor():
|
|||||||
while samples != max_samples:
|
while samples != max_samples:
|
||||||
sleep(RUN_TIMEOUT)
|
sleep(RUN_TIMEOUT)
|
||||||
try:
|
try:
|
||||||
distance: float = sonar.distance
|
distance: float = sonar.distance # reading distance from the sonic sensor
|
||||||
|
# distance: float = laser.range * 10 # reading distance from the laser sensor
|
||||||
|
|
||||||
if MIN_DISTANCE < distance < MAX_DISTANCE:
|
if MIN_DISTANCE < distance < MAX_DISTANCE:
|
||||||
|
|
||||||
log_data(data_file="sensor", data_line=str(distance), remark="") if LOG else None
|
log_data(data_file="sensor", data_line=str(distance), remark="") if LOG else None
|
||||||
@ -334,7 +339,6 @@ def servo_slower():
|
|||||||
|
|
||||||
return servo_angle
|
return servo_angle
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("pid-balancer_" + "time_file.txt", "w") as time_file:
|
with open("pid-balancer_" + "time_file.txt", "w") as time_file:
|
||||||
time_file.write(datetime.strftime(datetime.now(), '%Y%m%d%H%M%S.%f')[:-3])
|
time_file.write(datetime.strftime(datetime.now(), '%Y%m%d%H%M%S.%f')[:-3])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user