Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« on: March 25, 2009, 01:33:48 pm » |
mes premiers avec une Arduino. un moteur pas à pas pour la direction, un moteur DC pour la traction, trois roulettes de trotinettes, un peu de bricolage et voilà.... ça amuse bien ma fille.
|
|
|
|
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #1 on: March 28, 2009, 03:10:09 pm » |
Je viens d'installer des fins de course pour mettre la roue directrice en position milieu. La routine pour cette opération est appelée dans le setup(). La roue directrice se remet a zéro à chaque reset ou mise en tension.
|
|
|
|
« Last Edit: March 28, 2009, 03:11:22 pm by jfs »
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
Massongex, Suisse
Offline
Full Member
Karma: 2
Posts: 169
Arduino rocks
|
 |
« Reply #2 on: April 08, 2009, 03:41:53 pm » |
Chapeau, c'est super. Qu'as-tu utilisé comme contrôleur de moteur ?
churchill
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #3 on: April 08, 2009, 03:54:43 pm » |
Le moteur de traction est un moteur DC d'une imprimante, pour le "controler" j'utilise un "motor control shield".
Pour la direction c'est un moteur 48 pas unipolaire (5 fils) d'une imprimante également, pour le contrôler j'utilise un ULN2003 et 4 TIP120.
|
|
|
|
« Last Edit: April 08, 2009, 03:55:23 pm by jfs »
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 6
Arduino rocks
|
 |
« Reply #4 on: April 22, 2009, 12:13:50 pm » |
bonsoir à tous nouveau sur le site, je trouve vraiment sympa le travail de jean- françois.. je cherche dans la même direction..  la question est : pensez vous qu'avez un "Y" de type magic box je peux pas poster le lien..  (suffit de chercher magic box servo ) on puisse commander plus de deux servos en même temps..? ps: jean françois j'ai essayé d'envoyer MP mais ça ne marche pas.. ravi d'être parmi vous  bonne soirée ludo85
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 6
Arduino rocks
|
 |
