Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #15 on: May 02, 2012, 02:42:26 am » |
alors mes premieres problématique :
comment fait on un appel de fonction ?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #16 on: May 02, 2012, 02:50:07 am » |
ps: le copier coller bête et méchant ça na rien de bon !!
Skizo !
Merci, je suis pas programmeur, mais j ai quelques notions quand meme
|
|
|
|
|
Logged
|
|
|
|
|
83 - var
Offline
Sr. Member
Karma: 0
Posts: 452
ARDUINO Powa !
|
 |
« Reply #17 on: May 02, 2012, 03:40:40 am » |
lol te vexe pas  alors appel de fonction: Fonction: void hello_word (String hello) {String hello;
Serial.print(hello);
return 0; }
appel:
String envoyer ="saluuut"; hello_word(envoyer);
résultat:
sur la liaison série: saluut
si ta fonction n'a pas besoin de paramètre:
void attendre() { delay(10000);//attend 10s }
appel:
attendre();//attend 10s
voila tout simplement =) Skizo !
|
|
|
|
« Last Edit: May 02, 2012, 06:03:18 am by Jean-François »
|
Logged
|
Un tien vaux mieux que deux tu l'auras !
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #18 on: May 02, 2012, 06:22:03 am » |
j ai fait un ptit essai avec quelque chose de cette structure la #include <Wire.h> #include <NXShield.h> #include <NXTTouch.h> #include <NXTLight.h> #include <SumoEyes.h> #include <ACCLNx.h> #include <NXTUS.h>
// // declare the NXShield(s) attached to your Arduino. // NXShield nxshield;
// // declare the i2c devices used on NXShield(s). //
// // declare analog devices attached to nxshields. // NXTTouch touch1;
Void main() {str= 100 serial.void(avancer)
}
Void Avancer() { // Drive both motors forward and backward for a specific number of // rotations delay(1000); sprintf(str, "Both Motors Forward %d Rotations", rotations); Serial.println(str); str[0] = '\0'; nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Forward, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold); delay(1000); sprintf(str, "Both Motors Reverse %d Rotations", rotations); Serial.println(str); str[0] = '\0'; nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Reverse, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold);
Serial.println("Bank B motors >>"); }
|
|
|
|
|
Logged
|
|
|
|
|
83 - var
Offline
Sr. Member
Karma: 0
Posts: 452
ARDUINO Powa !
|
 |
« Reply #19 on: May 02, 2012, 06:32:51 am » |
alors: #include <Wire.h> #include <NXShield.h> #include <NXTTouch.h> #include <NXTLight.h> #include <SumoEyes.h> #include <ACCLNx.h> #include <NXTUS.h>
// // declare the NXShield(s) attached to your Arduino. // NXShield nxshield;
// // declare analog devices attached to nxshields. // NXTTouch touch1;
Void main() { str= 100 avancer(str);// comme ça l'appel de fonction avec paramètre
}
Void Avancer(int str) { int str;
// Drive both motors forward and backward for a specific number of // rotations delay(1000); sprintf(str, "Both Motors Forward %d Rotations", rotations); Serial.println(str); str[0] = '\0';//bon reflex =) nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Forward, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold); delay(1000); sprintf(str, "Both Motors Reverse %d Rotations", rotations); Serial.println(str); str[0] = '\0'; nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Reverse, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold);
Serial.println("Bank B motors >>"); }
sinon c'est pas faut mais il faut un pointeur, ou un str défini en globale pour qu'il sois aussi présent dans ta fonction.. Voila. Skizo !
|
|
|
|
|
Logged
|
Un tien vaux mieux que deux tu l'auras !
|
|
|
|
Ile-de-France (92 sud), France
Offline
Edison Member
Karma: 22
Posts: 1817
|
 |
