ANEXOS - Pàgina inicial de UPCommons
Transcript of ANEXOS - Pàgina inicial de UPCommons
ÍNDICE ANEXOS
ANEXO 1: ESPECIFICACIONES SENSOR DE DISTANCIA HC-SR04 ...................................................................1
ANEXO 2: ESPECIFICACIONES ARDUINO NANO........................................................................................... 5
ANEXO 3: ESPECIFICACIONES ESP32 ............................................................................................................9
ANEXO 4: ESPECIFICACIONES GAFAS VR HTC VIVE .....................................................................................13
ANEXO 5: ESPECIFICACIONES GAFAS AR HOLOLENS ..................................................................................17
ANEXO 6: CÓDIGO CARGADO A PLACA ARDUINO NANO, PARA REALIDAD VIRTUAL .................................23
ANEXO 7: CODIGO UNITY EN ENSAYO DE VIGAS ........................................................................................27
ANEXO 8: CODIGO UNITY EN ENSAYO DE PILARES .....................................................................................31
ANEXO 9: CÓDIGO CARGADO EN ESP32, DESARROLLADO EN ARDUINO PARA REALIDAD AUMENTADA ..35
ANEXO 10: CODIGO MATLAB PARA ANÁLISIS ESTRUCTURAL RANGO LINEAL ............................................39
ANEXO 11: CODIGO MATLAB PARA RECEPCIÓN Y ENVÍO DE DATOS.......................................................... 47
ANEXO 12: CODIGO UNITY ENTORNO REALIDAD AUMENTADA .................................................................51
ANEXO 13: CODIGO UNITY ALERTA SEGURIDAD ...................................................................................... ..61
7
A R D U I N O N A N O
ESPECIFICACIONES TÉCNICAS:
Microcontroller ATmega328
Architecture AVR
Operating Voltage 5 V
Flash Memory 32 KB of which 2 KB used by bootloader
SRAM 2 KB
Clock Speed 16 MHz
Analog IN Pins 8
EEPROM 1 KB
DC Current per I/O Pins 40 mA (I/O Pins)
Input Voltage 7-12 V
Digital I/O Pins 22 (6 of which are PWM)
PWM Output 6
Power Consumption 19 mA
PCB Size 18 x 45 mm
Weight 7 g
Product Code A000005
11
E S P 3 2
ESPECIFICACIONES TÉCNICAS: Voltaje de alimentación 3.3V DC (2.7 ~ 3.6V)
Corriente de operación ~ 80mA (Fuente superior a 500mA)
Voltaje lógico (entrades/salidas) 3.3 V
SoC ESP32 (ESP32-D0WDQ6)
CPU Dual Core Tensilica LX6 (32bit)
Frecuencia de Reloj 240 MHz
SRAM 520KB
Memoria Flash Externa 4 MB
Pinea Digitales GPIO 34 (incluyendo todos los periféricos)
UART 2
SPI 3
I2C 2
Capacitive Touch sensors 10
Interfaz SD
Timers 3 (16 bit)
PWM Led 16 canales independientes (16 bits)
ADC 2 (12-bit)
DAC 2 (8-bit)
Bluetooth, Protocolos V4.2 BR/EDR and BLE specification
Bluetooth, Radios NZIF receiver with -97 dBm sensitivity, Class-1, class-2 and
class-3 transmitter, AFH
Bluetooth, Audio CVSD and SBC
Stack de Protocolo TCP/IP integrado
Wi-Fi, Protocolo 802.11 b/g/n/e/i (802.11n up to 150 Mbps)
Wi-Fi, certificación RF FCC/CE/IC/TELEC/KCC/SRRC/NCC
Wi-Fi, rango de Frecuencia 2.4 ~ 2.5 GHz
Wi-Fi mode Station/SoftAP/SoftAP+Station/P2P
Wi-Fi Security WPA/WPA2/WPA2-Enterprise/WPS
Network protocols IPv4, IPv6, SSL, TCP/UDP/HTTP/FTP/MQTT
15
H T C V I V E
Especificaciones mínimas del ordenador donde se van a conectar:
- Tarjeta gráfica NVIDIA GeForce GTX 1060, equivalente o superior.
- Procesador Intel Core i5-4590, equivalente o superior
- Memoria RAM de 4GB o más.
- Salida de video HDMI 1.4, DisplatPort 1.2 o más actual.
- Puertos USB 1xUSB 2.0. o mejor
- Sistema operativo Windows 7 SP1, Windows 8.1., Windows 10.
Especificaciones de las gafas:
- Pantalla Dual AMOLED 3.6” diagonal
- Resolución de 1080x1200 pixeles por ojo (2160x1200 pixeles combinado)
- Frecuencia de actualización: 90Hz
- Campo de visualización: 110 grados.
- Funciones de seguridad: Límites del área d juego y cámara frontal.
- Sensores: SteamVR tracking, G-sensor, giroscopio, proximidad
- Conexiones: HDMI, USB 2.0.
- Micrófono integrado
- Uso por carga: 6 horas aproximadamente
Requisitos del área:
- No existen espacios mínimos
- Dimensiones de la habitación: mínimo 2x1.52m, máximo 5m entre
estaciones base
16
El uso de estas gafas, incluye las siguientes herramientas:
- Casco
- Dos controles inalámbricos
- 2 estaciones base
- Auriculares (En su caso)
- Cables, cargadores, etc.
19
M I C R O S O F T H O L O L E N S
Device Specifications: Optics
See-through holographic lenses (waveguides)
2 HD 16:9 light engines
Automatic pupillary distance calibration
Holographic Resolution: 2.3M total light points
Holographic Density: >2.5k radiants (light points per radian)
Sensors
1 IMU
4 environment understanding cameras
1 depth camera
1 2MP photo / HD video camera
Mixed reality capture
20
4 microphones
1 ambient light sensor
Human Understanding
Spatial sound
Gaze tracking
Gesture input
Voice support
Input / Output / Connectivity
Built-in speakers
Audio 3.5mm jack
Volume up/down
Brightness up/down
Power button
Battery status LEDs
Wi-Fi 802.11ac
Micro USB 2.0
Bluetooth 4.1 LE
Power
Battery Life
2-3 hours of active use
Up to 2 weeks of standby time
Fully functional when charging
Passively cooled (no fans)
Processors
Intel 32 bit architecture with TPM 2.0 support
Custom-built Microsoft Holographic Processing Unit (HPU 1.0)
21
Weight
579g
Memory
64GB Flash
2GB RAM
What's in the box?
HoloLens Development Edition
Clicker
Carrying case
Charger and cable
Microfiber cloth
Nose pads
Overhead strap
OS and Apps
Windows 10
Windows Store
Holograms
Microsoft Edge
Photos
Settings
Windows Feedback
Calibration
Learn Gestures
What you need to develop
Windows 10 PC able to run the latest compatible versions of Visual Studio
and Unity
Safety Eyewear
HoloLens has been tested and found to conform to the basic impact protection
requirements of ANSI Z87.1, CSA Z94.3 and EN 166
25
const int EchoPin = 5; const int TriggerPin = 6; const int LedPin = 13; void setup() { Serial.begin(9600); pinMode(LedPin, OUTPUT); pinMode(TriggerPin, OUTPUT); pinMode(EchoPin, INPUT); } void loop() { int cm = ping(TriggerPin, EchoPin); Serial.write(cm); delay(20); } int ping(int TriggerPin, int EchoPin) { long duration, distanceCm; digitalWrite(TriggerPin, LOW); delayMicroseconds(4); digitalWrite(TriggerPin, HIGH); delayMicroseconds(10); digitalWrite(TriggerPin, LOW); duration = pulseIn(EchoPin, HIGH); distanceCm = duration * 10 / 292/ 2; return distanceCm; }
29
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; public class viga : MonoBehaviour { public GameObject Fragmento1; public float DistanciaSensor; public float Escala; GameObject FragmentoClon1; SerialPort sp = new SerialPort("COM3", 9600); //Coincidir con Arduino void Start() { sp.Open(); sp.ReadTimeout = 10; } void Update() { if (sp.IsOpen) { try { MoveObject(sp.ReadByte()); print(sp.ReadByte()); } catch (System.Exception) { } } } void MoveObject(float dim1) { float dim = (DistanciaSensor - dim1) / 100; print(dim); float x = 0; float dy; float a = 0.5f; float L = 1.5f; for (int i = 0; i <= 200; i++) { x = x + 0.0075f; if (x <= 0.5) { dy = (4*dim*x*(3*a*L-3*a*a-x*x)/(3*a*L*L-4*a*a*a))*Escala;
FragmentoClon1 = Instantiate(Fragmento1, new Vector3(x, 0.8f-dy, 0), Quaternion.identity);
Destroy(FragmentoClon1, 0.06f); }
30
if (x > 0.5 && x <= 1) { dy = (4 * dim * a * (3 * L * x - 3 * x * x - a * a) / (3 * a * L * L - 4 * a * a * a)) * Escala; FragmentoClon1 = Instantiate(Fragmento1, new Vector3(x, 0.8f - dy, 0), Quaternion.identity); Destroy(FragmentoClon1, 0.06f); } if (x > 1) { dy = (4 * dim * (L - x) * (3 * a * L - 3 * a * a - (L - x) * (L - x)) / (3 * a * L * L - 4 * a * a * a)) * Escala; FragmentoClon1 = Instantiate(Fragmento1, new Vector3(x, 0.8f - dy, 0), Quaternion.identity); Destroy(FragmentoClon1, 0.06f); } } } }
33
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports; public class Columna2 : MonoBehaviour { public GameObject Fragmento1; public float DistanciaSensor; public float Escala; GameObject FragmentoClon1; SerialPort sp = new SerialPort("COM3", 9600); //Coincidir con Arduino void Start() { sp.Open(); sp.ReadTimeout = 10; } void Update() { if (sp.IsOpen) { try { MoveObject(sp.ReadByte()); print(sp.ReadByte()); } catch (System.Exception) { } } } void MoveObject(float dim1) { float flecha = (DistanciaSensor - dim1) / 100; print(flecha); float y = 0; float dz; float L = 1.5f; for (int i = 0; i <= 200; i++) { y = y + 0.0075f; dz = (flecha* Mathf.Sin(Mathf.PI*y/L)) * Escala; FragmentoClon1 = Instantiate(Fragmento1, new Vector3(-4, 0.3f + y, -3 + dz), Quaternion.identity); Destroy(FragmentoClon1, 0.06f); }
} }
37
#include "WiFi.h" #include "aREST.h" aREST rest = aREST(); const int EchoPin = 5; const int TriggerPin = 4; const int LedPin = 13; int cm,resp; String Reacciones; WiFiServer server(80); // Replace with your network credentials const char* ssid = "my_iphone"; const char* password = "delunoalocho"; int distFunction(String command) { Serial.println("Received rest request"); cm=0; for (int c=0; c<20;c++) { cm = ping(TriggerPin, EchoPin)+ cm; delay(40); } resp = cm / 20; Serial.println(resp); return resp; } int saveFunction(String command) { Reacciones = command; return 1; } void setup() { pinMode(TriggerPin, OUTPUT); pinMode(EchoPin, INPUT); Serial.begin(115200); rest.function("dist", distFunction); rest.function("save", saveFunction); rest.variable("reacciones", &Reacciones);
38
WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected with IP: "); Serial.println(WiFi.localIP()); server.begin(); } void loop() { delay(200); //Serial.println("loop "); WiFiClient client = server.available(); if (client) { Serial.println("new client "); if (client.available()) { rest.handle(client); } } } int ping(int TriggerPin, int EchoPin) { long duration, distanceCm; digitalWrite(TriggerPin, LOW); delayMicroseconds(4); digitalWrite(TriggerPin, HIGH); delayMicroseconds(10); digitalWrite(TriggerPin, LOW); duration = pulseIn(EchoPin, HIGH); distanceCm = duration * 10 / 292 / 2; return distanceCm; }
41
function REACCIONES = lineal10(dist)
%PROGRAMA QUE CALCULA REACCIONES EN LOS SOPORTES Y FUERZA HORIZONTAL
APLICADA A PORTICO 2D POR EL MÉTODO DE RIGIDEZ
%INTRODUCIR LOS DATOS DE ENTRADA:
Escala=0.02;
Dist_sensor=30; %Distancia inicial sensor [cm]
L1=4; %Longitud viga[m]
H=2; %Altura portico [m]
E1=200000000; %Mod. Elasticidad [kN/m2]
%Sección RHS 100x80x4
A1=0.00132; %Area elemento 1 [m2]
A2=0.00132; %Area elemento 2 [m2]
A3=0.00132; %Area elemento 3[m2]
I1=0.00000186; %Inercia elemento 1 [m4]
I2=0.00000186; %Inercia elemento 2 [m4]
I3=0.00000186; %Inercia elemento 3 [m4]
%Carga vertical
Pv=10; %Carga vertical [kN]
a1=0.80; %[m] Posicion carga vertical desde extremo izquierdo
asumiendo simetria con la otra carga vertical [m]
%DISTANCIA DE ENTRADA EN CENTIMETROS, SE DEBE CONVERTIR A METROS Y A
DESPLAZAMIENTO:
desp=(Dist_sensor-dist)/100;
k=zeros(6);
%VECTOR DE DESPLAZAMIENTOS CONOCIDOS%
DC=[0;0;0;0;0;0];
%NÚMERO DE GRADOS DE LIBERTAD%
GL=12;
KT=zeros(GL);
%NÚMERO DE ELEMENTOS%
i=3;
xN=[0;0;L1];
yN=[0;H;H];
xF=[0;L1;L1];
yF=[H;H;0];
%NÚMERO DE DESPLAZAMIENTOS DESCONOCIDOS%
d=6;
%NÚMERO DE CARGAS CONOCIDAS%
fu=6;
dceros=zeros(1,GL-d);
%CARGAS EN APOYOS%
CA=[0;0;0;0;0;0];
%NUMERACION CARGAS EN APOYOS%
NUM=[7;8;9;10;11;12];
42
%LONGITUDES BARRAS%
L=[H;L1;H];
%MÓDULO DE ELASTICIDAD%
E=[E1;E1;E1];
%ÁREA DE LA SECCIÓN TRANSVERSAL%
A=[A1;A2;A3];
%INERCIA EN Z%
Iz=[I1;I2;I3];
%NUMERACION
Nx=[7;1;4];
Ny=[8;2;5];
Rzi=[9;3;6];
Fx=[1;4;10];
Fy=[2;5;11];
Rzj=[3;6;12];
%OBTENCIÓN DE MATRIZ DE RIGIDEZ GLOBAL DEL ELEMENTO%
for n=1:i
k(1,1)=((A(n,1)*E(n,1)))/L(n,1);
k(1,2)=0;
k(1,3)=0;
k(1,4)=-((A(n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,2);
K(Rzj(n,1),Rzi(n,1))=k(6,3);
K(Rzj(n,1),Fx(n,1))=k(6,4);
K(Rzj(n,1),Fy(n,1))=k(6,5);
K(Rzj(n,1),Rzj(n,1))=k(6,6);
KT=K+KT;
End
%MATRIZ DE RIGIDEZ DE LA ESTRUCTURA
KT;
%SUBMATRIZ K11
K11=KT(1:d,1:d);
%SUBMATRIZ K12
K12=KT(1:d,d+1:GL);
%SUBMATRIZ K21
K21=KT(d+1:GL,1:d);
%SUBMATRIZ K22
K22=KT(d+1:GL,d+1:GL);
%VECTOR DE CARGAS CONOCIDAS%
P1x1=0.5;
p1y=-Pv;
p1z=-Pv*a1*(L1-a1)/L1;
p2x=0;
p2y=-Pv;
p2z=Pv*a1*(L1-a1)/L1;
CC=[P1x1;p1y;p1z;p2x;p2y;p2z];
DD=(K11)\(CC-(K12*DC));
D1=DD(1,1);
P1x2=0.6;
CC=[P1x2;p1y;p1z;p2x;p2y;p2z];
DD=(K11)\(CC-(K12*DC));
D2=DD(1,1);
P1x=((P1x2-P1x1)*(desp-D2)/(D2-D1))+P1x2;
CC=[P1x;p1y;p1z;p2x;p2y;p2z];
DD=(K11)\(CC-(K12*DC));
P=CC(1,1)
desplazamientos=[DD;DC];
despcm=desplazamientos*100;
%CARGAS DESCONOCIDAS
CD=(K21*DD)+(K22*DC);
%REACCIONES EN LOS APOYOS
REAC=CD-CA(1:GL-d,1);
45
FB=[0 0 0 Pv -P -P*a1*(L1-a1)/L1;Pv -P -P*a1*(L1-a1)/L1 0 -P
P*a1*(L1-a1)/L1;0 -P P*a1*(L1-a1)/L1 0 0 0];
for m=1:i
g=m;
dp=[desplazamientos(Nx(m,1),1);desplazamientos(Ny(m,1),1);desplazami
entos(Rzi(m,1),1);desplazamientos(Fx(m,1),1);desplazamientos(Fy(m,1)
,1);desplazamientos(Rzj(m,1),1)];
Fbarglob(:,g)=KB((m*6)-5:6*m,1:6)*dp;
Fbar(:,g) = R((m*6)-5:6*m,1:6)'*KB((m*6)-5:6*m,1:6)*dp;
End
%FUERZAS BARRAS EN EJES GLOBALES
Fbarglob;
%MOMENTOS PARA DIAGRAMA
M3=-Fbarglob(6,1);
M4=-Fbarglob(3,3);
M5=-REAC(3,1)-REAC(1,1)*H+REAC(2,1)*a1;
M6=-REAC(3,1)-REAC(1,1)*H+REAC(2,1)*(L1-a1)-Pv*(L1-2*a1);
REACCIONES=[REAC;P;desp*100;M3;M4;M5;M6;Pv;Escala];
REACCIONES=round([REACCIONES],2);
49
dist_ant=0;
while(1)
fullURL = 'http://172.20.10.9/dist';
saveURL = 'http://172.20.10.9/save?reac=';
try
jdist=webread(fullURL);
dist_ant = jdist;
catch exception
jdist = dist_ant;
disp('Error')
end
d= jdist.return_value;
R=lineal10(d)
jreac=jsonencode(R);
save_all = strcat(saveURL,jreac);
url = webread(save_all);
disp(save_all);
pause(5);
end
53
using System.Collections; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI;
public class cliente1 : MonoBehaviour { public LineRenderer Mlinea1; public LineRenderer Mlinea2; public LineRenderer Mlinea3; public LineRenderer Clinea1; public LineRenderer Clinea2; public LineRenderer Clinea3; public LineRenderer Alinea1; public LineRenderer Alinea2; public LineRenderer Alinea3; public GameObject Origen1; public GameObject Origen2; public GameObject Origen3; public GameObject Origen4; public GameObject OrigenP1; public GameObject OrigenP2; bool flagM = true; bool flagC = true; bool flagA = true; public Point point1; public Point point2; public Text X1; public Text Y1; public Text Z1; public Text X2; public Text Y2; public Text Z2; public Text Ph; public Text d; public Text M1; public Text M2; public Text M3; public Text M4; public Text M5; public Text M6; public Text M7; public Text M8; public Text V1t; public Text V2t; public Text V3t; public Text V4t; public Text V5t;
54
public Text A1t; public Text A2t; public Text A3t; public Text Pv1text; public Text Pv2text; float M1v; float M2v; float M3v; float M4v; float M5v; float M6v; float M7v; float M8v; float V1; float V2; float V3; float V4; float V5; float A1; float A2; float A3; float Pv; float Escala; void Start() { StartCoroutine(RequestReacciones()); } void Update() { if (point1 != null && point2 != null) { M1v = (float)point1.Z; M2v = (float)point2.Z; M3v = (float)point1.M1; M4v = (float)point2.M1; M5v = (float)point1.M2; M6v = (float)point2.M2; M7v = (float)point1.M1 * (-1.0f); M8v = (float)point2.M1; V1 = (float)point1.X; V2 = (float)point1.Y * (-1.0f); V5 = (float)point2.X; V3 = Pv - (float)point1.Y; V4 = (float)point2.Y; A1 = (float)point1.Y * (-1.0f); A2 = (float)point2.X; A3 = (float)point2.Y * (-1.0f);
55
Pv= (float)point1.PV; Escala =(float)point2.PV; Pv1text.text = "Pv =" + Pv + "kN"; Pv2text.text = "Pv =" + Pv + "kN"; Vector3 Coord_Origen1 = Origen1.transform.position; Vector3 Coord_Origen2 = Origen2.transform.position; Vector3 Coord_Origen3 = Origen3.transform.position; Vector3 Coord_Origen4 = Origen4.transform.position; Vector3 Coord_OrigenP1 = OrigenP1.transform.position; Vector3 Coord_OrigenP2 = OrigenP2.transform.position; if (flagM == true) { M1.text = Z1.text; M2.text = Z2.text; M3.text = point1.M1.ToString() + " kN*m"; M4.text = point2.M1.ToString() + " kN*m"; M5.text = point1.M2.ToString() + " kN*m"; M6.text = point2.M2.ToString() + " kN*m"; M7.text = M7v.ToString() + " kN*m"; M8.text = M4.text; Mlinea1.SetPosition(0, new Vector3(Coord_Origen1[0],Coord_Origen1[1],Coord_Origen1[2])); Mlinea1.SetPosition(1, new Vector3(Coord_Origen1[0]-M1v*Escala,Coord_Origen1[1],Coord_Origen1[2])); Mlinea1.SetPosition(2, new Vector3(Coord_Origen2[0]-M3v*Escala,Coord_Origen2[1],Coord_Origen2[2])); Mlinea1.SetPosition(3, new Vector3(Coord_Origen2[0],Coord_Origen2[1],Coord_Origen2[2])); Mlinea2.SetPosition(0, new Vector3(Coord_Origen2[0],Coord_Origen2[1],Coord_Origen2[2])); Mlinea2.SetPosition(1, new Vector3(Coord_Origen2[0],Coord_Origen2[1]+M7v*Escala,Coord_Origen2[2])); Mlinea2.SetPosition(2, new Vector3(Coord_OrigenP1[0],Coord_OrigenP1[1]+M5v*Escala,Coord_OrigenP1[2])); Mlinea2.SetPosition(3, new Vector3(Coord_OrigenP2[0],Coord_OrigenP2[1]+M6v*Escala,Coord_OrigenP2[2])); Mlinea2.SetPosition(4, new Vector3(Coord_Origen3[0],Coord_Origen3[1]+M8v*Escala,Coord_Origen3[2])); Mlinea2.SetPosition(5, new Vector3(Coord_Origen3[0], Coord_Origen3[1], Coord_Origen3[2])); Mlinea3.SetPosition(0, new Vector3(Coord_Origen3[0],Coord_Origen3[1],Coord_Origen3[2])); Mlinea3.SetPosition(1, new Vector3(Coord_Origen3[0]-M4v*Escala,Coord_Origen3[1],Coord_Origen3[2])); Mlinea3.SetPosition(2, new Vector3(Coord_Origen4[0]-M2v*Escala,Coord_Origen4[1],Coord_Origen4[2])); Mlinea3.SetPosition(3, new Vector3(Coord_Origen4[0],Coord_Origen4[1],Coord_Origen4[2])); } else { M1.text = " "; M2.text = " "; M3.text = " "; M4.text = " "; M5.text = " "; M6.text = " "; M7.text = " "; M8.text = " "; }
56
if (flagC == true) { V1t.text = V1.ToString() + " kN"; V2t.text = V2.ToString() + " kN"; V3t.text = V3.ToString() + " kN"; V4t.text = V4.ToString() + " kN"; V5t.text = V5.ToString() + " kN"; Clinea1.SetPosition(0, new Vector3(Coord_Origen1[0], Coord_Origen1[1], Coord_Origen1[2])); Clinea1.SetPosition(1, new Vector3(Coord_Origen1[0]+V1*Escala, Coord_Origen1[1], Coord_Origen1[2])); Clinea1.SetPosition(2, new Vector3(Coord_Origen2[0]+V1*Escala, Coord_Origen2[1], Coord_Origen2[2])); Clinea1.SetPosition(3, new Vector3(Coord_Origen2[0], Coord_Origen2[1], Coord_Origen2[2])); Clinea2.SetPosition(0, new Vector3(Coord_Origen2[0],Coord_Origen2[1], Coord_Origen2[2])); Clinea2.SetPosition(1, new Vector3(Coord_Origen2[0],Coord_Origen2[1]-V2*Escala, Coord_Origen2[2])); Clinea2.SetPosition(2, new Vector3(Coord_OrigenP1[0],Coord_Origen2[1]-V2*Escala,Coord_OrigenP1[2])); Clinea2.SetPosition(3, new Vector3(Coord_OrigenP1[0],Coord_OrigenP1[1]-V3*Escala,Coord_OrigenP1[2])); Clinea2.SetPosition(4, new Vector3(Coord_OrigenP2[0],Coord_OrigenP2[1],Coord_OrigenP2[2])); Clinea2.SetPosition(5, new Vector3(Coord_OrigenP2[0],Coord_OrigenP2[1]-V4*Escala,Coord_OrigenP2[2])); Clinea2.SetPosition(6, new Vector3(Coord_Origen3[0], Coord_OrigenP2[1]-V4*Escala, Coord_Origen3[2])); Clinea2.SetPosition(7, new Vector3(Coord_Origen3[0], Coord_Origen3[1], Coord_Origen3[2])); Clinea3.SetPosition(0, new Vector3(Coord_Origen3[0], Coord_Origen3[1], Coord_Origen3[2])); Clinea3.SetPosition(1, new Vector3(Coord_Origen3[0]+V5*Escala, Coord_Origen3[1], Coord_Origen3[2])); Clinea3.SetPosition(2, new Vector3(Coord_Origen4[0]+V5*Escala, Coord_Origen4[1], Coord_Origen4[2])); Clinea3.SetPosition(3, new Vector3(Coord_Origen4[0],Coord_Origen4[1],Coord_Origen4[2])); } else { V1t.text = " "; V2t.text = " "; V3t.text = " "; V4t.text = " "; V5t.text = " "; } if (flagA == true) { A1t.text = A1.ToString() + " kN"; A2t.text = A2.ToString() + " kN"; A3t.text = A3.ToString() + " kN"; Alinea1.SetPosition(0, new Vector3(Coord_Origen1[0], Coord_Origen1[1], Coord_Origen1[2])); Alinea1.SetPosition(1, new Vector3(Coord_Origen1[0]+A1*Escala, Coord_Origen1[1], Coord_Origen1[2])); Alinea1.SetPosition(2, new Vector3(Coord_Origen2[0]+A1*Escala, Coord_Origen2[1], Coord_Origen2[2])); Alinea1.SetPosition(3, new Vector3(Coord_Origen2[0], Coord_Origen2[1], Coord_Origen2[2])); Alinea2.SetPosition(0, new Vector3(Coord_Origen2[0],Coord_Origen2[1], Coord_Origen2[2])); Alinea2.SetPosition(1, new Vector3(Coord_Origen2[0],Coord_Origen2[1]-A2*Escala, Coord_Origen2[2])); Alinea2.SetPosition(2, new Vector3(Coord_Origen3[0], Coord_Origen3[1]-A2*Escala, Coord_Origen3[2])); Alinea2.SetPosition(3, new Vector3(Coord_Origen3[0], Coord_Origen3[1], Coord_Origen3[2]));
57
Alinea3.SetPosition(0, new Vector3(Coord_Origen3[0], Coord_Origen3[1], Coord_Origen3[2])); Alinea3.SetPosition(1, new Vector3(Coord_Origen3[0]+A3*Escala,Coord_Origen3[1], Coord_Origen3[2])); Alinea3.SetPosition(2, new Vector3(Coord_Origen4[0]+A3*Escala,Coord_Origen4[1], Coord_Origen4[2])); Alinea3.SetPosition(3, new Vector3(Coord_Origen4[0], Coord_Origen4[1], Coord_Origen4[2])); } else { A1t.text = " "; A2t.text = " "; A3t.text = " "; } X1.text = point1.X.ToString() + " KN"; Debug.Log(point1.X); Y1.text = point1.Y.ToString() + " KN"; Debug.Log(point1.Y); Z1.text = point1.Z.ToString() + " KN*m"; Debug.Log(point1.Z); X2.text = point2.X.ToString() + " KN"; Debug.Log(point2.X); Y2.text = point2.Y.ToString() + " KN"; Debug.Log(point2.Y); Z2.text = point2.Z.ToString() + " KN*m"; Debug.Log(point2.Z); Ph.text = point1.D.ToString() + " KN"; Debug.Log(point1.D); d.text = point2.D.ToString() + " cm"; Debug.Log(point2.D); } } IEnumerator RequestReacciones() { while (true) { var request = UnityWebRequest.Get("http://172.20.10.9/reacciones"); yield return request.SendWebRequest(); if (request.isNetworkError) { Debug.Log("Error While Sending: " + request.error); } else { parseResponse(request.downloadHandler.text); } yield return new WaitForSeconds(3.0f); var lineas = GameObject.FindGameObjectsWithTag("Lines"); foreach (var l in lineas) { Destroy(l); } } }
58
private void parseResponse(string response) { Debug.Log("Received: " + response); var reacciones = JsonUtility.FromJson<Reacciones>(response); reacciones.reacciones = reacciones.reacciones.Replace("[", "").Replace("]", ""); var puntos = reacciones.reacciones.Split(','); point1 = new Point {X=double.Parse(puntos[0]), Y=double.Parse(puntos[1]), Z=double.Parse(puntos[2]), D=double.Parse(puntos[6]), M1=double.Parse(puntos[8]), M2=double.Parse(puntos[10]), PV=double.Parse(puntos[12])}; point2 = new Point { X=double.Parse(puntos[3]), Y=double.Parse(puntos[4]), Z=double.Parse(puntos[5]), D=double.Parse(puntos[7]), M1=double.Parse(puntos[9]), M2=double.Parse(puntos[11]), PV=double.Parse(puntos[13])}; } public void DMFON() { flagM = true; } public void DMFOFF() { flagM = false; } public void DCON() { flagC = true; } public void DCOFF() { flagC = false; } public void DAON() { flagA = true; } public void DAOFF() { flagA = false; } } [System.Serializable] internal class Reacciones { public string reacciones; }
59
public class Point { public double X { get; set; } public double Y { get; set; } public double Z { get; set; } public double D { get; set; } public double M1 { get; set; } public double M2 { get; set; } public double PV { get; set; } }
63
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScriptAlert : MonoBehaviour { public GameObject SeñalPeligro; public GameObject EfectoPeligro; private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "MainCamera") { SeñalPeligro.SetActive(true); EfectoPeligro.SetActive(true); } } private void OnTriggerExit(Collider other) { if (other.gameObject.tag == "MainCamera") { SeñalPeligro.SetActive(false); EfectoPeligro.SetActive(false); } } }