« Reply #5 on: April 23, 2009, 05:20:28 am » |
bonjour voici le lien de la magic box servo (quadruple commande) dont je parlé hier.. http://www.gotronic.fr/catalog/robotique/robframe.php?page_cible=servo.htmqu'en pensez vous..? je cherche autour de multiple commande servo à ce que je sache d'un motor shield on ne peut gérer que 2 servos en simultanés.. comment faire..? en vous souhaitant une bonne journée ludo85 
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #6 on: March 03, 2010, 05:41:04 pm » |
Je m'aperçois que je n'avais jamais mis le code que j'avais utilisé. J'avais fait une fonction pour mettre le moteur PAP en position milieu à chaque démarrage de la carte, avec deux switchs à chaque fin de course. Pour le moteur DC un motorshield. #include <Wire.h> #include <string.h> #include <stdio.h>
uint8_t outbuf[6];
int cnt = 0; int ledPin = 13;
int dirbpin = 12; // Direction pinpour le moteur DC Digital 12 int speedbpin = 9; // vitesse pin for motor DC Digital 9 (PWM) (motorshield) int pinA = 8; // Moteur PAP int pinB = 7; // Moteur PAP int servoPin3 = 6; int servoPin2 = 5; int servoPin = 3;
int pin_stop = 4; // Stepper motor interrupteur de zerotage int stepper_count = 0; int stepper_return=0;
int encoderpin = 2; // lecture de la roue codeuse moteur DC Digital 2 // moteur PAP int etatPinA[8] = {0, 1, 1, 0}; //Séquence moteur PAP int etatPinB[8] = {1, 1, 0, 0}; //Séquence moteur PAP int pas_suivant = 1; int Old_time=0; int pos_stepper = 0; int delai_entre_pas = 0 ; // 8000 microseconds mini pour le démarrage. int pos_joy = 0; volatile int state = 0; //fin moteur PAP
int speed = 0;
float encoderpos = 0; int dir = 0; int dir_pap = 0;
int pulseWidth = 500; int pulseWidth2 = 1500; int pulseWidth3 = 500;
long lastPulse = 0; long lastPulse2 = 0; long lastPulse3 = 0;
int z_button = 0; int c_button = 0;
int refreshTime = 0;
int minPulse = 1400; int minPulse2 = 100; int minPulse3 = 100;
int dtime=10;
#define pwbuffsize 10 long pwbuff[pwbuffsize]; long pwbuffpos = 0; long pwbuff2[pwbuffsize]; long pwbuffpos2 = 0; long pwbuff3[pwbuffsize]; long pwbuffpos3 = 0;
void setup() { pinMode(dirbpin, OUTPUT);
beginSerial (38400); Wire.begin (); nunchuck_setpowerpins(); // use analog pins 2&3 as fake gnd & pwr nunchuck_init (); pinMode(servoPin, OUTPUT); pinMode(servoPin2, OUTPUT); pinMode(servoPin3, OUTPUT); pinMode (encoderpin,INPUT); pinMode(pinA, OUTPUT); // Moteur PAP pinMode(pinB, OUTPUT); // Moteur PAP pulseWidth = minPulse; pulseWidth2 = minPulse2; pulseWidth3 = minPulse3; // Serial.print ("Finished setup\n"); pinMode(pin_stop, INPUT); digitalWrite(pin_stop, LOW); mise_a_zero();
}
void nunchuck_init() { Wire.beginTransmission (0x52); Wire.send (0x40); Wire.send (0x00); Wire.endTransmission (); }
void send_zero() { Wire.beginTransmission (0x52); Wire.send (0x00); Wire.endTransmission (); }
int t = 0;
void loop() { t++; long last = millis();
if( t == 1) {
t = 0;
Wire.requestFrom (0x52, 6);
while (Wire.available ()) { outbuf[cnt] = nunchuk_decode_byte (Wire.receive ()); digitalWrite (ledPin, HIGH); cnt++; }
if (cnt >= 5) {
// printNunchuckData();
int z_button = 0; int c_button = 0;
if ((outbuf[5] >> 0) & 1) z_button = 1; if ((outbuf[5] >> 1) & 1) c_button = 1;
switch (c_button) { case 1: switch (z_button) { case 0: break; case 1: muovi(); motorDC(); Motor_PAP(); break; } break; case 0: switch (z_button) { case 0: delay(10000); break; case 1: delay(3000); break; } break; } }
cnt = 0; send_zero();
} // if(t==)
updateServo();
delay(dtime); }
void updateServo() {
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); delayMicroseconds(pulseWidth); digitalWrite(servoPin, LOW);
digitalWrite(servoPin2, HIGH); delayMicroseconds(pulseWidth2); digitalWrite(servoPin2, LOW); digitalWrite(servoPin3, HIGH); delayMicroseconds(pulseWidth3); digitalWrite(servoPin3, LOW);
lastPulse = millis(); } }
int i=0; void printNunchuckData() { int joy_x_axis = outbuf[0]; int joy_y_axis = outbuf[1]; int accel_x_axis = outbuf[2]; // * 2 * 2; int accel_y_axis = outbuf[3]; // * 2 * 2; int accel_z_axis = outbuf[4]; // * 2 * 2;
int z_button = 0; int c_button = 0;
if ((outbuf[5] >> 0) & 1) z_button = 1; if ((outbuf[5] >> 1) & 1) c_button = 1; if ((outbuf[5] >> 2) & 1) accel_x_axis += 2; if ((outbuf[5] >> 3) & 1) accel_x_axis += 1;
if ((outbuf[5] >> 4) & 1) accel_y_axis += 2; if ((outbuf[5] >> 5) & 1) accel_y_axis += 1;
if ((outbuf[5] >> 6) & 1) accel_z_axis += 2; if ((outbuf[5] >> 7) & 1) accel_z_axis += 1;
/* Serial.print (i,DEC); Serial.print ("\t");
Serial.print ("X: "); Serial.print (joy_x_axis, DEC); Serial.print ("\t");
Serial.print ("Y: "); Serial.print (joy_y_axis, DEC); Serial.print ("\t");
Serial.print ("AccX: "); Serial.print (accel_x_axis, DEC); Serial.print ("\t");
Serial.print ("AccY: "); Serial.print (accel_y_axis, DEC); Serial.print ("\t");
Serial.print ("AccZ: "); Serial.print (accel_z_axis, DEC); Serial.print ("\t");
Serial.print (z_button, DEC); Serial.print (" "); Serial.print (c_button, DEC); Serial.print ("\r\n"); */ int val[5]; Serial.print ("A"); val[0]=joy_x_axis*4; Serial.print( val[0] ); Serial.print( "B" ); val[1]=joy_y_axis*4; Serial.print( val[1] ); Serial.print( "C" ); val[2]=z_button; Serial.print( val[2] ); Serial.print( "D" ); val[3]=accel_x_axis*4; Serial.print( val[3] ); Serial.print( "E" ); val[4]=accel_y_axis*4; Serial.print( val[4] ); Serial.print( "F" ); val[5]=accel_z_axis*4; Serial.print( val[5] ); i++; }
char nunchuk_decode_byte (char x) { x = (x ^ 0x17) + 0x17; return x; }
void muovi (){ float tilt = (700 - outbuf[3]*2*2); float tilt2 = outbuf[2]*2*2; float tilt3 = outbuf[4]*2*2;
tilt = (tilt); pulseWidth = (tilt * 5) + minPulse;
tilt2 = (tilt2-288); pulseWidth2 = (tilt2 * 5) + minPulse2; tilt3 = (tilt3-288); pulseWidth3 = (tilt3 * 5) + minPulse3;
pwbuff[pwbuffpos] = pulseWidth; pwbuff2[pwbuffpos2] = pulseWidth2; pwbuff3[pwbuffpos3] = pulseWidth3; if( ++pwbuffpos == pwbuffsize ) pwbuffpos = 0; if( ++pwbuffpos2 == pwbuffsize ) pwbuffpos2 = 0; if( ++pwbuffpos3 == pwbuffsize ) pwbuffpos3 = 0;
pulseWidth=0; pulseWidth2=0; pulseWidth3=0;
for( int p=0; p<pwbuffsize; p++ ){ pulseWidth += pwbuff[p]; pulseWidth2 += pwbuff2[p]; pulseWidth3 += pwbuff3[p]; }
pulseWidth /= pwbuffsize; pulseWidth2 /= pwbuffsize; pulseWidth3 /= pwbuffsize;
}
void motorDC() { if (outbuf[1]>=144) { dir = 1 ; speed = (outbuf[1]*2*2-508)/2; if (digitalRead(encoderpin) == LOW) { //incremente la position encoderpos++; } } else if (outbuf[1]<=135) { dir = 0 ; speed = (510-outbuf[1]*2*2)/2; if (digitalRead(encoderpin) ==LOW ) { //decremente la position encoderpos--; } } else {speed = 0 ; } //else { speed = 0; } if (speed >=255){speed = 254 ;} if (speed <=0){speed = 0 ;} digitalWrite(dirbpin, dir); // set direction analogWrite(speedbpin, speed); // set speed (PWM) //dir = ((dir == 0) ? 1 : 0); // change direction //delay(10000); // 10 seconds /* Serial.print (outbuf[0], DEC); Serial.print (" "); Serial.println (speed, DEC);*/ Serial.println (encoderpos,DEC); }
// Uses port C (analog in) pins as power & ground for Nunchuck static void nunchuck_setpowerpins() { #define pwrpin PC3 #define gndpin PC2 DDRC |= _BV(pwrpin) | _BV(gndpin); PORTC &=~ _BV(gndpin); PORTC |= _BV(pwrpin); delay(100); // wait for things to stabilize }
A suivre ....
|
|
|
|
« Last Edit: March 03, 2010, 05:41:32 pm by jfs »
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #7 on: March 03, 2010, 05:42:44 pm » |
...La suite
void Motor_PAP(){ if (outbuf[0]>=125) { dir_pap = 1 ; pos_joy = (outbuf[0]-125)*79/125; } else if (outbuf[0]<=100) { dir_pap = 2 ; pos_joy = (outbuf[0]-100)*79/83; } else {pos_joy = 0 ;dir_pap=0; } if (pos_stepper!= pos_joy){ delai_entre_pas= micros()-Old_time; if (delai_entre_pas >= 8000){ //delayMicroseconds(8000); Old_time=micros(); digitalWrite(pinA, etatPinA[pas_suivant]); digitalWrite(pinB, etatPinB[pas_suivant]); switch (dir_pap){ case 0: if (pos_stepper<=0){ pas_suivant++; pos_stepper++; if(pas_suivant >=4){ pas_suivant=0; }} else if (pos_stepper>=0){ pas_suivant--; pos_stepper--; if(pas_suivant <0){ pas_suivant=3; }} etatPinA,state; etatPinB,!state; state=!state; break; case 1: if (pos_stepper<pos_joy){ pas_suivant++; pos_stepper++; if(pas_suivant >=4){ pas_suivant=0; }} break; case 2: if (pos_stepper>pos_joy){ pas_suivant--; pos_stepper--; if(pas_suivant <0){ pas_suivant=3; }} break;
} } } Serial.print (pos_stepper); Serial.print (" "); Serial.print (outbuf[0],DEC); Serial.print (" "); Serial.println (pos_joy); }
void mise_a_zero(){ delay (200); ////////////////////////////////touche a gauche while (digitalRead(pin_stop)==HIGH){ delai_entre_pas= micros()-Old_time; if (delai_entre_pas >= 10000){ //delayMicroseconds(8000); Old_time=micros(); digitalWrite(pinA, etatPinA[pas_suivant]); digitalWrite(pinB, etatPinB[pas_suivant]); pas_suivant--; if(pas_suivant <0){pas_suivant=3;} } } while (stepper_return<=15){ delai_entre_pas= micros()-Old_time; if (delai_entre_pas >= 10000){ //delayMicroseconds(8000); Old_time=micros(); digitalWrite(pinA, etatPinA[pas_suivant]); digitalWrite(pinB, etatPinB[pas_suivant]); pas_suivant++; stepper_return++; if(pas_suivant >=4){pas_suivant=0;} }} stepper_return=0; /////////////////////// fin de touche a gauche ///// touche a droite while (digitalRead(pin_stop)==HIGH){ delai_entre_pas= micros()-Old_time; if (delai_entre_pas >= 10000){ //delayMicroseconds(8000); Old_time=micros(); digitalWrite(pinA, etatPinA[pas_suivant]); digitalWrite(pinB, etatPinB[pas_suivant]); pas_suivant++; stepper_count++; if(pas_suivant >=4){pas_suivant=0;} }} ///// fin de touche a droite
/// positionnement a zero stepper_count= stepper_count/2; pos_stepper=stepper_count; while (stepper_count>=-4){ delai_entre_pas= micros()-Old_time; if (delai_entre_pas >= 10000){ //delayMicroseconds(8000); Old_time=micros(); digitalWrite(pinA, etatPinA[pas_suivant]); digitalWrite(pinB, etatPinB[pas_suivant]); pas_suivant--; stepper_count--; pos_stepper--; if(pas_suivant <0){pas_suivant=3;} } } /// fin de positionnement a zero
}
|
|
|
|
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
Massongex, Suisse
Offline
Full Member
Karma: 2
Posts: 169
Arduino rocks
|
 |
« Reply #8 on: March 09, 2010, 04:54:47 pm » |
Merci, je pense que ça va servir !
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #9 on: March 10, 2010, 01:52:31 am » |
Une petite précision encore, comme je n'utilise que le joystick du nunchuck, il y a toute une partie du code qui ne sert à rien. J'ai laissé le code dans son intégralité car je prévois d'utiliser l'accéléromètre et je compte remplacer mon moteur DC par un bruschless.
|
|
|
|
« Last Edit: March 10, 2010, 01:53:30 am by jfs »
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
Genève
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #10 on: March 17, 2010, 04:34:08 am » |
Bonjour Jean-François Je débute avec arduino et comme tu peu imaginer j'ai quelques problemes. Je tombe sur ton montage et c'est exactement ce que je soihaite pouvoir faire. 1er problème la mise à jour des biblihotèques. Peutu me guider? Merci
Pepi Genève
|
|
|
|
|
Logged
|
|
|
|
|
Geneva
Online
Faraday Member
Karma: 22
Posts: 2879
Yoplait... le pt'it suisse
|
 |
« Reply #11 on: March 17, 2010, 05:06:23 am » |
Normalement elle sont à jour dans le pack Arduino que tu installes :-?
Je comprends peut-être mal ta question ?
|
|
|
|
|
Logged
|
MacBook intel core 2 duo os X snow Leopard 10.6 eMac PPc G4 os X Leopard 10.5 powerbook G4 os X Leopard 10.5 imac PPC G3 os X Panther 10.3.9 Arduino Diecimila Arduino Mega Arduino Standalone Arduino 1307.04 
|
|
|
|
|