« Reply #20 on: May 02, 2012, 06:38:24 am » |
SuperBaloo J'ai l'impression que ta réflexion est relativement bien avancée. De mon point de vue, je prêche la religion des machines d'état. De ce que je vois de ta description tu as de quoi créer 2 ou 3 machines d'état qui vont gérer par exemple les moteurs, les décisions globales, ... Je te suggère de regarder ce sujet là : http://arduino.cc/forum/index.php/topic,102491.15.htmloù j'ai conseillé mat0013 sur la création d'un programme pour contrôler un train. Je lui ai fait un code que je pense être assez didactique (fichier demo_train2.ino ici). Tu devrais pouvoir t'en inspirer pour voir la méthode de travail. A+
|
|
|
|
|
Logged
|
Barbuduino: Arduino sur Breadboard & VinciDuino: Clone Leonardo // WR703: Mini-routeur hacké // LauchPad MSP430 et Stellaris // Panda II Arduino-like .NetMF sous VisualC# RTFC: Read That F.....g Code / RTFD: Read That F.....g Doc / RTFDS: Read That F.....g DataSheet / RTFS: Read That F.....g Schematic / Wot da ya wanna D.I.Y. today ?
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #21 on: May 02, 2012, 07:10:37 am » |
SuperBaloo J'ai l'impression que ta réflexion est relativement bien avancée. De mon point de vue, je prêche la religion des machines d'état. De ce que je vois de ta description tu as de quoi créer 2 ou 3 machines d'état qui vont gérer par exemple les moteurs, les décisions globales, ... Je te suggère de regarder ce sujet là : http://arduino.cc/forum/index.php/topic,102491.15.htmloù j'ai conseillé mat0013 sur la création d'un programme pour contrôler un train. Je lui ai fait un code que je pense être assez didactique (fichier demo_train2.ino ici). Tu devrais pouvoir t'en inspirer pour voir la méthode de travail. A+ J ai pas trop compris ton histoire de machine etat, peut tu m' expliquer plus en details. ce que j ai compris c est que chaque etat que tu me parle serait une fonction ex etat 1 = avancer etat 2 = reculer etat 3 = detecter
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #22 on: May 02, 2012, 07:21:34 am » |
#include <Wire.h> #include <NXShield.h> #include <NXTTouch.h> #include <NXTLight.h> #include <SumoEyes.h> #include <ACCLNx.h> #include <NXTUS.h>
// // declare the NXShield(s) attached to your Arduino. // NXShield nxshield;
// // declare analog devices attached to nxshields. // NXTTouch touch1;
Void main() { str= 100 avancer(str);// comme ça l'appel de fonction avec paramètre
}
Void Avancer(int str) { int str;
// Drive both motors forward and backward for a specific number of // rotations delay(1000); sprintf(str, "Both Motors Forward %d Rotations", rotations); Serial.println(str); str[0] = '\0';//bon reflex =) nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Forward, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold); delay(1000); sprintf(str, "Both Motors Reverse %d Rotations", rotations); Serial.println(str); str[0] = '\0'; nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Reverse, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold);
Serial.println("Bank B motors >>"); }
Petite question, je dois gerer l'évitement durant mon déplacement (en gros je m’arrête si y a quelqu'un devant), est il plus simple de mettre une condition si dans mon void.avancer() ou de créer un programme annexe
|
|
|
|
|
Logged
|
|
|
|
|
83 - var
Offline
Sr. Member
Karma: 0
Posts: 452
ARDUINO Powa !
|
 |
