simulation
This commit is contained in:
parent
eac1fa7808
commit
21ec2b425f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
__pycache__/
|
||||
build/
|
31
robot.py
Normal file
31
robot.py
Normal file
@ -0,0 +1,31 @@
|
||||
from math import cos, sin, pi
|
||||
|
||||
class Robot:
|
||||
# position
|
||||
pos=(0,1.5)
|
||||
# orientation
|
||||
rot=pi/2
|
||||
# velocite
|
||||
v=0
|
||||
# velocite angulaire
|
||||
angv=0
|
||||
# velocite des roues (non angulaire)
|
||||
wv=(0.1,0.1)
|
||||
# espace entre les deux roues
|
||||
l=0.1
|
||||
# time
|
||||
t = 0
|
||||
|
||||
def __init__(self):
|
||||
print("yo")
|
||||
|
||||
def update(self, dt):
|
||||
self.t += dt
|
||||
# https://robotics.stackexchange.com/questions/106/what-is-a-suitable-model-for-two-wheeled-robots
|
||||
self.v = 1/2*(self.wv[0]+self.wv[1])
|
||||
self.angv = 1/self.l*(self.wv[1]-self.wv[0])
|
||||
self.rot += self.angv*dt
|
||||
self.pos = (self.pos[0]+self.v*sin(self.rot)*dt,self.pos[1]+self.v*cos(self.rot)*dt)
|
||||
if(self.pos[0]>=10):
|
||||
print(self.t)
|
||||
sys.exit()
|
31
simulateur.py
Normal file
31
simulateur.py
Normal file
@ -0,0 +1,31 @@
|
||||
from robot import Robot
|
||||
|
||||
from math import degrees
|
||||
import sys, pygame
|
||||
from pygame.locals import *
|
||||
pygame.init()
|
||||
|
||||
size = width, height = 1000, 300
|
||||
black = 0, 0, 0
|
||||
|
||||
screen = pygame.display.set_mode(size)
|
||||
|
||||
r = Robot()
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT: sys.exit()
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == K_q:
|
||||
sys.exit()
|
||||
|
||||
screen.fill(black)
|
||||
r.update(1/60)
|
||||
robotShape = pygame.Rect(0,0, 10,20);
|
||||
rsurf = pygame.Surface((10,20)).convert_alpha();
|
||||
pygame.draw.rect(rsurf, (255,255,255), robotShape);
|
||||
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]))
|
||||
pygame.display.flip()
|
||||
|
Loading…
x
Reference in New Issue
Block a user