This commit is contained in:
leo 2022-11-23 11:48:34 +01:00
parent 260cd60b91
commit ca62e8ef89
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
2 changed files with 8 additions and 3 deletions

View File

@ -24,7 +24,7 @@ class Robot:
# pins reliés au moteurs (bw_l, fw_l, bw_r, fw_r)
motors_pins = ((9,10),(12,11))
# position du spot lumineux
light_pos = (5, 1.5)
light_pos = (9, 1.5)
# ecart entre les deux photores
photores_l = 0.1
# longeur du séparateur entre les photorésistances
@ -66,8 +66,8 @@ class Robot:
self.pr_l = self.PHOTORES_SHADOW
self.pr_r = self.PHOTORES_LIGHT
self.pins[self.pr_l_pin] = 1024 * self.PHOTORES_BRIDGE/(self.pr_l+self.PHOTORES_BRIDGE)
self.pins[self.pr_r_pin] = 1024 * self.PHOTORES_BRIDGE/(self.pr_r+self.PHOTORES_BRIDGE)
self.pins[self.pr_l_pin] = int(1024-1024 * self.PHOTORES_BRIDGE/(self.pr_l+self.PHOTORES_BRIDGE))
self.pins[self.pr_r_pin] = int(1024-1024 * self.PHOTORES_BRIDGE/(self.pr_r+self.PHOTORES_BRIDGE))
def analogWrite(self, pin, dc):

View File

@ -54,9 +54,14 @@ while True:
screen.fill(black)
robotShape = pygame.Rect(20,15, 10,20);
rsurf = pygame.Surface((50,50)).convert_alpha();
# robot
pygame.draw.rect(rsurf, (255,255,255), robotShape);
# heading
pygame.draw.line(rsurf, (255,255,255), (25,25), (25,50))
# dir2light
pygame.draw.line(rsurf, (255,255,255), (25,25), (25+25*sin(r.angle2spot),25+25*cos(r.angle2spot)))
# light
pygame.draw.polygon(screen, (255,255,0), ([100*a for a in r.light_pos],[100*(a+b) for a,b in zip(r.light_pos,(-1,1))],[100*(a+b) for a,b in zip(r.light_pos,(-1,-1))]))
rsurf_r = pygame.transform.rotate(rsurf, degrees(r.rot));
center = rsurf_r.get_rect().center
screen.blit(rsurf_r, (r.pos[0]*100-center[0],r.pos[1]*100-center[1]))