Bienvenido: Ingresar
location: attachment:rhino.cpp de Robotica/ProyectoRhino

Adjunto 'rhino.cpp'

Descargar

   1 /****************************************************************************/
   2 /* rhino.cpp (c++)                                                          */
   3 /*--------------------------------------------------------------------------*/
   4 /* Licencia GPL                                                             */
   5 /* Implementacion de la Clase Rhino                                         */
   6 /* Clase para la gestion del estado del controlador del Servo Robot XR4     */
   7 /*                             RHINO                                        */
   8 /****************************************************************************/
   9 /* Marco Alvarez Reyna                                                      */
  10 /* CIII UTN-FRC Argentina                                                   */
  11 /* Mayo 2007 / Abril 2008                                                   */
  12 /* mail: marcoalrey@gmail.com                                               */
  13 /****************************************************************************/
  14 
  15 #include "rhino.h"
  16 
  17 Rhino::Rhino()
  18 /***************************************************************/
  19 /*  Constructor                                                */
  20 /***************************************************************/
  21 {
  22     /* Valores por defecto */
  23     uiErrorCode = 0; 
  24     uiStatusCode = 0; 
  25     uiLogLevel  = 3; 
  26     pFile       = NULL;
  27 
  28     InitMessageVectors(RhinoBotErrorMsg, RhinoClassErrorMsg, RhinoBotStatusMsg, RhinoClassStatusMsg);
  29 }
  30 
  31 Rhino::~Rhino()
  32 /***************************************************************/
  33 /*  Destructor                                                 */
  34 /***************************************************************/
  35 {
  36     pFile       = NULL;
  37 }
  38 
  39 int Rhino::set_LogLevel(unsigned int _uiLogLevel)
  40 /***************************************************************/
  41 /*  Setea el nivel de logueo de errores                        */
  42 /***************************************************************/
  43 /* LOG LEVEL: "unsigned int uiLogLevel"
  44                MAX_LOG_LEVEL
  45 
  46    0 - El mensaje de error se almacena en una variable de la clase.
  47    1 - Se muestran en consola los mensajes de error.
  48    2 - Se graban en un archivo los mensajes de error.
  49    3 - Los mensajes de error se graban en arch. y se muestran en consola.
  50 */
  51 {
  52     if(_uiLogLevel < 0 || _uiLogLevel > MAX_LOG_LEVEL)
  53     {
  54 	uiLogLevel = 3; //Default LogLevel
  55 	ProcessErrorMsg(LOG_LEV);
  56 	ProcessStatusMsg(RC_DEF_LOG_LEV);
  57 	return -1;	
  58     }
  59     
  60     uiLogLevel = _uiLogLevel;
  61     return 0;
  62 }
  63 
  64 int Rhino::get_LogLevel(unsigned int *_uiLogLevel)
  65 /***************************************************************/
  66 /*  Devuelve el nivel de logueo de errores                     */
  67 /***************************************************************/
  68 {
  69     *_uiLogLevel = uiLogLevel;
  70     return 0; 
  71 }
  72 
  73 int Rhino::get_ErrorMsg(unsigned int _uiErrorCode, char *_cTextError)
  74 /***************************************************************/
  75 /*  Devuelve le mensaje de error corrspondiente al codigo de   */
  76 /*  error requerido                                            */
  77 /***************************************************************/
  78 {
  79     /* Rhino Bot Errors */
  80     if(_uiErrorCode >= 0 && _uiErrorCode <= MAX_RB_ERROR_CODES)
  81     {
  82 	strcpy(_cTextError, RhinoBotErrorMsg[_uiErrorCode]);      
  83 	return 0;
  84     }
  85 
  86     /* Rhino Class Errors */
  87     if(_uiErrorCode > MAX_RB_ERROR_CODES && _uiErrorCode <= (MAX_RB_ERROR_CODES + MAX_RC_ERROR_CODES))
  88     {
  89 	strcpy(_cTextError, RhinoClassErrorMsg[_uiErrorCode-MAX_RB_ERROR_CODES]);
  90 	return 0;
  91     }
  92     
  93     ProcessErrorMsg(ERR_CODE);
  94     return -1;
  95 }
  96 int Rhino::get_ErrorMsg(char *_cTextError)
  97 /***************************************************************/
  98 /*  Devuelve le mensaje de error del ultimo error producido    */
  99 /***************************************************************/
 100 {
 101     /* Rhino Bot Errors */
 102     if(uiErrorCode >= 0 && uiErrorCode <= MAX_RB_ERROR_CODES)
 103     {
 104 	strcpy(_cTextError, RhinoBotErrorMsg[uiErrorCode]);      
 105 	return 0;
 106     }
 107 
 108     /* Rhino Class Errors */
 109     if(uiErrorCode > MAX_RB_ERROR_CODES && uiErrorCode <= (MAX_RB_ERROR_CODES + MAX_RC_ERROR_CODES))
 110     {
 111 	strcpy(_cTextError, RhinoClassErrorMsg[uiErrorCode-MAX_RB_ERROR_CODES]);
 112 	return 0;
 113     }
 114     
 115     ProcessErrorMsg(ERR_CODE);
 116     return -1;
 117 }
 118 
 119 int Rhino::ProcessErrorMsg(unsigned int _uiErrorCode)
 120 /***************************************************************/
 121 /*  Rutina de procesamiento de errores                         */
 122 /***************************************************************/
 123 /*  FUNCION PRIVADA                                            */
 124 /***************************************************************/
 125 {
 126     if((_uiErrorCode < 0) || (_uiErrorCode > (MAX_RC_ERROR_CODES + MAX_RB_ERROR_CODES)))
 127     {
 128 	ProcessErrorMsg(ERR_CODE);
 129     }
 130     else
 131     {
 132 	uiErrorCode = _uiErrorCode;
 133 
 134 	get_ErrorMsg(cErrorMessage);
 135 	sprintf(RhinoMessages, "RhinoClass->ProcessErrorMsg:\n\tUltimo cmd enviado: %s\n\tUltima cadena recibida: %s\n\tCodigo de error: %d\n\tLog Level: %d\n\tMSG: %s\n", LastCmdAndMsg.LastCommandtoRhino, LastCmdAndMsg.LastMessageFromRhino, uiErrorCode, uiLogLevel, cErrorMessage);
 136 
 137 	if(uiLogLevel == 0)
 138 	{
 139 	    LogMessage(LMOCBk, RhinoMessages);
 140 	}
 141 	if(uiLogLevel == 1)
 142 	{
 143 	    LogMessage(LMODisplay, RhinoMessages);
 144 	}
 145 	if(uiLogLevel == 2)
 146 	{
 147 	    LogMessage(LMOFile, RhinoMessages);
 148 	}
 149 	if(uiLogLevel == 3)
 150 	{
 151 	    LogMessage(LMODisplay, RhinoMessages);
 152 	    LogMessage(LMOFile, RhinoMessages);
 153 	}
 154     }
 155 
 156     return 0;
 157 }
 158 
 159 int Rhino::ProcessStatusMsg(unsigned int _uiStatusCode)
 160 /***************************************************************/
 161 /*  Rutina de manejo de mensajes de estado del sistema         */
 162 /***************************************************************/
 163 /*  FUNCION PRIVADA                                            */
 164 /***************************************************************/
 165 {
 166      if((_uiStatusCode < 0) || (_uiStatusCode > (MAX_RC_STATUS_CODES + MAX_RB_STATUS_CODES)))
 167     {
 168 	ProcessErrorMsg(ERR_CODE);
 169     }
 170     else
 171     {
 172 	uiStatusCode = _uiStatusCode;
 173 
 174 	get_StatusMsg(cStatusMessage);
 175 	sprintf(RhinoMessages, "RhinoClass->ProcessStatusMsg:\n\tUltimo cmd enviado: %s\n\tUltima cadena recibida: %s\n\tCodigo de estado: %d\n\tLog Level: %d\n\tMSG: %s\n", LastCmdAndMsg.LastCommandtoRhino, LastCmdAndMsg.LastMessageFromRhino, uiStatusCode, uiLogLevel, cStatusMessage);
 176 
 177 	if(uiLogLevel == 0)
 178 	{
 179 	    LogMessage(LMOCBk, RhinoMessages);
 180 	}
 181 	if(uiLogLevel == 1)
 182 	{
 183 	    LogMessage(LMODisplay, RhinoMessages);
 184 	}
 185 	if(uiLogLevel == 2)
 186 	{
 187 	    LogMessage(LMOFile, RhinoMessages);
 188 	}
 189 	if(uiLogLevel == 3)
 190 	{
 191 	    LogMessage(LMODisplay, RhinoMessages);
 192 	    LogMessage(LMOFile, RhinoMessages);
 193 	}
 194     }
 195 
 196     return 0;
 197 }
 198 
 199 int  Rhino::get_ErrorCode(unsigned int *_uiErrorCode)
 200 /***************************************************************/
 201 /*  Devuelve el codigo de error del ultimo error producido     */
 202 /***************************************************************/
 203 {
 204     *_uiErrorCode = uiErrorCode;
 205     return 0;
 206 }
 207 
 208 int  Rhino::DisplayAllErrorMessages(void)
 209 /***************************************************************/
 210 /*  Imprime todos los mensajes de error                        */
 211 /***************************************************************/
 212 {
 213     sprintf(RhinoMessages, "ERROR MESSEGES\n\n");
 214     LogMessage(LMODisplay, RhinoMessages);
 215     int i=0;
 216     
 217     sprintf(RhinoMessages, "RHINO CONTROLLER ERRORS\n");
 218     LogMessage(LMODisplay, RhinoMessages);
 219     for(i=0; i<MAX_RB_ERROR_CODES ; i++)
 220     {
 221 	sprintf(RhinoMessages, "CODE:%d %s\n", i, RhinoBotErrorMsg[i]);
 222 	LogMessage(LMODisplay, RhinoMessages);
 223     }
 224 
 225     sprintf(RhinoMessages, "\nRHINO CLASS ERRORS\n");
 226     LogMessage(LMODisplay, RhinoMessages);
 227     for(i=0; i<MAX_RC_ERROR_CODES ; i++)
 228     {
 229 	sprintf(RhinoMessages, "CODE:%d %s\n", i, RhinoClassErrorMsg[i]);
 230 	LogMessage(LMODisplay, RhinoMessages);
 231     }
 232 
 233     return 0;
 234 }
 235 
 236 int Rhino::LogMessage(int _LogType, char * _Message)
 237 /***************************************************************/
 238 /*  Muestra y almacena mensajes del sistema                    */
 239 /***************************************************************/
 240 {
 241     if(_LogType == LMOCBk)
 242     {
 243 	strcpy(CallBack.sCBkMessage, _Message);
 244 	CallBack.bNewMsg = true;
 245     }
 246 
 247     if(_LogType == LMODisplay)
 248     {
 249 	fprintf(stderr, "%s", _Message);
 250     }
 251 
 252     if(_LogType == LMOFile)
 253     {
 254 	pFile = fopen("rc_error_log.txt","a+");
 255 	if(pFile == NULL){
 256 	    ProcessErrorMsg(NO_FILE);
 257 	    return -1;
 258 	}
 259 	fprintf(pFile,"%s\n", _Message);
 260 	fclose(pFile);
 261     }
 262 
 263     return 0;
 264 }
 265 
 266 int Rhino::CBkMsg(void)
 267 /***************************************************************/
 268 /*  Si hay algun mensaje pendiente por reportar devuelve true  */
 269 /***************************************************************/
 270 {
 271     if(CallBack.bNewMsg == true)
 272 	return 1;
 273     else 
 274 	return 0;
 275 }
 276 
 277 int Rhino::get_CBkMsg(char * _Message)
 278 /***************************************************************/
 279 /* Devulve el ultimo mensaje reportado por la clase            */
 280 /***************************************************************/
 281 {
 282     if(CallBack.bNewMsg == true){
 283 	strcpy(_Message, CallBack.sCBkMessage);
 284 	CallBack.bNewMsg = false;
 285     }
 286     else
 287 	strcpy(_Message, "No new message from Rhino Class\n");
 288 
 289     return 0;
 290 }
 291 
 292 int Rhino::InitMessageVectors(char _RhinoBotErrorMsg[MAX_RB_ERROR_CODES][MSG_LENGTH], char _RhinoClassErrorMsg[MAX_RC_ERROR_CODES][MSG_LENGTH], char _RhinoBotStatusMsg[MAX_RB_STATUS_CODES][MSG_LENGTH], char _RhinoClassStatusMsg[MAX_RC_STATUS_CODES][MSG_LENGTH])
 293 /***************************************************************/
 294 /* Inicializa los vectores pasados como parametro con con los  */ 
 295 /* mensajes de error de la clase                               */
 296 /***************************************************************/
 297 /* ERROR CODE:  "unsigned int uiErrorCode"
 298                  MAX_RB_ERROR_CODES
 299                  MAX_RC_ERROR_CODES
 300 		 MSG_LENGTH
 301 
 302    - de "0" a "MAX_RB_ERROR_CODES-1":
 303          Errores pertenecientes al controlador del brazo Rhino.
 304 
 305    - de "MAX_RB_ERROR_CODES" a "MAX_RB_ERROR_CODES + MAX_RC_ERROR_CODES": 
 306          Errores pertenecientes a la clase Rhino.
 307 
 308    -etc...
 309 
 310    - MSG_LENGTH es el largo maximo de los mensajes de error almacenados los 
 311      vectores
 312 */
 313 {
 314     const char RhinoBotErrorMsgSOURCE[MAX_RB_ERROR_CODES][MSG_LENGTH]={
 315 	{"	Rhino Controller Error:	BE HAPY, NO PROBLEM	"},
 316 	{"	Rhino Controller Error:	NO ERROR	"},
 317 	{"	Rhino Controller Error:	NO ERROR	"},
 318 	{"	Rhino Controller Error:	NO ERROR	"},
 319 	{"	Rhino Controller Error:	NO ERROR	"},
 320 	{"	Rhino Controller Error:	NO ERROR	"},
 321 	{"	Rhino Controller Error:	NO ERROR	"},
 322 	{"	Rhino Controller Error:	NO ERROR	"},
 323 	{"	Rhino Controller Error:	NO ERROR	"},
 324 	{"	Rhino Controller Error:	NO ERROR	"},
 325 	{"	Rhino Controller Error:	Invalid command.	"},
 326 	{"	Rhino Controller Error:	Parameter out of bounds.	"},
 327 	{"	Rhino Controller Error:	Missing parameter.	"},
 328 	{"	Rhino Controller Error:	Expected delimiter not seen.	"},
 329 	{"	Rhino Controller Error:	Command string too long.	"},
 330 	{"	Rhino Controller Error:	NO ERROR	"},
 331 	{"	Rhino Controller Error:	The teach pendant is active or busy.	"},
 332 	{"	Rhino Controller Error:	NO ERROR	"},
 333 	{"	Rhino Controller Error:	NO ERROR	"},
 334 	{"	Rhino Controller Error:	NO ERROR	"},
 335 	{"	Rhino Controller Error:	Host input buffer overflow.	"},
 336 	{"	Rhino Controller Error:	Host USART timed out.	"},
 337 	{"	Rhino Controller Error:	Host USART error (framing, parity, etc.).	"},
 338 	{"	Rhino Controller Error:	Teach pendant input buffer overflow.	"},
 339 	{"	Rhino Controller Error:	Teach pendant USART timed out.	"},
 340 	{"	Rhino Controller Error:	Teach pendant USART error (framing, parity, etc.).	"},
 341 	{"	Rhino Controller Error:	Teach pendant USART overrun.	"},
 342 	{"	Rhino Controller Error:	Host USART overrun.	"},
 343 	{"	Rhino Controller Error:	NO ERROR	"},
 344 	{"	Rhino Controller Error:	NO ERROR	"},
 345 	{"	Rhino Controller Error:	Bad RAM location.	"},
 346 	{"	Rhino Controller Error:	NO ERROR	"},
 347 	{"	Rhino Controller Error:	Teach pendant returned diagnostic error.	"},
 348 	{"	Rhino Controller Error:	NO ERROR	"},
 349 	{"	Rhino Controller Error:	Teach pendant not present.	"},
 350 	{"	Rhino Controller Error:	NO ERROR	"},
 351 	{"	Rhino Controller Error:	NO ERROR	"},
 352 	{"	Rhino Controller Error:	NO ERROR	"},
 353 	{"	Rhino Controller Error:	NO ERROR	"},
 354 	{"	Rhino Controller Error:	NO ERROR	"},
 355 	{"	Rhino Controller Error:	Missing label.	"},
 356 	{"	Rhino Controller Error:	No program in memory.	"},
 357 	{"	Rhino Controller Error:	Insufficient teach pendant memory.	"},
 358 	{"	Rhino Controller Error:	Insufficient EEPROM memory.	"},
 359 	{"	Rhino Controller Error:	Can't replace first record.	"},
 360 	{"	Rhino Controller Error:	A pendant program already exists.	"},
 361 	{"	Rhino Controller Error:	NO ERROR	"},
 362 	{"	Rhino Controller Error:	NO ERROR	"},
 363 	{"	Rhino Controller Error:	NO ERROR	"},
 364 	{"	Rhino Controller Error:	NO ERROR	"},
 365 	{"	Rhino Controller Error:	Hard home routine failed.	"},
 366 	{"	Rhino Controller Error:	Hard home not set.	"},
 367 	{"	Rhino Controller Error:	Soft home not set.	"},
 368 	{"	Rhino Controller Error:	Arithmetic overflow.	"},
 369 	{"	Rhino Controller Error:	Trig function returned error.	"},
 370 	{"	Rhino Controller Error:	Error stack overflow.	"},
 371 	{"	Rhino Controller Error:	Still executing a trapezoidal move.	"},
 372 	{"	Rhino Controller Error:	Inactive motor referenced.	"},
 373 	{"	Rhino Controller Error:	Insufficient move data (velocity or acceleration = 0).	"},
 374 	{"	Rhino Controller Error:	Improper motor mode for command.	"},
 375 	{"	Rhino Controller Error:	Limit switch A not found.	"},
 376 	{"	Rhino Controller Error:	Limit switch B not found.	"},
 377 	{"	Rhino Controller Error:	Limit switch C not found.	"},
 378 	{"	Rhino Controller Error:	Limit switch D not found.	"},
 379 	{"	Rhino Controller Error:	Limit switch E not found.	"},
 380 	{"	Rhino Controller Error:	Limit switch F not found.	"},
 381 	{"	Rhino Controller Error:	Limit switch G not found.	"},
 382 	{"	Rhino Controller Error:	Limit switch H not found.	"},
 383 	{"	Rhino Controller Error:	NO ERROR	"},
 384 	{"	Rhino Controller Error:	Interpolation move out of bounds.	"},
 385 	{"	Rhino Controller Error:	xvz position out of bounds.	"},
 386 	{"	Rhino Controller Error:	NO ERROR	"},
 387 	{"	Rhino Controller Error:	NO ERROR	"},
 388 	{"	Rhino Controller Error:	NO ERROR	"},
 389 	{"	Rhino Controller Error:	NO ERROR	"},
 390 	{"	Rhino Controller Error:	NO ERROR	"},
 391 	{"	Rhino Controller Error:	NO ERROR	"},
 392 	{"	Rhino Controller Error:	NO ERROR	"},
 393 	{"	Rhino Controller Error:	NO ERROR	"},
 394 	{"	Rhino Controller Error:	NO ERROR	"},
 395 	{"	Rhino Controller Error:	Limit switch A stuck.	"},
 396 	{"	Rhino Controller Error:	Limit switch B stuck.	"},
 397 	{"	Rhino Controller Error:	Limit switch C stuck.	"},
 398 	{"	Rhino Controller Error:	Limit switch D stuck.	"},
 399 	{"	Rhino Controller Error:	Lim it switch E stuck.	"},
 400 	{"	Rhino Controller Error:	Limit switch F stuck.	"},
 401 	{"	Rhino Controller Error:	Lim it switch G stuck.	"},
 402 	{"	Rhino Controller Error:	Lim it switch H stuck. 	"},
 403 	{"	Rhino Controller Error:	NO ERROR	"},
 404 	{"	Rhino Controller Error:	NO ERROR	"},
 405 	{"	Rhino Controller Error:	NO ERROR	"},
 406 	{"	Rhino Controller Error:	Invalid robot type specifier.	"},
 407 	{"	Rhino Controller Error:	Invalid motor specifier.	"},
 408 	{"	Rhino Controller Error:	NO ERROR	"},
 409 	{"	Rhino Controller Error:	Invalid pendant mode.	"},
 410 	{"	Rhino Controller Error:	NO ERROR	"},
 411 	{"	Rhino Controller Error:	Invalid xyz specifier. 	"},
 412 	{"	Rhino Controller Error:	Invalid xyz parameter.	"},
 413 	{"	Rhino Controller Error:	NO ERROR	"},
 414 	{"	Rhino Controller Error:	NO ERROR	"},
 415 	{"	Rhino Controller Error:	Motor A stalled.	"},
 416 	{"	Rhino Controller Error:	Motor B stalled.	"},
 417 	{"	Rhino Controller Error:	Motor C stalled.	"},
 418 	{"	Rhino Controller Error:	Motor D stalled.	"},
 419 	{"	Rhino Controller Error:	Motor E stalled.	"},
 420 	{"	Rhino Controller Error:	Motor F stalled.	"},
 421 	{"	Rhino Controller Error:	Motor G stalled.	"},
 422 	{"	Rhino Controller Error:	Motor H stalled.	"},
 423 	{"	Rhino Controller Error:	NO ERROR	"},
 424 	{"	Rhino Controller Error:	NO ERROR	"},
 425 	{"	Rhino Controller Error:	Motor A's current limit circuit was activated.	"},
 426 	{"	Rhino Controller Error:	Motor B's current limit circuit was activated.	"},
 427 	{"	Rhino Controller Error:	Motor C's current limit circuit was activated.	"},
 428 	{"	Rhino Controller Error:	Motor D's current limit circuit was activated.	"},
 429 	{"	Rhino Controller Error:	Motor E's current limit circuit was activated.	"},
 430 	{"	Rhino Controller Error:	Motor F's current limit circuit was activated.	"},
 431 	{"	Rhino Controller Error:	Motor G's current limit circuit was activated.	"},
 432 	{"	Rhino Controller Error:	Motor H's current limit circuit was activated.	"},
 433 	{"	Rhino Controller Error:	Aux Port 1's current limit circuit was activated.	"},
 434 	{"	Rhino Controller Error:	Aux Port 2's current limit circuit was activated.	"},
 435 	{"	Rhino Controller Error:	NO ERROR	"},
 436 	{"	Rhino Controller Error:	NO ERROR	"},
 437 	{"	Rhino Controller Error:	NO ERROR	"},
 438 	{"	Rhino Controller Error:	NO ERROR	"},
 439 	{"	Rhino Controller Error:	NO ERROR	"},
 440 	{"	Rhino Controller Error:	NO ERROR	"},
 441 	{"	Rhino Controller Error:	NO ERROR	"},
 442 	{"	Rhino Controller Error:	NO ERROR	"}   
 443     };
 444     
 445     const char RhinoClassErrorMsgSOURCE[MAX_RC_ERROR_CODES][MSG_LENGTH]={
 446 	{"	Rhino Class Error:	BE HAPY, NO PROBLEM	"},
 447 	{"	Rhino Class Error:	'Error Code' fuera de rango	"},
 448 	{"	Rhino Class Error:	'Log Level' fuera de rango	"},
 449 	{"	Rhino Class Error:	No se pudo crear el archivo de registro "},
 450 	{"	Rhino Class Error:	NO ERROR	"},
 451 	{"	Rhino Class Error:	NO ERROR	"},
 452 	{"	Rhino Class Error:	NO ERROR	"},
 453 	{"	Rhino Class Error:	NO ERROR	"},
 454 	{"	Rhino Class Error:	NO ERROR	"},
 455 	{"	Rhino Class Error:	NO ERROR	"},
 456 	{"	Rhino Class Error:	NO ERROR	"},
 457 	{"	Rhino Class Error:	NO ERROR	"},
 458 	{"	Rhino Class Error:	NO ERROR	"},
 459 	{"	Rhino Class Error:	NO ERROR	"},
 460 	{"	Rhino Class Error:	NO ERROR	"},
 461 	{"	Rhino Class Error:	NO ERROR	"},
 462 	{"	Rhino Class Error:	NO ERROR	"},
 463 	{"	Rhino Class Error:	NO ERROR	"},
 464 	{"	Rhino Class Error:	NO ERROR	"},
 465 	{"	Rhino Class Error:	NO ERROR	"},
 466 	{"	Rhino Class Error:	NO ERROR	"},
 467 	{"	Rhino Class Error:	NO ERROR	"},
 468 	{"	Rhino Class Error:	NO ERROR	"},
 469 	{"	Rhino Class Error:	NO ERROR	"},
 470 	{"	Rhino Class Error:	NO ERROR	"},
 471 	{"	Rhino Class Error:	NO ERROR	"},
 472 	{"	Rhino Class Error:	NO ERROR	"},
 473 	{"	Rhino Class Error:	NO ERROR	"},
 474 	{"	Rhino Class Error:	NO ERROR	"},
 475 	{"	Rhino Class Error:	NO ERROR	"},
 476 	{"	Rhino Class Error:	NO ERROR	"},
 477 	{"	Rhino Class Error:	NO ERROR	"}
 478     };
 479 
 480     for(int i=0; i<MAX_RB_ERROR_CODES; i++)
 481 	strcpy(_RhinoBotErrorMsg[i], RhinoBotErrorMsgSOURCE[i]);
 482 
 483     for(int i=0; i<MAX_RC_ERROR_CODES; i++)
 484 	strcpy(_RhinoClassErrorMsg[i], RhinoClassErrorMsgSOURCE[i]);
 485 
 486 /*Falta completar los mensajes del sistemas*/
 487     const char RhinoBotStatusMsgSOURCE[MAX_RB_STATUS_CODES][MSG_LENGTH]={
 488 	{"	Rhino Controller Status:	BE HAPY, NO PROBLEM	"},
 489 	{"	Rhino Controller Status:	At least one motor is performing a trapezoidal move"},
 490 	{"	Rhino Controller Status:	A system error has ocurred"},
 491 	{"	Rhino Controller Status:	The general purpose delay timer is active	"},
 492 	{"	Rhino Controller Status:	At least one wait on input or wait on switch is still pending	"},
 493 	{"	Rhino Controller Status:	No teach pedant is connected	"},
 494 	{"	Rhino Controller Status:	The teach pedant ENTER key hast been pressed	"},
 495 	{"	Rhino Controller Status:	The teach pedant ESCAPER key hast been pressed	"},
 496 	{"	Rhino Controller Status:	A teach pedant error has ocurred	"},	
 497 	{"	Rhino Controller Status:	Motor A is executing a trapezoidal move	"},
 498 	{"	Rhino Controller Status:	Motor B is executing a trapezoidal move	"},
 499 	{"	Rhino Controller Status:	Motor C is executing a trapezoidal move	"},
 500 	{"	Rhino Controller Status:	Motor D is executing a trapezoidal move	"},
 501 	{"	Rhino Controller Status:	Motor E is executing a trapezoidal move	"},
 502 	{"	Rhino Controller Status:	Motor F is executing a trapezoidal move	"},
 503 	{"	Rhino Controller Status:	Motor G is executing a trapezoidal move	"},
 504 	{"	Rhino Controller Status:	Motor H is executing a trapezoidal move	"},
 505 	{"	Rhino Controller Status:	The motor is either stationary or in a mode other than trapezoidal "},
 506 	{"	Rhino Controller Status:	NC "}
 507     };
 508     const char RhinoClassStatusMsgSOURCE[MAX_RC_STATUS_CODES][MSG_LENGTH]={
 509 	{"	Rhino Class Status:	BE HAPY, NO PROBLEM	"},
 510 	{"	Rhino Class Status:	Se asume LogLevel 3 por defecto	"},
 511 	{"	Rhino Class Status:	Depuracion de comando pendiente	"},
 512 	{"	Rhino Class Status:	NC	"}
 513     };
 514     
 515     for(int i=0; i<MAX_RB_STATUS_CODES; i++)
 516 	strcpy(_RhinoBotStatusMsg[i], RhinoBotStatusMsgSOURCE[i]);
 517     
 518     for(int i=0; i<MAX_RC_STATUS_CODES; i++)
 519 	strcpy(_RhinoClassStatusMsg[i], RhinoClassStatusMsgSOURCE[i]);
 520     
 521     return 0;
 522 }
 523 
 524 int Rhino::ProcessCommandToRhino(char * _sCommand)
 525 /***************************************************************/
 526 /* Esta funcion procesa los comandos de estado del sistema     */
 527 /* Parametros:                                                 */
 528 /* [Status cmd I(char *)                                       */
 529 /* I:in O:out                                                  */
 530 /***************************************************************/
 531 {
 532     if(!strcmp(_sCommand, "SA") || !strcmp(_sCommand, "sa"))
 533  	LastCmdAndMsg.uiLastCommandtoRhino = SA;
 534 //     else if(!strcmp(_sCommand, "SC") || !strcmp(_sCommand, "sc"))
 535 // 	LastCmdAndMsg.uiLastCommandtoRhino = SC;
 536     else if(!strcmp(_sCommand, "SE") || !strcmp(_sCommand, "se"))
 537  	LastCmdAndMsg.uiLastCommandtoRhino = SE;
 538 //     else if(!strcmp(_sCommand, "SM") || !strcmp(_sCommand, "sm"))
 539 // 	LastCmdAndMsg.uiLastCommandtoRhino = SM;
 540 //     else if(!strcmp(_sCommand, "SP") || !strcmp(_sCommand, "sp"))
 541 // 	LastCmdAndMsg.uiLastCommandtoRhino = SP;
 542     else if(!strcmp(_sCommand, "SS") || !strcmp(_sCommand, "ss"))
 543  	LastCmdAndMsg.uiLastCommandtoRhino = SS;
 544 //     else if(!strcmp(_sCommand, "SU") || !strcmp(_sCommand, "su"))
 545 // 	LastCmdAndMsg.uiLastCommandtoRhino = SU;
 546 //     else if(!strcmp(_sCommand, "SV") || !strcmp(_sCommand, "sv"))
 547 // 	LastCmdAndMsg.uiLastCommandtoRhino = SV;
 548 //     else if(!strcmp(_sCommand, "SX") || !strcmp(_sCommand, "sx"))
 549 // 	LastCmdAndMsg.uiLastCommandtoRhino = SX;
 550 //     else if(!strcmp(_sCommand, "SZ") || !strcmp(_sCommand, "sz"))
 551 // 	LastCmdAndMsg.uiLastCommandtoRhino = SZ;
 552     else
 553 	LastCmdAndMsg.uiLastCommandtoRhino = NC;
 554    
 555     strcpy(LastCmdAndMsg.LastCommandtoRhino, _sCommand);
 556     strcpy(LastCmdAndMsg.LastMessageFromRhino, "");
 557 
 558     return 0;
 559 /*CODIFICACION PENDIENTE*/
 560 }
 561 
 562 int Rhino::ProcessCommandToRhino(char * _sCommand, unsigned int *_iCmdCode)
 563 /***************************************************************/
 564 /* Esta funcion procesa los comandos de estado del sistema y   */
 565 /* devuelve el enumerador correspondiente a ese comando        */  
 566 /* Parametros:                                                 */
 567 /* [Status cmd I(char *); Status cmd code O(unsigned int)]     */
 568 /* I:in O:out                                                  */
 569 /***************************************************************/
 570 {
 571     if(!strcmp(_sCommand, "SA") || !strcmp(_sCommand, "sa")){
 572  	LastCmdAndMsg.uiLastCommandtoRhino = SA;
 573 	*_iCmdCode = SA;
 574     }
 575 //    else if(!strcmp(_sCommand, "SC") || !strcmp(_sCommand, "sc"))
 576 //	*_iCmdCode = SC;
 577     else if(!strcmp(_sCommand, "SE") || !strcmp(_sCommand, "se")){
 578  	LastCmdAndMsg.uiLastCommandtoRhino = SE;
 579 	*_iCmdCode = SE;
 580     }
 581 //    else if(!strcmp(_sCommand, "SM") || !strcmp(_sCommand, "sm"))
 582 //	*_iCmdCode = SM;
 583 //    else if(!strcmp(_sCommand, "SP") || !strcmp(_sCommand, "sp"))
 584 //	*_iCmdCode = SP;
 585     else if(!strcmp(_sCommand, "SS") || !strcmp(_sCommand, "ss")){
 586  	LastCmdAndMsg.uiLastCommandtoRhino = SS;
 587 	*_iCmdCode = SS;
 588     }
 589 //    else if(!strcmp(_sCommand, "SU") || !strcmp(_sCommand, "su"))
 590 // 	*_iCmdCode = SU;
 591 //     else if(!strcmp(_sCommand, "SV") || !strcmp(_sCommand, "sv"))
 592 // 	*_iCmdCode = SV;
 593 //     else if(!strcmp(_sCommand, "SX") || !strcmp(_sCommand, "sx"))
 594 // 	*_iCmdCode = SX;
 595 //     else if(!strcmp(_sCommand, "SZ") || !strcmp(_sCommand, "sz"))
 596 // 	*_iCmdCode = SZ;
 597     else{
 598  	LastCmdAndMsg.uiLastCommandtoRhino = NC;
 599 	*_iCmdCode = NC;
 600     }
 601 
 602     strcpy(LastCmdAndMsg.LastCommandtoRhino, _sCommand);
 603     strcpy(LastCmdAndMsg.LastMessageFromRhino, "");
 604     
 605     return 0;
 606 /*CODIFICACION PENDIENTE*/
 607 }
 608 
 609 int Rhino::ProcessMessageFromRhino(char * _StringCode)
 610 /***************************************************************/
 611 /* Esta funcion procesa la respuesta del Rhino ante petitorios */
 612 /* de estado y asocia los mensajes de error y estado           */
 613 /* correspondientes.                                           */
 614 /* Parametros:                                                 */
 615 /* Rhino message I(char *);                                    */
 616 /***************************************************************/
 617 {
 618     strcpy(LastCmdAndMsg.LastMessageFromRhino, _StringCode);
 619 
 620     if(LastCmdAndMsg.uiLastCommandtoRhino != NC){
 621 	
 622 	unsigned int _uiCode = atoi(_StringCode);
 623 	
 624 	switch(LastCmdAndMsg.uiLastCommandtoRhino)
 625 	{
 626 	    case SS:
 627 		uiStatusCode = _uiCode;
 628 		
 629 		if(_uiCode & 128){
 630 		    ProcessStatusMsg(RB_MOTOR_MOVE);
 631 		}
 632 		if(_uiCode & 64){
 633 		    ProcessStatusMsg(RB_ERROR);
 634 		}
 635 		if(_uiCode & 32){
 636 		    ProcessStatusMsg(RB_DTIMER_ACT);
 637 		}
 638 		if(_uiCode & 16){
 639 		    ProcessStatusMsg(RB_WAIT_PENDING);
 640 		}
 641 		if(_uiCode & 8){
 642 		    ProcessStatusMsg(RB_NO_TP);
 643 		}
 644 		if(_uiCode & 4){
 645 		    ProcessStatusMsg(RB_TP_ENTER);
 646 		}
 647 		if(_uiCode & 2){
 648 		    ProcessStatusMsg(RB_TP_ESC);
 649 		}
 650 		if(_uiCode & 1){
 651 		    ProcessStatusMsg(RB_TP_ERROR);
 652 		}
 653 		if(_uiCode == 0){
 654 		    ProcessStatusMsg(RB_STS_NS);
 655 		}
 656 		break;
 657 		
 658 	    case SA:
 659 		uiStatusCode = _uiCode;
 660 		
 661 		if(_uiCode & 128){
 662 		    ProcessStatusMsg(RB_MOTOR_H_TMON);
 663 		}
 664 		if(_uiCode & 64){
 665 		    ProcessStatusMsg(RB_MOTOR_G_TMON);
 666 		}
 667 		if(_uiCode & 32){
 668 		    ProcessStatusMsg(RB_MOTOR_F_TMON);
 669 		}
 670 		if(_uiCode & 16){
 671 		    ProcessStatusMsg(RB_MOTOR_E_TMON);
 672 		}
 673 		if(_uiCode & 8){
 674 		    ProcessStatusMsg(RB_MOTOR_D_TMON);
 675 		}
 676 		if(_uiCode & 4){
 677 		    ProcessStatusMsg(RB_MOTOR_C_TMON);
 678 		}
 679 		if(_uiCode & 2){
 680 		    ProcessStatusMsg(RB_MOTOR_B_TMON);
 681 		}
 682 		if(_uiCode & 1){
 683 		    ProcessStatusMsg(RB_MOTOR_A_TMON);
 684 		}
 685 		if(_uiCode == 0){
 686 		    ProcessStatusMsg(RB_MOTORS_NOTM);
 687 		}
 688 		break;
 689 		
 690 	    case SE:
 691 		uiErrorCode = _uiCode;
 692 		ProcessErrorMsg(_uiCode);
 693 		break;
 694 		
 695 	    default:
 696 		ProcessStatusMsg(RC_DEP_CMD_PENDING);
 697 		break;
 698 	}
 699 	return 0;   
 700     }
 701     
 702     ProcessStatusMsg(RC_DEP_CMD_PENDING);
 703     return 0;
 704 /*CODIFICACION PENDIENTE*/
 705 }
 706 
 707 int Rhino::ProcessMessageFromRhino(unsigned int _iStatusCmd, char * _StringCode, unsigned int *_iCode, char * _sMessage)
 708 /***************************************************************/
 709 /* Esta funcion procesa la respuesta del Rhino ante petitorios */
 710 /* de estado y asocia los mensajes de error y estado           */
 711 /* orrespondientes.                                            */
 712 /* Parametros:                                                 */
 713 /* [Status comd code I(unsigned int); Rhino message I(char *); */ 
 714 /* Rhino error code O(unsigned int);                           */
 715 /* Rhino error mesage O(char *)]                               */
 716 /***************************************************************/
 717 {
 718     strcpy(LastCmdAndMsg.LastMessageFromRhino, _StringCode);
 719 
 720     if(LastCmdAndMsg.uiLastCommandtoRhino != NC){
 721 	
 722 	*_iCode = atoi(_StringCode);
 723 	
 724 	unsigned int uiCode = *_iCode;
 725 	
 726 	switch(_iStatusCmd)
 727 	{
 728 	    case SS:
 729 		uiStatusCode = uiCode;
 730 		
 731 		if(uiCode & 128){
 732 		    ProcessStatusMsg(RB_MOTOR_MOVE);
 733 		    get_StatusMsg(_sMessage);  // :S
 734 		}
 735 		if(uiCode & 64){
 736 		    ProcessStatusMsg(RB_ERROR);
 737 		    get_StatusMsg(_sMessage);  // :(
 738 		}
 739 		if(uiCode & 32){
 740 		    ProcessStatusMsg(RB_DTIMER_ACT);
 741 		    get_StatusMsg(_sMessage);
 742 		}
 743 		if(uiCode & 16){
 744 		    ProcessStatusMsg(RB_WAIT_PENDING);
 745 		    get_StatusMsg(_sMessage);
 746 		}
 747 		if(uiCode & 8){
 748 		    ProcessStatusMsg(RB_NO_TP);
 749 		    get_StatusMsg(_sMessage);
 750 		}
 751 		if(uiCode & 4){
 752 		    ProcessStatusMsg(RB_TP_ENTER);
 753 		    get_StatusMsg(_sMessage);
 754 		}
 755 		if(uiCode & 2){
 756 		    ProcessStatusMsg(RB_TP_ESC);
 757 		    get_StatusMsg(_sMessage);
 758 		}
 759 		if(uiCode & 1){
 760 		    ProcessStatusMsg(RB_TP_ERROR);
 761 		    get_StatusMsg(_sMessage);
 762 		}
 763 		if(uiCode == 0){
 764 		    ProcessStatusMsg(RB_STS_NS);
 765 		    get_StatusMsg(_sMessage);  // :D
 766 		}
 767 		break;
 768 		
 769 	    case SE:
 770 		uiErrorCode = uiCode;
 771 		ProcessErrorMsg(uiCode);
 772 		get_ErrorMsg(_sMessage);
 773 		break;
 774 		
 775 	    case SA:
 776 		uiStatusCode = uiCode;
 777 		
 778 		if(uiCode & 128){
 779 		    ProcessStatusMsg(RB_MOTOR_H_TMON);
 780 		    get_StatusMsg(_sMessage);
 781 		}
 782 		if(uiCode & 64){
 783 		    ProcessStatusMsg(RB_MOTOR_G_TMON);
 784 		    get_StatusMsg(_sMessage);
 785 		}
 786 		if(uiCode & 32){
 787 		    ProcessStatusMsg(RB_MOTOR_F_TMON);
 788 		    get_StatusMsg(_sMessage);
 789 		}
 790 		if(uiCode & 16){
 791 		    ProcessStatusMsg(RB_MOTOR_E_TMON);
 792 		    get_StatusMsg(_sMessage);
 793 		}
 794 		if(uiCode & 8){
 795 		    ProcessStatusMsg(RB_MOTOR_D_TMON);
 796 		    get_StatusMsg(_sMessage);
 797 		}
 798 		if(uiCode & 4){
 799 		    ProcessStatusMsg(RB_MOTOR_C_TMON);
 800 		    get_StatusMsg(_sMessage);
 801 		}
 802 		if(uiCode & 2){
 803 		    ProcessStatusMsg(RB_MOTOR_B_TMON);
 804 		    get_StatusMsg(_sMessage);
 805 		}
 806 		if(uiCode & 1){
 807 		    ProcessStatusMsg(RB_MOTOR_A_TMON);
 808 		    get_StatusMsg(_sMessage);
 809 		}
 810 		if(uiCode == 0){
 811 		    ProcessStatusMsg(RB_MOTORS_NOTM);
 812 		    get_StatusMsg(_sMessage);
 813 		}
 814 		break;
 815 		
 816 	    default:
 817 		ProcessStatusMsg(RC_DEP_CMD_PENDING);
 818 		break;
 819 	}
 820 	return 0;    
 821     }
 822     
 823     ProcessStatusMsg(RC_DEP_CMD_PENDING);
 824     return 0;
 825 /*CODIFICACION PENDIENTE*/
 826 }
 827 
 828 int Rhino::get_StatusMsg(char *_cTextStatus)
 829 /***************************************************************/
 830 /*  Devuelve le mensaje de estado del ultimo mensaje generado  */
 831 /***************************************************************/
 832 {
 833     /* Rhino Bot Status Messages */
 834     if(uiStatusCode >= 0 && uiStatusCode <= MAX_RB_STATUS_CODES)
 835     {
 836 	strcpy(_cTextStatus, RhinoBotStatusMsg[uiStatusCode]);      
 837 	return 0;
 838     }
 839 
 840     /* Rhino Class Status Messages */
 841     if(uiStatusCode > MAX_RB_STATUS_CODES && uiStatusCode <= (MAX_RB_STATUS_CODES + MAX_RC_STATUS_CODES))
 842     {
 843 	strcpy(_cTextStatus, RhinoClassStatusMsg[uiStatusCode-MAX_RB_STATUS_CODES]);
 844 	return 0;
 845     }
 846     
 847     ProcessErrorMsg(ERR_CODE);
 848     return -1;
 849 }
 850 int Rhino::get_StatusMsg(unsigned int _uiStatusCode, char *_cTextStatus)
 851 /***************************************************************/
 852 /*  Devuelve le mensaje de estado corrspondiente al codigo de  */
 853 /*  status pasado como parametro                               */
 854 /***************************************************************/
 855 {
 856  /* Rhino Bot Status Messages*/
 857     if(_uiStatusCode >= 0 && _uiStatusCode <= MAX_RB_STATUS_CODES)
 858     {
 859 	strcpy(_cTextStatus, RhinoBotStatusMsg[_uiStatusCode]);      
 860 	return 0;
 861     }
 862 
 863     /* Rhino Class Status Messages*/
 864     if(_uiStatusCode > MAX_RB_STATUS_CODES && _uiStatusCode <= (MAX_RB_STATUS_CODES + MAX_RC_STATUS_CODES))
 865     {
 866 	strcpy(_cTextStatus, RhinoClassStatusMsg[_uiStatusCode-MAX_RB_STATUS_CODES]);
 867 	return 0;
 868     }
 869     
 870     ProcessErrorMsg(ERR_CODE);
 871     return -1;
 872 }
 873 int Rhino::get_StatusCode(unsigned int *_uiStatusCode)
 874 /***************************************************************/
 875 /*  Devuelve el codigo de status del ultimo mensaje generado   */
 876 /***************************************************************/
 877 {
 878     *_uiStatusCode = uiStatusCode;
 879     return 0;
 880 }

