-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReto_QR_Final.py
More file actions
103 lines (93 loc) · 2.55 KB
/
Reto_QR_Final.py
File metadata and controls
103 lines (93 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Reto Quantum Robotics
# Frida Cano Falcón
from random import randrange
from turtle import *
from freegames import vector, square
# or
import turtle
import random
import numpy as np
import math
import time
# Generacion de Coordenadas aleatorias
x = round(random.uniform(-249, 249),2)
y = round(random.uniform(-249, 249),2)
while(x==0 and y== 0): # Revisar si las coordenadas no son en las que ya se encuentra el rover
x = round(random.uniform(-249, 249),2)
y = round(random.uniform(-249, 249),2)
xRound = math.ceil(x)
cor = [x,y]
print("Coordenadas finales: ",cor)
# Variables principales
rX = 0
rY = 0
fX = 0
# Angulo del rover en funcion de la ubicacion en cuadrantes del punto final
if((x>0 and y>0) or (x>0 and y<0)): # I y IV cuadrante
ang = (math.atan(y/x))
fX = 1
if((x<0 and y>0) or (x<0 and y<0)): # II y III cuadrante
ang = (math.pi)+(math.atan(y/x))
fX = -1
if(x==0 and y>0):
ang = 90
if(x==0 and y<0):
ang = -90
if(y==0 and x>0):
ang = 0
if(y==0 and x<0):
ang = 180
# Configuración de rover
rover = turtle.Turtle(shape='turtle')
rover.shapesize(1,1)
rover.setposition(rX,rY) # Posición inicial
rover.settiltangle(math.degrees(0)) # Dirección inicial
# Mapa
def world():
""" Crear el plano
"""
bgcolor('white') # Color del fondo
up()
goto(cor)
dot(5, 'red') # Punto final
# Movimiento del rover
def move(begin):
"""Movimiento del rover
"""
global rX, rY, x, y, xRound
if(begin==1):
#Actualizar angulo en dirección al punto final
rover.settiltangle(math.degrees(ang))
update()
if(x>rX):
mX = rX-x
mY = rY-y
else:
mX = x-rX
mY = y-rY
while(rover.position()!=cor): #Trayectoria
rX = (rX + fX)
rY = ((mY/mX)*(rX)) # Trayectoria basada en la ecuación de línea recta
rover.setposition(rX,rY)
if(rX==xRound):
rX = x
rY = ((mY/mX)*(rX))
rover.setposition(rX,rY)
begin = 0
print("Posicion del rover",rover.position(),math.degrees(ang), "grados")
print("RECORRIDO TERMINADO")
break
time.sleep(0.25)
print("Posicion del rover",rover.position(),math.degrees(ang), "grados")
update()
update()
# Configuración de la pantalla
setup(600,600)
hideturtle()
tracer(False)
title("Rover Autonomous Navigation")
world()
# Tecla que indica cuándo empezar el movimiento
listen()
onkey(lambda: move(1),'Left')
mainloop()