Example #1
0
int main( int argc, char **argv )
{
#ifdef WIN32
	SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sigint_handler, TRUE );
#else
	struct sigaction act;
	memset( &act, 0, sizeof( act ) );
	act.sa_handler = sigint_handler;
	sigaction( SIGINT, &act, NULL );
#endif

	com = Com_construct();

	if( argc > 1 )
	{
		Com_setAddress( com, argv[1] );
	}
	else
	{
		Com_setAddress( com, "172.26.1.1" );
		//Com_setAddress( com, "192.168.101.101" );
	}

	if( FALSE == Com_connect( com ) )
	{
		error( "Error on connect" );
	}
	else
	{
		char addressBuffer[256];
		Com_address( com, addressBuffer, 256 );
		printf( "Connected to %s\n", addressBuffer );
	}

	cbha = CompactBHA_construct();

	drive();

	CompactBHA_destroy( cbha );
	Com_destroy( com );

	printf( "Press any key to exit...\n" );

	waitForKey();
}
Example #2
0
float valeurCapteurInduction_c(int iNumPin, const char* hostname){

	//Déclaration et initialisation des variables
	ComId com;
	AnalogInputId pinCapteur;

	int i;
	boolean connectSetCom = 0;
	boolean connectPin = 0;
	boolean tempsInit = 1;
	float fvalue = -1.0;

	int tailleFenetreValue = 20;
	int nbValueMoyenne = 10;
	float value[20];

	//Connection à Robotino (via adresse IP)
	com = Com_construct();
	Com_setAddress(com,hostname);

	if( FALSE == Com_connect(com) )
	{
		fprintf(stderr, "Error on connect\n");
		return -1.0;
	}
	else
	{
		char addressBuffer[256];
		Com_address( com, addressBuffer, 256 );
		printf( "Connected to %s\n", addressBuffer );
	}
	
	//Construction de l'objet analogique : numero du pin allant de 0 à 7 (AIN1 -> AIN8)
	pinCapteur = AnalogInput_construct(iNumPin-1);

	//On associe notre objet analogique à notre interface de communication
	connectSetCom = AnalogInput_setComId(pinCapteur, com);	

	if(connectSetCom == 0){
		fprintf(stderr, "Error on connectSetComId pin\n");
		return -1.0;
	}

	//On associe le numéro de pin à notre objet
	connectPin = AnalogInput_setInputNumber(pinCapteur, iNumPin-1);
	
	//Initialisation capteur
	while(tempsInit){

		if(connectPin == 0){
			printf( "Erreur Pin Connexion \n" );
			break;
		}

		//Permet d'initialiser notre capteur : on sort de la boucle une fois que l'on lit une valeur > 0
		if(AnalogInput_value(pinCapteur) > 0.001){
			tempsInit = 0;
		}
	}

	//Récuperation valeur capteur
	for(i=0;i<tailleFenetreValue;i++){
		value[i] = AnalogInput_value(pinCapteur);
	}
		 
	//Moyenne des X dernières valeurs afin d'éliminer des erreurs de mesures
	for(i=nbValueMoyenne;i<tailleFenetreValue;i++){
		if(fvalue == -1.0){
			fvalue = 0;
		}
		fvalue = fvalue + value[i];
	}
	
	//Valeur moyenne du capteur induction
	fvalue = fvalue/(tailleFenetreValue-nbValueMoyenne);
	fprintf(stdout, "Valeur Induction : %f \n", fvalue);
	
	//On détruit les objets associés à notre interface de communication
	AnalogInput_destroy(pinCapteur);
	Com_destroy(com);

	return fvalue;
}