« Reply #23 on: May 02, 2012, 07:39:56 am » |
ça c'est à toi de voir si dans ta fonction il avance une seconde après il vois ce qui ce passe et continue a nouveau d'avance tu peut le mettre dans ta fonction mais bon pendant ces une seconde tout peut ce passé sans qu'il le vois :s et c'est histoire de machine d'état c'est une façon simple de procéder, comme tu dit sa donnerai sa: switche (x): { case 1: avancer break;
case 2: reculer break;
case 3: tourner break; }
et avec ça soit a chaque fin de case tu passe au suivant soit tu choisie l'action avant: switche (x): { case 1: avancer x=2; break;
case 2: reculer x=3; break;
case 3: tourner x=1; break; }
if(je veux tourner){x=3;} if(je veux avancer){x=1;} if(je veux reculer){x=2;}
switche (x): { case 1: avancer break;
case 2: reculer break;
case 3: tourner break; }
par exemple... Skizo !
|
|
|
|
|
Logged
|
Un tien vaux mieux que deux tu l'auras !
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #24 on: May 02, 2012, 08:12:58 am » |
Que pensez vous de celui ci avec intégration du timer et arret urgence #include <Wire.h> #include <NXShield.h> #include <NXTTouch.h> #include <NXTLight.h> #include <SumoEyes.h> #include <ACCLNx.h> #include <NXTUS.h>
// // declare the NXShield(s) attached to your Arduino. // NXShield nxshield;
// // declare analog devices attached to nxshields. // NXTTouch touch1;
Void main() { time=90000 timer(time); str= 100 avancer(str);// comme ça l'appel de fonction avec paramètre
}
Void timer(int time) {
int time; time1=milis(); if (time1>=(time)) // non bloquante ! {time=millis(); else Void arreturgence } }
Void arreturgence() { nxshield.bank_a.motorReset(); nxshield.bank_b.motorReset(); nxshield.bank_c.motorReset(); }
Void Avancer(int str) { int str;
// Drive both motors forward and backward for a specific number of // rotations delay(1000); sprintf(str, "Both Motors Forward %d Rotations", rotations); Serial.println(str); str[0] = '\0';//bon reflex =) nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Forward, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold); delay(1000); sprintf(str, "Both Motors Reverse %d Rotations", rotations); Serial.println(str); str[0] = '\0'; nxshield.bank_a.motorRunRotations(SH_Motor_Both, SH_Direction_Reverse, SH_Speed_Medium, rotations, SH_Completion_Wait_For, SH_Next_Action_BrakeHold);
Serial.println("Bank B motors >>"); }
|
|
|
|
« Last Edit: May 02, 2012, 08:14:46 am by SuPeRBaLoO »
|
Logged
|
|
|
|
|
83 - var
Offline
Sr. Member
Karma: 0
Posts: 452
ARDUINO Powa !
|
 |
« Reply #25 on: May 02, 2012, 08:38:41 am » |
... regarde change ça: Void timer(int time) { time1=milis();//bof comme téchnique, ca va marcher au début et plus apres... il te faut une reference... if (time1>=(time)) {time=millis(); else Void arreturgence // <================= encore une fois l'appel c'est : arreturgence(); et c'est tout :s } }
change comme ça ! Void timer(int time) {
time1=milis(); if (time1>=(time2+time)) { time2=millis(); return 1; //<=== signe que ta tempo est passée.. } else { return 0; }//<=== tempo pas fini
}
l'appel de l’arrêt d'urgence ce fait pas la, il ce fait après avoir testé ton capteur ou la variable qui est image de la présence de quelque chose.. tu a encore trop de chemin à faire avant d'avoir un problème compréhensible va sur le cite du zero un peut tu avancera plus vite.. Skizo !
|
|
|
|
|
Logged
|
Un tien vaux mieux que deux tu l'auras !
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 20
|
 |
« Reply #26 on: May 02, 2012, 08:50:08 am » |
tu a encore trop de chemin à faire avant d'avoir un problème compréhensible va sur le cite du zero un peut tu avancera plus vite..
Skizo !
Je comprend pas, il s'agit bien la du forum arduino, ou les gens s'entraide dans leur galère ??? Il y a des gens qui sont complétement hors sujet vis a vis d'arduino (ex info de capteur ou autre) et on les aide, je vois pas pourquoi on pourrais pas m'aider sur un projet de robot, avec un nxt shield que beaucoup de jeunes roboticiens pourraient utiliser.
|
|
|
|
|
Logged
|
|
|
|
|
83 - var
Offline
Sr. Member
Karma: 0
Posts: 452
ARDUINO Powa !
|
 |
« Reply #27 on: May 02, 2012, 09:00:29 am » |
le problème n'est pas la, ton projet est intéressent et le matos approprier au forum, mais ton code n'est pas du tout compilable et tu nous donne une version avec ton idée et nous faut qu'on en face un code qui fonctionne.. c'est pas trop comme ça que ça marche.. normalement tu apprend comment fonctionne tes fonction etc, tu fait ton programme petit bou par petit bou ou gros programme peut importe et la on répond a toute tes questions et on corrige ton code, mais la c'est même pas du C même les if(){ }else.. son pas respecté etc.. il va falloir que tu apprenne un peu avant je pense..
ps: on dirait que tu veut faire marcher un robot sans savoir programmer en C...
Skizo !
|
|
|
|
« Last Edit: May 02, 2012, 09:02:04 am by skizoh »
|
Logged
|
Un tien vaux mieux que deux tu l'auras !
|
|
|
|
|