PDF de programación - ANEXO B. CÓDIGO FUENTE - Simulación virtual en un entorno DirectX3D del corte tridimensional de piezas mediante un robot manipulador

Imágen de pdf ANEXO B. CÓDIGO FUENTE - Simulación virtual en un entorno DirectX3D del corte tridimensional de piezas mediante un robot manipulador

ANEXO B. CÓDIGO FUENTE - Simulación virtual en un entorno DirectX3D del corte tridimensional de piezas mediante un robot manipuladorgráfica de visualizaciones

Publicado el 23 de Agosto del 2018
817 visualizaciones desde el 23 de Agosto del 2018
718,4 KB
204 paginas
Creado hace 16a (05/06/2007)
Simulación virtual en un entorno DirectX3D del corte tridimensional de

piezas mediante un robot manipulador.



______________________________________________________________________


Código fuente.

ANEXO B. CÓDIGO FUENTE.

En este apartado se muestra el código fuente generado en el programa de desarrollo

Microsoft Visual Studio C++ 6.0 para las dos grandes aplicaciones comentadas en este

proyecto: ‘Corte3D’ y ‘Rx90’. Por un lado, la primera obtiene y procesa toda la

información para ejecutar una trayectoria de corte y establece una comunicación con el

controlador CS7, por otro, la segunda simula en el ordenador al robot siguiendo la

trayectoria obtenida entorno a una pieza diseñada previamente.

Desglosamos el código fuente, para una mayor facilidad en la lectura, en clases, y a

su vez, éstas las dividimos en archivos de cabecera (extensión “.h”) y de

implementación (extensión “.cpp”).

______________________________________________________________________

139

Simulación virtual en un entorno DirectX3D del corte tridimensional de

piezas mediante un robot manipulador.



______________________________________________________________________


Código fuente.

B.1 APLICACIÓN ‘CORTE3D’.

B.1.1 CCorte3D.

B.1.1.1. Corte3D.h

////////////////////////////////////////////////////////////////////

//

//

//

//



Corte3D.h: Archivo de cabecera del la clase principal

CCorte3D.



//

//

//

//

////////////////////////////////////////////////////////////////////

#if !defined(AFX_CORTE3D_H__4B0F6DF2_B5C3_461B_BF07_84ED9419B3FC__INCLUDED_)

#define AFX_CORTE3D_H__4B0F6DF2_B5C3_461B_BF07_84ED9419B3FC__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__



#error include 'stdafx.h' before including this file for PCH

#endif

#include "resource.h"



// main symbols



#include "PuertoSerie.h"

#include "PuntoTrayectoria.h"



/////////////////////////////////////////////////////////////////////////////

// CCorte3DApp:

// See Corte3D.cpp for the implementation of this class

//



class CDlgSimulacion;

class CCorte3DApp : public CWinApp

{

public:

void ComprobarPosiblesSaltos(int PuntosAPT);

void PuntosDeSeparacion(int nNumeroPuntosAPT);

void PuntosDeAproximacion();

void CalculaPuntoCentral(int nPuntos);

CPuertoSerie m_serie;

CPuntoTrayectoria* m_pPuntoTrayectoria;

CPuntoTrayectoria m_MundoReal;



CPuntoTrayectoria m_MundoVirtual;

CPuntoTrayectoria m_Transformacion;

CCorte3DApp();

void EnviarOrden(LPCTSTR lpszOrden);



BOOL AbrirYLeerFicheroAPT(CString& strContFicheroAPT);

BOOL ProcesarContenidoFicheroAPT(CString& strContFicheroAPT);



// Overrides



// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CCorte3DApp)

public:

virtual BOOL InitInstance();

//}}AFX_VIRTUAL

______________________________________________________________________

140

Simulación virtual en un entorno DirectX3D del corte tridimensional de

piezas mediante un robot manipulador.



______________________________________________________________________



Código fuente.

// Implementation

//{{AFX_MSG(CCorte3DApp)

// NOTE - the ClassWizard will add and remove member functions here.

// DO NOT EDIT what you see in these blocks of generated code !

//}}AFX_MSG

DECLARE_MESSAGE_MAP()



};



/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before // the previous line.

#endif // !defined(AFX_CORTE3D_H__4B0F6DF2_B5C3_461B_BF07_84ED9419B3FC__INCLUDED_)



B.1.1.2. Corte3D.cpp

//////////////////////////////////////////////////////////////

//

//

//

//



//

Corte3D.cpp: implementa la clase principal de la //

aplicación.



//

//

//////////////////////////////////////////////////////////////



#include "stdafx.h"

#include "Corte3D.h"

#include "Corte3DDlg.h"

#include <string.h>

#include <math.h>

#include <iostream.h>

#include <fstream.h>

#define PI

3.1415926

#define pasos 5



#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif



/////////////////////////////////////////////////////////////////////////////

// CCorte3DApp



BEGIN_MESSAGE_MAP(CCorte3DApp, CWinApp)



//{{AFX_MSG_MAP(CCorte3DApp)

// NOTE - the ClassWizard will add and remove mapping macros here.

