Z out of chaine range
CptPingouin
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour a tous je suis en terminal et cette année j'ai un projet coeff 16 au bac seul problème on est en galère on rame donc est ce que quelqu'un pourrait m'aider communiquer par mail pour un suivi svp:
Le probleme qui se pose aujourd'hui est que la valeur z de mon gyromètre est dit : out of range en gros j'ai ce programme python
import serial
ser = serial.Serial("COM5",timeout=1) #Le port utilisé est ici COM4
print(ser)
while 1:
chaine= ser.read(12)
chaine= str(chaine)
chaine= chaine.replace("'",";")
chaine= chaine.split(";")
print (chaine)
x = chaine[1]
y = chaine[2]
z = chaine[3]
print (x , y , z )
qui me récupère les données du gyromètre connecté a une carte arduino mais le problème semble être qu'il ne récupère pas les valeurs directement donc le temps que le gyromètre s'initialise la valeur z semble inexistante dans le programme arduino
#include <Wire.h>
#include "ITG3200.h"
ITG3200 gyro;
void setup()
{
Serial.begin(9600);
gyro.init();
gyro.zeroCalibrate(200,10);//sample 200 times to calibrate and it will take 200*10ms
}
void loop()
{
int x, y ,z;
gyro.getXYZ(&x,&y,&z);
Serial.print(" ; ");
Serial.print (0 + x);
Serial.print(" ; ");
Serial.print(0 + y);
Serial.print(" ; ");
Serial.print(0 + z);
Serial.print(" ; ");
delay(100);
}
j'ai rajouter le 0 + variable pour commencer avec une variable mais rien n'y fait ça commence sans valeur je ne sais pas comment faire quelqu'un pourrait m'aider svp
*EDIT* en changeant le timeout de 1 a 0.1 j'ai pu obtenir quelque valeur mais plante au bout d'un moment
Serial<id=0x2baf950, open=True>(port='COM5', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=0.1, xonxoff=False, rtscts=False, dsrdtr=False)
['b', '099 ', ' -409 ', '', '']
099 -409
['b', ' ', ' 485 ', ' -9', '']
485 -9
['b', '75 ', ' -617 ', ' ', '']
75 -617
['b', '', ' -10 ', ' -9 ', '', '']
-10 -9
['b', ' ', ' 811 ', ' -5', '']
811 -5
['b', '84 ', ' 29 ', ' ', '', '']
84 29
['b', ' 177 ', ' 943 ', '', '']
177 943
['b', ' -1567 ', ' ', ' ', '']
-1567
['b', '1773 ', ' 302 ', '', '']
1773 302
['b', ' -242 ', ' ', ' 1', '']
-242 1
['b', '120 ', ' -1099 ', '']
120 -1099
['b', '', ' -409 ', ' ', ' ', '']
-409
['b', '485 ', ' -975 ', '', '']
485 -975
['b', ' -617 ', ' ', '']
-617
['b', '', '']
Traceback (most recent call last):
File "U:\Python_arduino\pyton arduino essai.py", line 12, in <module>
z = chaine[3]
IndexError: list index out of range
>>>
Le probleme qui se pose aujourd'hui est que la valeur z de mon gyromètre est dit : out of range en gros j'ai ce programme python
import serial
ser = serial.Serial("COM5",timeout=1) #Le port utilisé est ici COM4
print(ser)
while 1:
chaine= ser.read(12)
chaine= str(chaine)
chaine= chaine.replace("'",";")
chaine= chaine.split(";")
print (chaine)
x = chaine[1]
y = chaine[2]
z = chaine[3]
print (x , y , z )
qui me récupère les données du gyromètre connecté a une carte arduino mais le problème semble être qu'il ne récupère pas les valeurs directement donc le temps que le gyromètre s'initialise la valeur z semble inexistante dans le programme arduino
#include <Wire.h>
#include "ITG3200.h"
ITG3200 gyro;
void setup()
{
Serial.begin(9600);
gyro.init();
gyro.zeroCalibrate(200,10);//sample 200 times to calibrate and it will take 200*10ms
}
void loop()
{
int x, y ,z;
gyro.getXYZ(&x,&y,&z);
Serial.print(" ; ");
Serial.print (0 + x);
Serial.print(" ; ");
Serial.print(0 + y);
Serial.print(" ; ");
Serial.print(0 + z);
Serial.print(" ; ");
delay(100);
}
j'ai rajouter le 0 + variable pour commencer avec une variable mais rien n'y fait ça commence sans valeur je ne sais pas comment faire quelqu'un pourrait m'aider svp
*EDIT* en changeant le timeout de 1 a 0.1 j'ai pu obtenir quelque valeur mais plante au bout d'un moment
Serial<id=0x2baf950, open=True>(port='COM5', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=0.1, xonxoff=False, rtscts=False, dsrdtr=False)
['b', '099 ', ' -409 ', '', '']
099 -409
['b', ' ', ' 485 ', ' -9', '']
485 -9
['b', '75 ', ' -617 ', ' ', '']
75 -617
['b', '', ' -10 ', ' -9 ', '', '']
-10 -9
['b', ' ', ' 811 ', ' -5', '']
811 -5
['b', '84 ', ' 29 ', ' ', '', '']
84 29
['b', ' 177 ', ' 943 ', '', '']
177 943
['b', ' -1567 ', ' ', ' ', '']
-1567
['b', '1773 ', ' 302 ', '', '']
1773 302
['b', ' -242 ', ' ', ' 1', '']
-242 1
['b', '120 ', ' -1099 ', '']
120 -1099
['b', '', ' -409 ', ' ', ' ', '']
-409
['b', '485 ', ' -975 ', '', '']
485 -975
['b', ' -617 ', ' ', '']
-617
['b', '', '']
Traceback (most recent call last):
File "U:\Python_arduino\pyton arduino essai.py", line 12, in <module>
z = chaine[3]
IndexError: list index out of range
>>>