Archivos adjuntos

Para referirse a los adjuntos de una página, usa attachment:nombredelarchivo, como se muestra abajo en la lista de archivos. NO uses la URL del enlace [get], ya que puede cambiar fácilmente y dejar de funcionar.
  • [obtener | ver] (2010-05-19 15:03:32, 0.4 KB) [[attachment:ChangeLog.txt]]
  • [obtener | ver] (2010-05-19 15:03:33, 76.3 KB) [[attachment:ClienteRhinoVisu.png]]
  • [obtener | ver] (2010-05-19 15:03:33, 4.6 KB) [[attachment:DemoVisu.png]]
  • [obtener | ver] (2010-05-19 15:03:33, 30.9 KB) [[attachment:DiagramaServidorRhino.png]]
  • [obtener | ver] (2010-05-19 15:03:33, 28.2 KB) [[attachment:Diagramas_De_Flujo_Servidor_V3.0.zip]]
  • [obtener | ver] (2010-05-19 15:03:33, 0.9 KB) [[attachment:Dir-Info.txt]]
  • [obtener | ver] (2010-05-19 15:03:33, 423.4 KB) [[attachment:DocClaseRhinoStatus.zip]]
  • [obtener | ver] (2010-05-19 15:03:34, 4.1 KB) [[attachment:EstructuraDirectoriosDesarrollo.png]]
  • [obtener | ver] (2010-05-19 15:03:34, 2.2 KB) [[attachment:HistoricoDeCambios.txt]]
  • [obtener | ver] (2010-05-19 15:03:34, 0.8 KB) [[attachment:Makefile]]
  • [obtener | ver] (2010-05-19 15:03:34, 688.7 KB) [[attachment:Proyecto-Rhino.pdf]]
  • [obtener | ver] (2010-05-19 15:03:37, 5622.6 KB) [[attachment:Rhino-AGV_Fotos.zip]]
  • [obtener | ver] (2010-05-19 15:03:42, 0.2 KB) [[attachment:RhinoLog.txt]]
  • [obtener | ver] (2010-05-19 15:03:42, 364.8 KB) [[attachment:ServidorRhinoVisu.png]]
  • [obtener | ver] (2010-05-19 15:03:43, 0.5 KB) [[attachment:_Makefile]]
  • [obtener | ver] (2010-05-19 15:03:43, 3.8 KB) [[attachment:_terminal.cpp]]
  • [obtener | ver] (2010-05-19 15:03:43, 1.0 KB) [[attachment:change_log.txt]]
  • [obtener | ver] (2010-05-19 15:03:43, 4.6 KB) [[attachment:cmddef.h]]
  • [obtener | ver] (2010-05-19 15:03:43, 11.4 KB) [[attachment:comSerial.cpp]]
  • [obtener | ver] (2010-05-19 15:03:43, 5.5 KB) [[attachment:comSerial.h]]
  • [obtener | ver] (2010-05-19 15:03:43, 5.8 KB) [[attachment:errdef.h]]
  • [obtener | ver] (2010-05-19 15:03:43, 0.5 KB) [[attachment:rc_error_log.txt]]
  • [obtener | ver] (2010-05-19 15:03:43, 30.6 KB) [[attachment:rhino.cpp]]
  • [obtener | ver] (2010-05-19 15:03:43, 5.2 KB) [[attachment:rhino.h]]
  • [obtener | ver] (2010-05-19 15:03:43, 2.5 KB) [[attachment:statusdef.h]]
  • [obtener | ver] (2010-05-19 15:03:43, 0.7 KB) [[attachment:terminal.cpp]]
  • [obtener | ver] (2010-05-19 15:03:43, 0.5 KB) [[attachment:utilities.txt]]
 All files | Selected Files: delete move to page copy to page

No tienes permisos para adjuntar un archivo a esta página.