def tracer_grille(grille, agrandissement, angle, origine): n = 4000 calibre = 0.1 pwm_X = PWM(0) pwm_Y = PWM( 1) # il n'existe que 2 canaux pour implementer les PWMs (0 et 1) pwm_X.export() pwm_Y.export() pwm_X.period = 100000 # les unites sont en nanosecondes, ainsi dans cet exemple la periode vaut 100000*1ns = 100 us pwm_Y.period = 100000 GPIO.setmode( GPIO.BOARD) # On lit les pattes dans l'ordre classique en électronique GPIO.setup(35, GPIO.OUT) # La broche 35 est configurée en sortie ##La fréquence max du lever/baisser de stylo et 4Hz. Donc 250ms. ### Ecriture de la grille for i in range(0, len(grille)): for j in range(0, len(grille[0])): if (grille[i][j] != 0): seq_chiffre = choix(grille[i][j], i, j, agrandissement, angle) x = seq_chiffre[0] y = seq_chiffre[1] haut = seq_chiffre[2] for k in range(0, len(x)): x[k] += origine[0] * calibre y[k] += origine[1] * calibre stylo_haut() for k in range(0, len(x)): if (k != 0): lever_stylo(haut[k], haut[k - 1]) pwm_X.duty_cycle = int(x[k] * pwm_X.period / 3.3) pwm_Y.duty_cycle = int(y[k] * pwm_Y.period / 3.3) pwm_X.enable = True pwm_Y.enable = True stylo_haut() #Lorsque l'on a termine avec la table tracante pwm_X.enable = False # On desactive la PWM pwm_Y.enable = False pwm_X.unexport() pwm_Y.unexport() GPIO.cleanup( ) # A la fin du programme on remet à 0 les broches du Rasberry PI return (0)
def calibrage(): GPIO.setmode( GPIO.BOARD) # On lit les pattes dans l'ordre classique en électronique GPIO.setup(35, GPIO.OUT) # La broche 35 est configurée en sortie pwm_X = PWM(0) pwm_Y = PWM( 1) # il n'existe que 2 canaux pour implementer les PWMs (0 et 1) pwm_X.export() pwm_Y.export() pwm_X.period = 100000 # les unites sont en nanosecondes, ainsi dans cet exemple la periode vaut 100000*1ns = 100 us pwm_Y.period = 100000 GPIO.output(35, GPIO.HIGH) for i in range(0, int(pwm_Y.period / 5)): pwm_Y.duty_cycle = 5 * i pwm_Y.enable = True for i in range(0, int(pwm_X.period / 5)): pwm_X.duty_cycle = 5 * i pwm_X.enable = True for i in range(0, int(pwm_Y.period / 5)): pwm_Y.duty_cycle = pwm_Y.period - 5 * i pwm_Y.enable = True for i in range(0, int(pwm_X.period / 5)): pwm_X.duty_cycle = pwm_X.period - 5 * i pwm_X.enable = True pwm_X.enable = False pwm_Y.enable = False stylo_haut() time.sleep(1) pwm_X.duty_cycle = int(pwm_X.period / 2) pwm_X.enable = True time.sleep(1) camera = picamera.PiCamera() camera.capture('calibrage.jpg') time.sleep(1) pwm_X.enable = False pwm_X.unexport() pwm_Y.unexport() GPIO.cleanup() return 1
import numpy as np from pwm import PWM """### Motor initialization and configuration Motor speed range [0 - stop, 1 - full speed] """ # Enable servo # object for servo MOTOR_BRAKE = 1000000 motor = PWM(0) motor.period = 20000000 motor.duty_cycle = MOTOR_BRAKE motor.enable = True #!! Wait for 3 seconds until the motor stops beeping """# Upon start of device, motor speed must be set to 0 for at least 5 seconds""" motor.duty_cycle = MOTOR_BRAKE + 120000 # Motor should run at low speed motor.duty_cycle = MOTOR_BRAKE + 1000000 # Motor full speed motor.duty_cycle = MOTOR_BRAKE # stop motor """### Servo configuration and calibration Servo angle range [-1 - full left, 0 - center, 1 - full right] * Physical calibration of steering - Mount the motor on the vehicle
from pwm import PWM pwm0 = PWM(0) pwm1 = PWM(1) pwm0.export() pwm1.export() pwm0.period = 20000000 pwm1.period = 20000000 pwm0.duty_cycle = 1000000 pwm0.enable = False pwm1.duty_cycle = 1465000 pwm1.enable = False
from pwm import PWM pwm0 = PWM(0) pwm0.export() pwm0.period = 20000000 pwm0.duty_cycle = 1000000 pwm0.enable = True pwm0.duty_cycle = 1000000
minSpeed = 1000000 # 0 speed zeroRot = 1000000 maxRot = 500000 rot = zeroRot pwm0 = PWM(0) # motor pwm0.export() pwm0.period = 20000000 pwm0.duty_cycle = minSpeed pwm1 = PWM(1) # servo pwm1.export() pwm1.period = 20000000 pwm1.duty_cycle = zeroRot pwm0.enable = True pwm1.enable = True if not debug: print("waiting for moter") sleep(3) print("motor ready") speed = 1200000 if debug: speed = minSpeed pwm0.duty_cycle = speed camera = PiCamera()
# In[5]: '''#hardcoding speed pwm0.duty_cycle = 11000 PWM duty cycle for straightline motion: 1500000 pwm1_ref = 1465000 pwm1.duty_cycle = pwm1_ref''' pwm0 = PWM(0) pwm1 = PWM(1) pwm0.export() pwm1.export() pwm0.period = 20000000 pwm1.period = 20000000 pwm0.duty_cycle = 1000000 pwm1.duty_cycle = 1500000 pwm0.enable = True pwm1.enable = True pwm1_ref = 1465000 pwm1.duty_cycle = pwm1_ref # In[6]: #Setting parameters res = (320, 240) straight_threshold = 30 row = 100 peak_ref = 160 prev_peak_pos = 160 time_th = 0.001 peak_diff_th = 70 peak_diff_th_st = 10 ctr_3peak = 0