void defaite() { // Il manque a faire le fichier jaiperdu AUDIO_SetVolume(90); /*AUDIO_PlayFile("jaiperdu.mp3");*/ tourner(180, GAUCHE); THREAD_MSleep(3000); tourner(180, DROITE); }
void victoire() { AUDIO_SetVolume(100); AUDIO_PlayFile("jaigagner.mp3"); tourner(45, GAUCHE); tourner(90, DROITE); tourner(90, GAUCHE); tourner(90, DROITE); tourner(360, GAUCHE); tourner(360, DROITE); tourner(45, GAUCHE); }
int main(int argc, char *argv[]) { int cadence = ANNEAU_CADENCE_DEFAULT; // Cadence définit en millisecondes if (argc < 2) { __raise(-1, "Usage: %s <projet [, cadence]>", argv[0]); } // // Initialisation init(argv); // Cadence if (argc > 2) { cadence = atoi(argv[2]); } // Anneau int i; Anneau ano; ano.id = __pid; for (i = 0; i < ANNEAU_NUM_CASES; i++) { ano.cases[i].num = i; ano.cases[i].type = VIDE; ano.connexion[i] = 0; } *((Anneau *) __anneau) = ano; // // Démarrage printf("== Démarrage de l'anneau...\n"); printf("==== Cadence de rotation: %d ms/tour\n", cadence); // info(); // // Petite pause usleep(2000); // // Rotation int rotation = 1; while (1) { usleep(cadence * 1000); // Attente // La roue tourne d'un pas tourner(); printf("\tRotation %5d: \n", rotation++); info(); // Émission d'un signalS sonore pour informer les robots ding(); } __endProcess(); return 0; }
void RandomIA::tournerAngleDroitDroite(float puissance){ tourner(puissance, 90.0); }
void RandomIA::tournerAngleDroitGauche(float puissance){ tourner(puissance, -90.0); }
int main() { int socketServeur; int socketClient = -1; int clientConnecte = 0; int i; int ecrit = 0; int lu = -1; int speed = 500; int stopCount = 0; int distance = 0; int distance_32bits = 0; struct sockaddr_in addrServeur; socklen_t longueurAdresse; // Nombre d'octets de la structure sockaddr_in char nomDuClient[1024], portDuClient[32]; char commande = 'X'; char clientONOFF = 'o'; pthread_t thread1; pthread_t thread2; // Initialisation des GPIO initGPIO(); // Initialisation Mutex if(pthread_mutex_init(&lock, NULL) != 0) { perror("mutex"); exit(-1); } pthread_create(&thread1, NULL, thread_distance, &socketClient); pthread_create(&thread2, NULL, thread_speed, &socketClient); printf("creation du thread1 et 2\n"); // Cree un socket de communication socketServeur = socket(PF_INET, SOCK_STREAM, 0); if(socketServeur == -1) { perror("Socket"); exit(-1); } printf("Socket crée avec succès ! (%d)\n", socketServeur); addrServeur.sin_addr.s_addr = INADDR_ANY; //toutes addrServeur.sin_family = PF_INET; addrServeur.sin_port = htons(PORT); // lose the pesky "Address already in use" error message int yes = 1; if( setsockopt(socketServeur, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) { perror("setsockopt"); exit(errno); } // Demande l'attachement local de la socket longueurAdresse = sizeof(addrServeur); if( bind(socketServeur, (struct sockaddr *)&addrServeur, longueurAdresse) == -1 ) { perror("bind"); exit(-2); } printf("Socket attachée avec succès!\n"); if (listen(socketServeur, CLIENT_MAX) == -1) { perror("listen"); exit(errno); } printf("Socket placée en écoute passive...\n"); printf("Attente d'une demande de connexion (quitter avec Cltrl-C)\n\n"); while(1) { if(clientConnecte == 0) { socketClient = accept4(socketServeur, (struct sockaddr *)&addrServeur, &longueurAdresse, SOCK_NONBLOCK); if(socketClient == -1 ) { printf("errno : %d\n", errno); perror("accept"); close(socketClient); close(socketServeur); exit(errno); } printf("Nouveau client !\n"); if ( getnameinfo((struct sockaddr*)&addrServeur, sizeof(addrServeur), nomDuClient, sizeof(nomDuClient), portDuClient, sizeof(portDuClient), NI_NUMERICHOST | NI_NUMERICSERV) == 0) { printf("client=%s, port=%s\n", nomDuClient, portDuClient); } clientConnecte = 1; //ecrits = write(socketClient, &clientONOFF, 1); } // nanosleep((struct timespec[]){{0, 10000000}}, NULL); lu = read(socketClient, &commande, 1); if(lu == -1) { if(errno == EAGAIN) // Nothing to read { continue; } else { printf("Error reading from socketClient ! \n"); printf("errno = %d \n", errno); break; } } if(lu == 0) { printf("Socket closed ! \n"); speed = 500; avancer(0); commande = 's'; close(socketClient); clientConnecte = 0; continue; } printf("lu = %d\n", lu); printf("commande = %c\n", commande); switch(commande) { case 'a' : //printf("AVANCE\n"); avancer(speed); break; case 'r' : //printf("RECULE\n"); reculer(speed); break; case 'd' : //printf("DROITE\n"); tourner(DROITE, speed); break; case 'g' : //printf("GAUCHE\n"); tourner(GAUCHE, speed); break; case '+' : speed = speedChange(UP, speed); break; case '-' : speed = speedChange(DOWN, speed); break; case 's' : //printf("REPOS\n"); avancer(0); } //distance = ultrason(); } close(socketClient); close(socketServeur); return 0; }
int mainCRJ() { int essai, comptePastille, pastille = 0; int vitesse = 50; int direction = 1; int gagner = 0; gestionAvantDeCommencer(); transmettreMot(1, "A TOI"); for (essai = 1; essai < 11 && !gagner; ++essai) { if (essai % 2 == 1) { pastille = 0; } else { pastille = 3; } while (capt_boutonEssai != 1) { THREAD_MSleep(20); } MOTOR_SetSpeed(MOTOR_RIGHT, vitesse * vitesseDroitePRGauche); MOTOR_SetSpeed(MOTOR_LEFT, vitesse); suivreLigne(); for (comptePastille = 0; comptePastille < 4; ++comptePastille) { while (couleur == eBLANC || couleur == eNOIR || couleur == eORANGE) { suivreLigne(); THREAD_MSleep(20); } stockerCouleur(couleur, essai, pastille); if (essai % 2 == 1) { ++pastille; } else { --pastille; } while (couleur != eBLANC) { suivreLigne(); THREAD_MSleep(20); } } while (couleur != eORANGE) { suivreLigne(); THREAD_MSleep(20); } tourner(180, DROITE); //transmettre essai, verif couleurs, etc int verifNbrCouleurABonnePlace(essai); } /* gestionAvantDeCommencer(); int essai, pastille = 0; int direction = 1; int gagner = 0; while (essai != 10 && gagner != 1) { while (capt_boutonEssai == 1) { suivreLigne(); if (direction == 1) { while (pastille != nbPastilles) { int couleurCaptee = lireCouleur(); if (couleurCaptee != blanc) { stockerCouleur(couleurCaptee, essai, pastille); pastille++; do { int couleur = lireCouleur(); THREAD_MSleep(200); } while (couleur != blanc); } } direction *= (-1); MOTOR_SetSpeed(MOTOR_LEFT, 0); MOTOR_SetSpeed(MOTOR_RIGHT, 0); tourner(180, DROITE); } else { pastille = (nbPastilles - 1); while (pastille != (-1)) { int couleurCaptee = lireCouleur(); if (couleurCaptee != blanc) { stockerCouleur(couleurCaptee, essai, pastille); pastille--; do { int couleur = lireCouleur(); THREAD_MSleep(200); } while (couleur != blanc); } } direction *= (-1); MOTOR_SetSpeed(MOTOR_LEFT, 0); MOTOR_SetSpeed(MOTOR_RIGHT, 0); } THREAD_MSleep(200); verifNbrCouleurOK(essai); verifNbrCouleurABonnePlace(essai); storeDansStructure(essai); envoieStringStructure(essai); debugAffichage(direction, essai); //Ajouter : Fonction d'affichage sur la matrice de LED int i = 0; int j = 0; for (i = 0; i < nbPastilles; i++) { if (tableau_a_verifier[i][essai] == vert) j++; } if (j == nbPastilles) gagner = 1; essai++; } THREAD_MSleep(200); } if (gagner == 1) victoire(); else defaite(); THREAD_MSleep(50); // Sleep for 50ms */ return 0; }