# Importing libraries
import matplotlib.pyplot as plt #this library handles graphs with python
import matplotlib as mpl #this library handles graphs with python
import numpy as np #this library handles equations and general arithmetics
import random #this library handles randomized values that may be used in certains equations
from time import sleep #this library handles statistic who are affected over time and allows certain commands to run with a custom delay
from IPython import display #this library handles displaying arrays of samples
control= 0 #this variable sets the origin of our data in the position 0
angulo_0_X = 0 #this variable handles the origin of the X axis of the data on the graph
angulo_0_Y = 0 #this variable handles the origin of the Y axis of the data on the graph
n=20 #this variable handles the number of values to be inserted within the arrays
#angulo_ref_X = 70 this variable handles the reference values of the angles in the X axis
angulo_ref_Y = 5 #this variable handles the reference values of the angles in the Y axis
angulo_medido_P = [4] * n #this array is used to register the angles measured by the test subject
angulo_medido_C = [4] * n #this array is used to register the angles measured by the control subject
rango_usuario_control = 10 #this variable handles the range of values that the angles are supposed to oscillate within for the control subject
#(+/- 10 degrees)
rango_usuario_prueba = 20 #this variable handles the range of values that the angles are supposed to oscillate within for the test subject
#(+/- 20 degrees)
referencia= [4] * n #this array is used for the reference angle that the device is supposed to be trying to follow
V_max_C= [4] * n #this arrray is used for the maximum value of the range the control subject is supposed to oscillate within
V_min_C= [4] * n #this arrray is used for the minimum value of the range the control subject is supposed to oscillate within
V_max_P= [4] * n #this arrray is used for the maximum value of the range the test subject is supposed to oscillate within
V_min_P= [4] * n #this arrray is used for the minimum value of the range the test subject is supposed to oscillate within
tiempo = np.linspace(0, 8, 20) # this variable is used so that the graph follows certain criteria (from 0 to 8 seconds with a number of 20
#inserted values)
fig, ax = plt.subplots() # this command is used to project a 2D or 3D graph, and the fig and ax criteria is used to divide the data that
#is going to be inserted in said graph (figure, axis)
#these are the functions used to generate the stats that allow the graphs to translate the obtained randomized data to something a bit more appealing
def usuario_prueba(angulo_ref, angulo_0, var_control, angulo_medido, rango): #we generate the test subject function with the proper criteria so it
#can calculate the data for the graph
print(f"Reference Angle on Y: {angulo_ref}") #this command allows us to know where the reference value in the Y axis is curently located
while var_control <= 5: #this while command is used for the first 5 data nodes in which the range of angles oscillates between its origin
#and the reference value
angulo_medido[var_control] = angulo_0 + (random.randint(0, 5)) # This is the line that covers the measured angle (in this case its a
# randomized simulation between a certain range)
#print(f"{angulo_medido[var_control]}") this command is used to print the current value of a measured angle,
#only used for checking the code is actually working
var_control +=1 #everytime the command is done with a node it moves on to the next one, this is done up until the while conditions are met
while var_control < 15: #this while command is used for the next 10 data nodes in which the range of angles oscillates between its
#origin and the reference value
angulo_medido[var_control] = random.randint((angulo_ref-rango),(angulo_ref+rango)) # This is the line that covers the measured angle
#(in this case its a randomized simulation between a certain range)
#print(f"{angulo_medido[var_control]}") this command is used to print the current value of a measured angle,
#only used for checking the code is actually working
var_control +=1 #everytime the command is done with a node it moves on to the next one,
#this is done up until the while conditions are met
while var_control < 20: #this while command is used for the last 5 data nodes in which the range of angles oscillates between its origin
#and the reference value
angulo_medido[var_control] = angulo_0 + (random.randint(0, 5)) # This is the line that covers the measured angle
#(in this case its a randomized simulation between a certain range)
#print(f"{angulo_medido[var_control]}") this command is used to print the current value of a measured angle,
#only used for checking the code is actually working
var_control +=1 #everytime the command is done with a node it moves on to the next one,
#this is done up until the while conditions are met
def usuario_control(angulo_ref, angulo_0, var_control, angulo_medido, rango):
print(f"Reference Angle on X: {angulo_ref}")
while var_control <= 5: #this while command is used for the first 5 data nodes in which the range of angles oscillates between its
#origin and the reference value
angulo_medido[var_control] = angulo_0 + (random.randint(0, 5)) # This is the line that covers the measured angle
#(in this case its a randomized simulation between a certain range)
#print(f"{angulo_medido[var_control]}") this command is used to print the current value of a measured angle,
#only used for checking the code is actually working
var_control +=1 #everytime the command is done with a node it moves on to the next one,
#this is done up until the while conditions are met
while var_control < 15: #this while command is used for the next 10 data nodes in which the range of angles oscillates between its
#origin and the reference value
angulo_medido[var_control] = random.randint((angulo_ref-rango),(angulo_ref+rango)) # This is the line that covers the measured angle
#(in this case its a randomized simulation between a certain range)
#print(f"{angulo_medido[var_control]}") this command is used to print the current value of a measured angle,
#only used for checking the code is actually working
var_control +=1 #everytime the command is done with a node it moves on to the next one, this is done up until the while conditions are met
while var_control < 20: #this while command is used for the last 5 data nodes in which the range of angles oscillates between its
#origin and the reference value
angulo_medido[var_control] = angulo_0 + (random.randint(0, 5)) # This is the line that covers the measured angle
#(in this case its a randomized simulation between a certain range
#print(f"{angulo_medido[var_control]}") this command is used to print the current value of a measured angle,
#only used for checking the code is actually working
var_control +=1 #everytime the command is done with a node it moves on to the next one,
#this is done up until the while conditions are met
def constante(arreglo, var_control, referencia):
while var_control < 20: #This is the line that covers all of the 20 nodes of the reference line
arreglo[var_control]= referencia #This line states that the value for the reference line shall be the constant we established
#within the reference array
#print(f" Posicion: {var_control} valor {arreglo[var_control]}") this command is used to show the current position and value
#of the graphed data
var_control +=1 #everytime the command is done with a node it moves on to the next one,
#this is done up until the while conditions are met
#This section covers the constant values that hold the angle reference line
constante(referencia, control, angulo_ref_Y)
# Control subject parameters: this line allows us to determine what dats is to be inserted in the control subject function that is used
#in the functions above for graphing the data
usuario_control(angulo_ref_Y, angulo_0_Y, control, angulo_medido_C, rango_usuario_control) #the function contains the Y reference angle,
#the origin of the Y position, the general position of origin through time, the measured angle for the control subject,
#and the range of reference for the control subject
#This next two lines of code determine the range of values in regards of the control subject and its angles,
#using the general reference value in Y and adding or substracting the chosen reference value depending of
#which subject we are reviewing (value inserted in line 21)
constante(V_min_C, control, (angulo_ref_Y-rango_usuario_control))
constante(V_max_C, control, (angulo_ref_Y+rango_usuario_control))
# Test subject parameters: this line allows us to determine what dats is to be inserted in the control subject function that is used
#in the functions above for graphing the data
usuario_prueba(angulo_ref_Y, angulo_0_Y, control, angulo_medido_P, rango_usuario_prueba) #the function contains the Y reference angle,
#the origin of the Y position, the general position of origin through time, the measured angle for the test subject,
#and the range of reference for the test subject
#This next two lines of code determine the range of values in regards of the control subject and its angles,
#using the general reference value in Y and adding or substracting the chosen reference value depending of
#which subject we are reviewing (value inserted in line 22)
constante(V_min_P, control, (angulo_ref_Y-rango_usuario_prueba))
constante(V_max_P, control, (angulo_ref_Y+rango_usuario_prueba))
# This is the graph section
plt.suptitle("Behavior Graph on Y Axis: ") #this command covers the tutle of the graph
ax.set_xlabel("Time (Seconds)") #this command covers the label of the X axis of the graph
ax.set_ylabel("Angle (Degrees)") #this command covers the label of the Y axis of the graph
ax.plot(tiempo, referencia, label = 'Reference Angle', marker = '>') #this command covers the plotting part of the general reference value
#with requested plotting values, its label name, and marker
# Control subject graph section
ax.plot(tiempo, angulo_medido_C, label = 'Control Subject', marker = 'o') #this command covers the plotting part of the control subject data
#with its label name, rquested values and marker
ax.plot(tiempo, V_max_C, linestyle = 'dotted', linewidth='3', label = 'V max Control')
#this command covers the maximum range value of the control subject with its requested data, linestyle, width, and label
ax.plot(tiempo, V_min_C, linestyle = 'dotted', linewidth='3', label = 'V min Control')
#this command covers the minimum range value of the control subject with its requested data, linestyle, width, and label
# Test subject graph section
ax.plot(tiempo, angulo_medido_P, label = 'Test Subject', marker = 'o')
#this command covers the plotting part of the test subject data with its label name, rquested values and marker
ax.plot(tiempo, V_max_P, linestyle = 'dotted', linewidth='3', label = 'V max Test')
#this command covers the maximum range value of the test subject with its requested data, linestyle, width, and label
ax.plot(tiempo, V_min_P, linestyle = 'dotted', linewidth='3', label = 'V min Test')
#this command covers the minimum range value of the test subject with its requested data, linestyle, width, and label
ax.legend(loc = 'upper right') #This line covers the location of the graph legend
ax.grid() #This command states that the plotter shall use a grid system
plt.show() #This command tells the system to show the plotter system
print(tiempo) #This command covers the printing of the time variable that the system is using for data gathering