// DO NOT EDIT what you see in these blocks of generated code!

//}}AFX_MSG

ON_COMMAND(ID_HELP, CWinApp::OnHelp)

END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////

// CCorte3DApp construction



CCorte3DApp::CCorte3DApp()

______________________________________________________________________

141

Simulación virtual en un entorno DirectX3D del corte tridimensional de

piezas mediante un robot manipulador.



______________________________________________________________________

{

Código fuente.

// TODO: add construction code here,

// Place all significant initialization in InitInstance



}



/////////////////////////////////////////////////////////////////////////////

// The one and only CCorte3DApp object



CCorte3DApp theApp;



/////////////////////////////////////////////////////////////////////////////

// CCorte3DApp initialization



BOOL CCorte3DApp::InitInstance()

{



// Standard initialization

// If you are not using these features and wish to reduce the size

// of your final executable, you should remove from the following

// the specific initialization routines you do not need.

#ifdef _AFXDLL



Enable3dControls();



// Call this when using MFC in a shared DLL

#else



Enable3dControlsStatic(); // Call this when linking to MFC statically

#endif

// Dialog creation may fail if the dialog template has a Rich Edit //control in it because

the Rich Edit control is not initialized.

// Call the MFC global function AfxInitRichEdit before you create the //dialog to initialize

the Rich Edit Control. A good place to initialize //the Rich Edit control is in the

application's InitInstance function //before you create the dialog.

AfxInitRichEdit();

CCorte3DDlg dlg;

m_pMainWnd = &dlg;

int nResponse = dlg.DoModal();

if (nResponse == IDOK)

{



}

// TODO: Place code here to handle when the dialog is

// dismissed with OK

else if (nResponse == IDCANCEL)

{



}

// TODO: Place code here to handle when the dialog is

// dismissed with Cancel

// Since the dialog has been closed, return FALSE so that we exit the

// application, rather than start the application's message pump.

return FALSE;



}

//////////////////////////////////////////////////////////////////////////////

//

// Método que sirve para enviar órdenes al controlador.

//

// Parámetros:

______________________________________________________________________

142

Simulación virtual en un entorno DirectX3D del corte tridimensional de

piezas mediante un robot manipulador.



Código fuente.


______________________________________________________________________

//

- Puntero a CString constante (LPCTSTR) que almacena la orden.

Como no se va a modificar se pasa de esta forma y no como CString&.

PROBAR CSTRING& Y NO HAY Q DEFINIR strComandoAEnviar DENTRO

QUIZAS DEBERIAS ESTAR DENTRO DE LA CLASE CPUERTOSERIE

//

//

//

//

//

//

//////////////////////////////////////////////////////////////////////////////

void CCorte3DApp::EnviarOrden(LPCTSTR lptszOrden)

{



//char chRetornoCarro[1] = {'\r'};

//char chRetornoCarro = '\r';



// Añadimos el caracter RC al final de la orden para que pueda ser

// interpretada por el controlador.

CString strComandoAEnviar;

strComandoAEnviar.Format("%s\r", lptszOrden);



// Enviamos los datos por el puerto serie carácter a carácter. Como sólo

// podemos enviar carácteres de 1 byte, hemos de convertir el CString, que

// es un LPCTSTR, a LPCSTR (es decir, de TCHAR* a char*). El método miembro

// Write de la clase CSerial admite o un void* pData o un LPCSTR.

//

// Paso la cadena de TCHAR a una cadena de char.

// Como está contenida en una instancia de la clase CString (que contiene

// TCHAR), hay q pasarla a LPCSTR (const char*) o LPSTR (char*) para poder

// enviarla caracter a caracter por el puerto serie. Mediante un cast solo

// podemos obtener un LPCTSTR. Usando el método miembro GetBuffer() podemos

// obtener un puntero LPTSTR, que debemos posteriormente liberar usando el

// método miembro ReleaseBuffer(). Hasta que no lo hayamos liberado no

// podemos usar ningún otro método miembro de esa instancia CString.

//

// Por tanto, hemos de diferenciar si estamos usando UNICODE o MCBS (Ansi)

// (#ifdef _UNICODE (...) #endif):

//

//

//

//

//

//

//

//

//

//

//

//

//

//

//

//



//



//

a)

UNICODE: un TCHAR contiene un wchar_t de 2bytes.



Por tanto, hacemos un cast y obtenemos un LPCTSTR que contiene

caracteres UNICODE (2 bytes por caracter) y no lo podemos usar

para transmitir por el puerto serie. Podemos usar las macros ATL

para conversión entre formatos de cadena (hemos de incluir

#include <atlconv.h> y poner la macro USES_CONVERSION al

función que las usa, pues en ella se definen algunas variables

principio de la locales necesarias).

En concreto usaremos T2A(LPTSTR xx), que devuelve un LPSTR, o

T2C
  • Links de descarga
http://lwp-l.com/pdf13149

Comentarios de: ANEXO B. CÓDIGO FUENTE - Simulación virtual en un entorno DirectX3D del corte tridimensional de piezas mediante un robot manipulador (0)


No hay comentarios
 

Comentar...

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad