Académique Documents
Professionnel Documents
Culture Documents
Se debe entregar al delgado el informe del prootipo físico y virtual se sugiere el siguiente
formato de calificación
UNIVERSIDAD NACIONAL
DE SAN AGUSTIN
ESCUELA PROFESIONAL
DE INGENIERIA
INDUSTRIAL
CURSO AUTOMATIZACION INDUSTRIAL
NRO INTEGRANTESS
1 ALUMNO 1
2 ALUMNO2
3 ALUMNO 3
4 ALUMNO 4
5 ALUMNO 5
Nota Nota
PRACTICA1 Prototipo Virtual pv Pf
simular circuitos de control con
instrumentos de medición en
Proteus
informe en word ( es en otro
archivo . Digital)
justificacion d ela notas
Nota Nota
PRACTICA 2 Prototipo Virtual pv Pf
simular circuitos de control con
instrumentos de medición en
Proteus
informe en word ( es en otro
archivo . Digital)
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca -2-
LISTA DE PRACTICAS
Practica1. Cicruito electrónico con instrumentos de medida
Practica 2 hacer funcionar el blink
Practica3 comunicación serial con arduino que tiene las siguientes tareas
TAREA 1.
Prototipo Virtual. simular circuitos de control con instrumentos de medición en Proteus (
por esta vez será en grupo por que no hay laboratorio pero se hara preguntas individuales
pag 33 pag 1
Uando la ley de OHM verifique los voltajes , la resistencia del led, y la caída de la tensión
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca -4-
2.772
intensidad 5 0.0126
396.825397
segunda manera de calcular la
resistencia
R V 177.777778
I
Agregue una resistencia variable mueva la resistencia el cambio del brillo del led
Objetivo. Simular el funcionamiento del arduino en forma virtual con proteus y en forma
física . realizando el ejercicio básico del blink
//Leer una entrada digital y mostrar por la pantalla del computador (consola serial) el estad
o del pulsador cuando es oprimido */
int boton=2; //Pin donde se encuentra el pulsador, entrada
int led =13;
void setup() // Se ejecuta cada vez que el Arduino se inicia
{
pinMode(boton,INPUT); //Configurar el boton como una entrada
pinMode(led,OUTPUT); //Configurar el boton como una entrada
Serial.begin(9600); //Inicia comunicación serial
}
void loop() // Esta funcion se mantiene ejecutando
{ // cuando este energizado el Arduino
//Guardar en una variable entera el valor del boton 0 ó 1
int estado = digitalRead(boton);
digitalWrite(led,estado);
switch(estado)
{ case 0: Serial.println('A'); break;
case 1: Serial.println('B'); break;
}
delay(10); //Retardo para la visualización de datos en la consola
}
Para probar el envio de la señal de Arduino al monitor serial presione o apague el boton
simulado en proteus y vera que envia la letra A o la letra B por el monitor serial.
En HMI ver como Prender un foco desde visual basic
Diseño en proteus
CODIGO EN ARDUINO
char Cadena[10]="R123";
char dato;
char letra;
int nro,i;
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca -7-
int Rojo=11;
int Verde=10;
int Azul=9;
int valor=0;
void setup() {
pinMode(Rojo,OUTPUT);//D
pinMode(Verde,OUTPUT);//D
pinMode(Azul,OUTPUT);//D
Serial.begin(9600);
}
void loop()
{ i=0;
if (Serial.available() > 0)
{ valor=1;
while (Serial.available() > 0)
{
dato= Serial.read();
delay(5);
if (i==0 )
letra=dato;
else
Cadena[i-1]=dato;
i++;
}
Cadena[i-1]='\n';
Serial.println(Cadena);
nro = ato******************i(Cadena) ;
i=0;
}
if (valor==1)
{
Serial.print(letra);
Serial.println(Cadena);
switch(letra)
{ case 'R': analogWrite(Rojo, nro); break;
case 'V': analogWrite(Verde, nro); break;
case 'A': analogWrite(Azul, nro); break;
}
delay(10);
valor=0;
}
}
Si usted escribe por Ejemplo V234 se prende el led verde a esa intensidad ,
El Codigo de Arduino es
El Resultado es
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca -9-
Tarea1. Pasar información digital del exterior digital del exterior al arduino con HMI
visual Basic
Prender un led desde el Visual Basic ( aumente para prender varios leds)
Imports System.IO
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 10 -
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
'Dim Cadena As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "COM4" ' Cambia el Puerto
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
ListBox1.Items.Add("PUERTO CERRADO")
End Sub
Private Sub Listar(sender As Object, e As EventArgs) Handles BtnListar.Click
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(sp)
Next
End Sub
BtnCerrar.Enabled = False
BtnAbrir.Enabled = True
ListBox1.Items.Add("PUERTO CERRADO")
End Sub
End Class
Su salida es
Abra el monitor serial de arduino y abra el Puerto de visual basic y vera que al presionar
abrir puerto y luego click en el botón prender envía la letra A para prender el led y al
hacer clik en el botón apagar envia la letra B para Apagar el Led en Arduino
Tarea2. Pasar información digital del arduino al exterior con HMI visual Basic( arduino
escribe). Envie por el puerto serial (monitor serial de arduino) una letra y el visual basic
debe recibir. Diseñe el siguiente formulario en visual Basic
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 13 -
SU CODIGO ES
Next
End Sub
End Class
Su ejecución es
Abra el monitor serial de arduino y envie una seña si el visual basic recibe la letra A
Indica que el foco esta prendido y se recibe la letra B indica que el foco esta apagado
Su codigo en arduino es
//Leer una entrada digital y mostrar por la pantalla del computador (consola serial) el
estado del pulsador cuando es oprimido */
int boton=2; //Pin donde se encuentra el pulsador, entrada
int led =13;
void setup() // Se ejecuta cada vez que el Arduino se inicia
{
pinMode(boton,INPUT); //Configurar el boton como una entrada
pinMode(led,OUTPUT); //Configurar el boton como una entrada
Serial.begin(9600); //Inicia comunicación serial
}
void loop() // Esta funcion se mantiene ejecutando
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 15 -
Si se prende un foco en proteus aparece una señal de que el fofo esta prendido
Tarea 3. Pasar información analogica del exterior al arduino ( arduino lee) y usando
HMI Visual Basic( visual Basic escribe)
Su codigo es
Imports System.Drawing
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Public rojo As Integer
Public verde As Integer
Public azul As Integer
Public CadRojo As String
Public CadVerde As String
Public CadAzul As String
Public contVerde As Integer = 0
Public Velocidad As Integer = 10
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "COM4" ' Cambia elbli Puerto
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
BtnCerrar.Enabled = False
btnAbrir.Enabled = True
txtRojo.Text = rojo
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 17 -
txtVerde.Text = verde
txtAzul.Text = azul
End Sub
Pruebe el puerto Serial en visual basic ( Sin necesidad de proteus ) solo usando el
monitor serial de arduino.
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 19 -
char Cadena[10]="R123";
char dato;
char letra;
int nro,i;
int Rojo=9;
int Verde=10;
int Azul=11;
int valor=0;
void setup() {
pinMode(Rojo,OUTPUT);//D
pinMode(Verde,OUTPUT);//D
pinMode(Azul,OUTPUT);//D
Serial.begin(9600);
}
void loop()
{ i=0;
if (Serial.available() > 0)
{ valor=1;
while (Serial.available() > 0)
{
dato= Serial.read();
delay(5);
if (i==0 )
letra=dato;
else
Cadena[i-1]=dato;
i++;
}
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 20 -
Cadena[i-1]='\n';
Serial.println(Cadena);
nro = atoi(Cadena) ;
i=0;
}
if (valor==1)
{
Serial.print(letra);
Serial.println(Cadena);
switch(letra)
{ case 'R': analogWrite(Rojo, nro); break;
case 'V': analogWrite(Verde, nro); break;
case 'A': analogWrite(Azul, nro); break;
}
delay(10);
valor=0;
Serial.flush();
}
}
Se tiene los siguientes vértices de un cubo ( puede ser cualquier poliedro) grabe lo
seleccionado en amarillo como archivo de texto llamado vértices puntosCubo.txt
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 21 -
VERTICE X Y Z
0 0 0 0
1 1 0 0
2 1 1 0
3 0 1 0
4 0 0 1
5 1 0 1
6 1 1 1
7 0 1 1
Y los siguientes caras de un cubo ( grabe las celdas pintadas de amarillo como
CarasCubo.txt
CARA 0 1 2 3
0 0 1 2 3
1 1 5 6 2
2 4 5 6 7
3 0 4 7 3
4 3 2 6 7
5 0 1 5 4
Diseñe el siguiente formulario en Visual Basic 2017
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 22 -
Imports System.Windows.Forms
Imports System.IO
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 23 -
Imports System.IO.Ports
Imports System.Threading
Imports System.Drawing
Sub Iniciar()
DataGridView1.ColumnCount = 6
DataGridView1.RowCount = 5
Dim fila As Integer
For fila = 1 To 5
DataGridView1.Columns(fila).Width = 50
Next
For fila = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView1.Columns(0).HeaderText = "PARAMETROS"
DataGridView1.Columns(1).HeaderText = "UNIDAD"
DataGridView1.Columns(2).HeaderText = "EjeX"
DataGridView1.Columns(3).HeaderText = "Eje Y"
DataGridView1.Columns(4).HeaderText = "Eje Z"
DataGridView1.Columns(5).HeaderText = "VarD o W"
DataGridView1.Rows(2).Cells(4).Value = Ez
DataGridView1.Rows(2).Cells(5).Value = varEsca
DataGridView1.Rows(3).Cells(0).Value = "Modo (0,1) vel "
DataGridView1.Rows(3).Cells(1).Value = "Unidades"
DataGridView1.Rows(3).Cells(5).Value = D
End Sub
Else
ex = -limiteex
End If
Case Keys.Y, Keys.Up ' 66 ' B Inverso De Y
If ey >= -limiteey Then
ey = ey - varEsca
Else
ey = limiteey
End If
Case Keys.B, Keys.Down ' traslacion
If ey <= limiteey Then
ey = ey + varEsca
Else
ey = -limiteey
End If
Case Keys.C, Keys.PageDown ' C ROTACION Inverso de C
If Ez >= -100 Then
Ez = Ez - varEsca
Else
Ez = 100
End If
Case Keys.Z, Keys.PageUp ' ROTACION EJE Z
If Ez <= limiteez Then
Ez = Ez + varEsca
Else
Ez = -limiteez
End If
End Select
DataGridView1.Rows(2).Cells(2).Value = ex
DataGridView1.Rows(2).Cells(3).Value = ey
DataGridView1.Rows(2).Cells(4).Value = Ez
btnTodo_Click(sender, e)
txtEscalado.Text = ""
End Sub
Form2.Width = ancho
Form2.Height = alto
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 26 -
grafico = Form2.CreateGraphics()
brocha = New SolidBrush(Color.Yellow)
'borrador = New SolidBrush(Color.Blue)
pluma = New Pen(Color.Red, 2)
Iniciar()
End Sub
Sub GraficarVertices(MvertW(,) As String, nvert As Integer)
Dim fila As Integer
Dim Px, Py, x, y, z As Single
For fila = 0 To nvert - 1
x = MvertW(fila, 0)
y = MvertW(fila, 1)
z = MvertW(fila, 2)
Px = x * D / (D + z)
Py = y * D / (D + z)
grafico.DrawEllipse(pluma, cx + Px, cy + Py, 5, 5)
grafico.DrawString(fila, MiFuente, brocha, cx + Px, cy + Py)
Next
End Sub
Else
AnguloX = 0
End If
Case Keys.B, Keys.Down ' 66 ' B Inverso De Y
If AnguloY >= -3600 Then
AnguloY = AnguloY - varAngulo
Else
AnguloY = 3600
End If
Case Keys.Y, Keys.Up ' ROTACION EJE Y
If AnguloY <= 3600 Then
AnguloY = AnguloY + varAngulo
Else
AnguloY = 0
End If
Case Keys.C, Keys.PageDown ' C ROTACION Inverso de C
If AnguloZ >= -36000 Then
AnguloZ = AnguloZ - varAngulo
Else
AnguloZ = 3600
End If
Case Keys.Z, Keys.PageUp ' ROTACION EJE Z
If AnguloZ <= 3600 Then
AnguloZ = AnguloZ + varAngulo
Else
AnguloZ = 0
End If
End Select
DataGridView1.Rows(0).Cells(2).Value = AnguloX
DataGridView1.Rows(0).Cells(3).Value = AnguloY
DataGridView1.Rows(0).Cells(4).Value = AnguloZ
btnTodo_Click(sender, e)
txtRot.Text = ""
End Sub
Private Sub txtTraslacion_KeyDown(sender As Object, e As KeyEventArgs) Handles
txtTras.KeyDown
tx = DataGridView1.Rows(1).Cells(2).Value
ty = DataGridView1.Rows(1).Cells(3).Value
tz = DataGridView1.Rows(1).Cells(4).Value
Select Case e.KeyCode
Case Keys.A, Keys.Left ' A rotacion inverso de X
If tx >= -limitetx Then
tx = tx - vart
Else
tx = limitetx
End If
Case Keys.X, Keys.Right ' ROTACION EJE X
If tx <= limitetx Then
tx = tx + vart
Else
tx = -limitetx
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 28 -
End If
Case Keys.Y, Keys.Up ' 66 ' B Inverso De Y
If ty >= -limitety Then
ty = ty - vart
Else
ty = limitety
End If
Case Keys.B, Keys.Down ' traslacion
If ty <= limitety Then
ty = ty + vart
Else
ty = -limitety
End If
Case Keys.C, Keys.PageDown ' C ROTACION Inverso de C
If tz >= -100 Then
tz = tz - vart
Else
tz = 100
End If
Case Keys.Z, Keys.PageUp ' ROTACION EJE Z
If tz <= limitetz Then
tz = tz + vart
Else
tz = -limitetz
End If
End Select
DataGridView1.Rows(1).Cells(2).Value = tx
DataGridView1.Rows(1).Cells(3).Value = ty
DataGridView1.Rows(1).Cells(4).Value = tz
btnTodo_Click(sender, e)
txtTras.Text = ""
End Sub
Sub Proceso(Mvert(,) As String, MVertW(,) As String, NfilasV As Integer, NcolV As
Integer)
CopiarMatrices(Mvert, MVertW, NfilasV, NcolV)
RotacionXYZ(MVertW, AnguloX, AnguloY, AnguloZ, NfilasV)
EscaladoXYZ(MVertW, ex, ey, Ez, NfilasV)
TraslacionXYZ(MVertW, tx, ty, tz, NfilasV)
End Sub
Private Sub btnProcesar_Click(sender As Object, e As EventArgs) Handles
btnProcesar.Click
Proceso(MVert, MVertW, NfilasV, NColV)
End Sub
Sub MostrarMatrizFormulario(A(,) As String, nf As Integer, nc As Integer)
Dim fila, col As Integer
Dim cadena As String
For fila = 0 To nf - 1
cadena = ""
For col = 0 To nc - 1
cadena = cadena & A(fila, col) & vbTab
Next
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 29 -
ListBox1.Items.Add(cadena)
Next
End Sub
ListBox1.Items.Add(sp)
Next
End Sub
Module MODULE1
Sub Main()
Console.WriteLine("ARCHIVO DE PUNTOS ")
RecuperarMatriz(ArchivoPuntos, MVert, NfilasV, NColV)
MostrarMatriz(MVert, NfilasV, NColV)
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 31 -
Console.WriteLine("ARCHIVO DE CARAS")
RecuperarMatriz(ArchivoCaras, MCaras, NfilasC, NColC)
MostrarMatriz(MCaras, NfilasC, NColC)
Console.ReadLine()
End Sub
End Module
Module Module2
Sub EscaladoXYZ(MVW(,) As String, ByVal Ex As Single,
ByVal Ey As Single, ByVal Ez As Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
MVW(fila, 0) = MVW(fila, 0) * Ex
MVW(fila, 1) = MVW(fila, 1) * Ey
MVW(fila, 2) = MVW(fila, 2) * Ez
Next
End Sub
Sub CopiarMatrices(Mvert(,) As String, MvertW(,) As String, nf As Integer, nc As
Integer)
Dim fila, col
For fila = 0 To nf - 1
For col = 0 To nc - 1
MvertW(fila, col) = Mvert(fila, col)
Next
Next
End Sub
Sub TraslacionXYZ(MVW(,) As String, ByVal tx As Single, ByVal ty As Single, ByVal tz
As Single, nf As Integer)
Dim fila As Integer
For fila = 0 To nf - 1
MVW(fila, 0) = MVW(fila, 0) + tx
MVW(fila, 1) = MVW(fila, 1) + ty
MVW(fila, 2) = MVW(fila, 2) + tz
Next
End Sub
Sub RotacionXYZ(MVW(,) As String, ByVal AnguloX As Single,
ByVal AnguloY As Single, ByVal anguloZ As Single, nf As Integer)
Dim x1 As Single, y1 As Single, z1 As Single
Dim x2 As Single, y2 As Single, z2 As Single
Dim fila As Integer = 0
REM rotacion X
Dim arx = AnguloX * Math.PI / 180
For fila = 0 To nf - 1
x1 = MVW(fila, 0)
y1 = MVW(fila, 1)
z1 = MVW(fila, 2)
x2 = x1
y2 = CSng(y1 * Math.Cos(arx) - z1 * Math.Sin(arx))
z2 = CSng(y1 * Math.Sin(arx) + z1 * Math.Cos(arx))
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 32 -
MVW(fila, 0) = x2
MVW(fila, 1) = y2
MVW(fila, 2) = z2
Next
REM rotacion Y
Dim ary = AnguloY * Math.PI / 180
For fila = 0 To nf - 1
x1 = MVW(fila, 0)
y1 = MVW(fila, 1)
z1 = MVW(fila, 2)
x2 = CSng(x1 * Math.Cos(ary) - z1 * Math.Sin(ary))
y2 = y1
z2 = CSng(-x1 * Math.Sin(ary) + z1 * Math.Cos(ary))
MVW(fila, 0) = x2
MVW(fila, 1) = y2
MVW(fila, 2) = z2
Next
REM rotacion Z
Dim arz = anguloZ * Math.PI / 180
For fila = 0 To nf - 1
x1 = MVW(fila, 0)
y1 = MVW(fila, 1)
z1 = MVW(fila, 2)
x2 = CSng(x1 * Math.Cos(arz) - y1 * Math.Sin(arz))
y2 = CSng(x1 * Math.Sin(arz) + y1 * Math.Cos(arz))
z2 = z1
MVW(fila, 0) = x2
MVW(fila, 1) = y2
MVW(fila, 2) = z2
Next
End Sub
End Module
}Imports System.Drawing
Imports System.IO
Module Module3
Public Const limitetx As Integer = 500
Public Const limitety As Integer = 500
Public Const limitetz As Integer = 500
Public Const limiteex As Integer = 500
Public Const limiteey As Integer = 500
Public Const limiteez As Integer = 500
Public NfilasV As Integer
Public NColV As Integer
Public NfilasC As Integer
Public NColC As Integer
Public ArchivoPuntos As String = "C:\datos1\puntosCubo.txt"
Public ArchivoCaras As String = "C:\datos1\CarasCubo.txt"
Public tx As Single = 0
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 33 -
Public ty As Single = 0
Public tz As Single = 0
Public AnguloX As Integer = 0
Public AnguloY As Integer = 0
Public AnguloZ As Integer = 0
Public Const maxfilas As Integer = 8
Public Const maxcol As Integer = 4
Public MVert(maxfilas, maxcol) As String
Public MVertW(maxfilas, maxcol) As String
Public Const ancho As Integer = 600
Public Const alto As Integer = 600
Public MCaras(maxfilas, maxcol) As String
Public grafico As Graphics
Public brocha As SolidBrush
Public pluma As Pen
Public ex As Single = 100
Public ey As Single = 100
Public Ez As Single = 100
Public cx As Integer = 200 'ancho / 2
Public cy As Integer = 200 ' alto / 2
Public cont As Integer = 0
Public varAngulo As Single = 10
Public vart As Single = 10
Public varEsca As Single = 1
Public D As Single = 1000
End Module
Imports System.IO
Module Module4
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant
End Function
Ejecute la aplicacion
Abra el monitor serial del arduino se va simular use Vsp. Y pase información por ese
monitor por ejmplo la cadena 45:45:15 ( giro en eje X 45 grados, giro en Eje Y a 45
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 35 -
grados, giro en eje z A 15 grados) primero presione el botón abrir puerto y luego send y
vera usted que rota el cubo a esos valores
El Codigo de Arduino es
El Resultado es
Cierre el monitor serial de arduino para que lo emplee el proteus y vea el resultado al
mover los potenciómetros rota el cubo
Arregle las 3 ventanas para una mejor vision
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Imports System.Drawing
Public Tz As Single = 0
Public Vart As Single = 1
Public limite As Single = 1024
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "COM4" ' Cambia el Puerto
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
CheckForIllegalCrossThreadCalls = False ' Esta línea no le gusta mucho a los
programadores, pero aquí la ponemos para que funcione el Label1
ListBox1.Items.Add("Puerto Abierto")
grafico1 = PictureBox1.CreateGraphics
Form2.Width = ancho
Form2.Height = alto
pluma = New Pen(Color.Red, 2)
grafico2 = Form2.CreateGraphics
Form2.Show()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim pos1, pos2 As Integer
Dim Cadena, Rx, RY, Rz As String
Try
txtMensaje.Text = SerialPort1.ReadLine
Cadena = txtMensaje.Text
pos1 = InStr(Cadena, ":")
Rx = Mid(Cadena, 1, pos1 - 1)
pos2 = InStr(pos1 + 1, Cadena, ":")
RY = Mid(Cadena, pos1 + 1, pos2 - pos1 - 1)
Rz = Mid(Cadena, pos2 + 1)
TxtRx.Text = Rx
txtRy.Text = RY
txtRz.Text = Rz
txtTx.Text = TxtRx.Text
txtTy.Text = txtRy.Text
txttz.Text = txtRz.Text
enviar_Click(sender, e)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Sub
End Sub
End Sub
End Sub
Rx = Mid(Cadena, 1, pos1 - 1)
pos2 = InStr(pos1 + 1, Cadena, ":")
RY = Mid(Cadena, pos1 + 1, pos2 - pos1 - 1)
Rz = Mid(Cadena, pos2 + 1)
TxtRx.Text = Rx
txtRy.Text = RY
txtRz.Text = Rz
txtTx.Text = TxtRx.Text
txtTy.Text = txtRy.Text
txttz.Text = txtRz.Text
End Sub
End Class
El Codigo de Arduino es
delay(10);
Serial.print(valorX);
Serial.print(":");
Serial.print(valorY);
Serial.print(":");
Serial.println(valorZ);
}
El Resultado es
La solución es
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 43 -
BIBLIOGRAFIA
1. Tiendaderobotica.com. Guía Básica de Arduino.(Libro Kit Básico Pdf) 2014
Oscar Torrente Artero . Curso Arduino/ Curso practico de formcion .ALfaomega mexico
REVISION grupos a y c 30 de setiemrbe
Grupos cy jueves 03 de octubre del 2019
Este programa es modificado de comunicación serial arduino HMI visual Basic y las
librerías OPENGL modificado de la pag 37
Se pide
Terminar el programa agregando luces
Hacer interface con el arduino usando potenciómetros y luego sensores de distancia
Hacer lo mismo pero con blender
Imports System.Drawing
Imports System.Windows.Forms
Imports Tao.Platform.Windows
Imports System.Windows
Public Class Form1
Dim Opengl As OGL
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 45 -
DataGridView1.Rows(2).Cells(5).Value = varEsca
txObj = DataGridView1.Rows(3).Cells(2).Value
tyObj = DataGridView1.Rows(3).Cells(3).Value
tzObj = DataGridView1.Rows(3).Cells(4).Value
varObj = DataGridView1.Rows(3).Cells(5).Value
End Sub
Private Sub Rotacion(sender As Object, e As KeyEventArgs) Handles txtRot.KeyDown
AnguloX = DataGridView1.Rows(0).Cells(2).Value
AnguloY = DataGridView1.Rows(0).Cells(3).Value
AnguloZ = DataGridView1.Rows(0).Cells(4).Value
Select Case e.KeyCode
Case Keys.A, Keys.Left ' A rotacion inverso de X
If AnguloX >= -3600 Then
AnguloX = AnguloX - varAngulo
Else
AnguloX = 3600
End If
Case Keys.X, Keys.Right ' ROTACION EJE X
If AnguloX <= 3600 Then
AnguloX = AnguloX + varAngulo
Else
AnguloX = 0
End If
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 47 -
txtRot.Text = ""
End Sub
Private Sub txtTraslacion_KeyDown(sender As Object, e As KeyEventArgs) Handles
txtTras.KeyDown
tx = DataGridView1.Rows(1).Cells(2).Value
ty = DataGridView1.Rows(1).Cells(3).Value
tz = DataGridView1.Rows(1).Cells(4).Value
Select Case e.KeyCode
Case Keys.A, Keys.Left ' A rotacion inverso de X
If tx >= -limite Then
tx = tx - vart
Else
tx = limite
End If
Case Keys.X, Keys.Right ' ROTACION EJE X
If tx <= limite Then
tx = tx + vart
Else
tx = -limite
End If
Case Keys.Y, Keys.Up ' 66 ' B Inverso De Y
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 48 -
Else
tyObj = limite
End If
Case Keys.B, Keys.Down ' traslacion
If tyObj <= limite Then
tyObj = tyObj + vart
Else
tyObj = -limite
End If
Case Keys.C, Keys.PageDown ' C ROTACION Inverso de C
If tzObj >= -100 Then
tzObj = tzObj - vart
Else
tzObj = 100
End If
Case Keys.Z, Keys.PageUp ' ROTACION EJE Z
If tzObj <= limite Then
tzObj = tzObj + vart
Else
tzObj = -limite
End If
End Select
DataGridView1.Rows(1).Cells(2).Value = txObj
DataGridView1.Rows(1).Cells(3).Value = tyObj
DataGridView1.Rows(1).Cells(4).Value = tzObj
txtObjeto.Text = ""
End Sub
ey = limite
End If
Case Keys.B, Keys.Down ' traslacion
If ey <= limite Then
ey = ey + varEsca
Else
ey = -limite
End If
Case Keys.C, Keys.PageDown ' C ROTACION Inverso de C
If Ez >= -100 Then
Ez = Ez - varEsca
Else
Ez = 100
End If
Case Keys.Z, Keys.PageUp ' ROTACION EJE Z
If Ez <= limite Then
Ez = Ez + varEsca
Else
Ez = -limite
End If
End Select
DataGridView1.Rows(2).Cells(2).Value = ex
DataGridView1.Rows(2).Cells(3).Value = ey
DataGridView1.Rows(2).Cells(4).Value = Ez
txtEscalado.Text = ""
End Sub
Private Sub btnForm2_Click(sender As Object, e As EventArgs) Handles
btnAbrirOpengl.Click
Opengl = New OGL
Opengl.InitOPENGL(User.GetDC(Form2.Handle))
Form2.Show()
Opengl.BucleOpenGl()
End Sub
Private Sub btnCerrarOpengl_Click(sender As Object, e As EventArgs) Handles
btnCerrarOpengl.Click
Opengl.EliminarOpenGL()
Form2.Close()
End Sub
Private Sub BtnAbrir_Click(sender As Object, e As EventArgs) Handles BtnAbrir.Click
RecuperarMatriz(VerticesCoord, MVertCoord, NfVertCoord, NcVertCoord)
ListBox1.Items.Add("ARCHIVO DE VERTICES COOORDENADAS")
MostrarMatrizFormulario(MVertCoord, NfVertCoord, NcVertCoord)
RecuperarMatriz(VerticesCoord, MVertCoord, NfVert, NcVert)
RecuperarMatriz(CarasCoord, MCarascoord, NFCarasCoord, NcCarasCoord)
ListBox1.Items.Add("ARCHIVO DE CARAS")
MostrarMatrizFormulario(MCarascoord, NFCarasCoord, NcCarasCoord)
'xxxxxxxxxxxxxxxxxxxxxx
RecuperarMatriz(Vertices, MVert, NfVert, NcVert)
Imports Tao.OpenGl
Imports Tao.OpenGl.Glu
Imports Tao.FreeGlut
Imports Tao.Platform.Windows
Module Module1
Sub MAIN()
'RecuperarMatriz(VerticesCoord, MVert, NfVert, NcVert)
'Console.WriteLine("MATRIZ VERTICES")
'MostrarMatriz(MVert, NfVert, NcVert)
'RecuperarMatriz(ArchivoCaras, MCaras, NFCaras, NcCaras)
'Console.WriteLine("MATRIZ Caras")
'MostrarMatriz(MCaras, NFCaras, NcCaras)
'Console.ReadLine()
End Sub
End Module
Imports System.IO
Module Module2
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant
End Function
Imports System.Drawing
Imports Tao.OpenGl
Imports Tao.OpenGl.Glu
Imports Tao.FreeGlut
Imports Tao.Platform.Windows
Module Module3
Public tipo As Integer = 0
Public alto As Integer = 600
Public ancho As Integer = 600
Public AnguloX As Integer = 0
Public AnguloY As Integer = 0
Public AnguloZ As Integer = 0
Public Caras As String = "C:\datos1\Caras.txt"
Public CarasCoord As String = "C:\datos1\CarasCoord.txt"
Imports Tao.OpenGl
Imports Tao.Platform.Windows
Imports System.Windows.Forms
Imports Tao.FreeGlut
Public Class OGL
Dim hRC As System.IntPtr
Dim hDc As System.IntPtr
' Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByVal
Destination As Gdi.PIXELFORMATDESCRIPTOR, ByVal Length As Integer)
Public Sub InitOPENGL(ByVal ghDC As System.IntPtr)
Dim pfd As Gdi.PIXELFORMATDESCRIPTOR
Dim PixelFormat As Integer
hDc = ghDC
'ZeroMemory(pfd, Len(pfd))
pfd.nSize = Len(pfd)
pfd.nVersion = 1
Guía de practica AI2019 B mínima requerida \Ismael Véliz Vilca - 54 -
Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_FILL)
Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F)
Gl.glMatrixMode(Gl.GL_PROJECTION)
Gl.glLoadIdentity()
Gl.glOrtho(-tam, tam, -tam, tam, -tam * 2, tam * 2)
Gl.glMatrixMode(Gl.GL_MODELVIEW)
Gl.glEnable(Gl.GL_DEPTH_TEST)
Gl.glLoadIdentity()
End Sub
Public Sub BucleOpenGl()
Do
Render()
Loop
End Sub
Gl.glEnd()
Next
End Sub
Sub display()
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT)
Gl.glLoadIdentity()
Gl.glRotatef(AnguloX, 1.0F, 0.0F, 0.0F)
Gl.glRotatef(AnguloY, 0.0F, 1.0F, 0.0F)
Gl.glRotatef(AnguloZ, 0.0F, 0.0F, 1.0F)
Gl.glTranslatef(tx, ty, tz)
Gl.glScalef(ex, ey, Ez)
'Gl.glColor3f(1, 1, 0)
'Glu.gluSphere(qobj, 1, 32, 32)
Gl.glColor3f(1, 0, 0)
DibujarCoordenadas(MVertCoord, MCarascoord, NFCarasCoord, NcCarasCoord)
Gl.glPushMatrix()
Gl.glTranslatef(txObj, tyObj, tzObj)
Gl.glColor3f(1, 1, 0)
DibujarCubo(MVert, MCaras, NFCaras, NcCaras)
Gl.glPopMatrix()
Gl.glFlush()
Gdi.SwapBuffers(hDc)
End Sub
Sub Render()
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT)
Application.DoEvents()
Gl.glColor3f(0, 1, 0)
display()
End Sub
End Class