• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Program Arduino, scinająca się płytka
#1
Witam,
mam problem z programem płytki Arduino.
Poniżej wrzucam mój program, ma on bibliotekę obsługującą żyroskop i radio.
Po dodaniu fragmentów odpowiedzialnych z działanie żyroskopu, płytka staję w miejscu przy linijce
Kod:
byte xMSB = readRegister(L3G4200D_Address, 0x29);
 byte xLSB = readRegister(L3G4200D_Address, 0x28);
x = ((xMSB << 8) | xLSB);

kosniks
Poziom 3
Offline 







Dołączył: 01 Kwi 2016
Posty: 14
Punkty: 9
  • Miasto: Radzymin
Raportuj [/url]

 [url=http://www.elektroda.pl/rtvforum/viewtopic.php?p=16137548#16137548]#1
19 Gru 2016 18:04
Witam,
mam problem z programem płytki Arduino.
Poniżej wrzucam mój program, ma on bibliotekę obsługującą żyroskop i radio.
Po dodaniu fragmentów odpowiedzialnych z działanie żyroskopu, płytka staję w miejscu przy linijce
Kod: c Rozwiń Zaznacz wszystko
Kod:
 byte xMSB = readRegister(L3G4200D_Address, 0x29);
  byte xLSB = readRegister(L3G4200D_Address, 0x28);
 x = ((xMSB << 8) | xLSB);




To cały program:
Kod:
#include <SoftwareSerial.h>
#include <Wire.h>

#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24

int L3G4200D_Address = 105; //I2C address of the L3G4200D
int dron;
int x;
int y;
int z;

SoftwareSerial mySerial(5, 6); // RX, TX
int synch=1;
boolean guzik = false;
boolean nowsynch = false;
boolean lastsynch = false;
int mapAY;
int AY;
int pwm=100;
int pwm1=100;
int pwm2=100;
int pwm3=100;
int pwm4=100;
int obrot = 0;
int msg;
int liczba;

int servo1=3;
int servo2=10;
int servo3=9;
int servo4=11;


void setup()
{

 Serial.begin(9600);  // Debugging only
Wire.begin();
 
 
 mySerial.begin(9600);
 
 Serial.println("starting up L3G4200D");
   

   
   setupL3G4200D(2000); // Configure L3G4200  - 250, 500 or 2000 deg/sec  
               
   delay(1500); //wait for the sensor to be ready

}

void loop()
{


   
 

 
     
       if(mySerial.available() > 1){    
   msg = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)    
  }
   getGyroValues();  // This will update x, y, and z with new values

 

if(msg==10){
 praca(1000,1000,1000,1000);}
 if(msg==11){
 praca(190,190,190,190);}
if(msg==12){
 praca(180,180,180,180);}
 if(msg==13){
 praca(175,175,175,175);}
if(msg==14){
 praca(170,170,170,170);}
if(msg==15){
 praca(165,165,165,165);}
if(msg==16){
 praca(160,160,160,160);}
if(msg==17){
 praca(155,155,155,155);}
if(msg==18){
 praca(150,150,150,150);}
if(msg==19){
 praca(147,147,147,147);}
if(msg==190){
 praca(145,145,145,145);}
if(msg==191){
 praca(140,140,140,140);}
if(msg==192){
 praca(135,135,135,135);}
if(msg==193){
 praca(110,110,110,110);}
if(msg==0){
 praca(100,100,100,100);}



if(msg==110){
 praca1(1000,1000,1000,1000);}
if(msg==111){
 praca1(185,190,190,190);}
if(msg==112){
 praca1(175,180,180,180);}
if(msg==113){
 praca1(165,170,170,170);}
if(msg==114){
 praca1(160,165,165,165);}
if(msg==115){
 praca1(145,150,150,150);}      
if(msg==116){
 praca1(140,145,145,145);}
if(msg==117){
 praca1(135,140,140,140);}
if(msg==118){
 praca1(130,135,135,135);}
if(msg==119){
 praca1(125,130,130,130);}
if(msg==40){
 praca1(120,125,125,125);}
if(msg==41){
 praca1(115,120,120,120);}
if(msg==42){
 praca1(110,115,115,115);}
if(msg==43){
 praca1(100,110,110,110);}



if(msg==120){
 praca1(1000,1000,1000,1000);}
if(msg==121){
 praca1(190,190,185,190);}
if(msg==122){
 praca1(180,180,175,180);}
if(msg==123){
 praca1(170,170,165,170);}
if(msg==124){
 praca1(160,160,155,160);}
if(msg==125){
 praca1(150,150,145,150);}      
if(msg==126){
 praca1(145,145,140,145);}
if(msg==127){
 praca1(140,140,135,140);}
if(msg==128){
 praca1(135,135,130,135);}
if(msg==129){
 praca1(130,130,125,130);}
if(msg==50){
 praca1(125,125,120,125);}
if(msg==51){
 praca1(120,120,115,120);}
if(msg==52){
 praca1(115,115,110,115);}
if(msg==53){
 praca1(110,110,100,110);}



if(msg==130){
 praca1(1000,1000,1000,1000);}
if(msg==131){
 praca1(190,185,190,190);}
if(msg==132){
 praca1(180,175,180,180);}
if(msg==133){
 praca1(170,165,170,170);}
if(msg==134){
 praca1(160,155,160,160);}
if(msg==135){
 praca1(150,145,150,150);}      
if(msg==136){
 praca1(145,140,145,145);}
if(msg==137){
 praca1(140,135,140,140);}
if(msg==138){
 praca1(135,130,135,135);}
if(msg==139){
 praca1(130,125,130,130);}
if(msg==60){
 praca1(125,120,125,125);}
if(msg==61){
 praca1(120,115,120,120);}
if(msg==62){
 praca1(115,110,115,115);}
if(msg==63){
 praca1(110,100,110,110);}



if(msg==140){
 praca1(1000,1000,1000,1000);}
if(msg==141){
 praca1(190,190,190,185);}
if(msg==142){
 praca1(180,180,180,175);}
if(msg==143){
 praca1(170,170,170,165);}
if(msg==144){
 praca1(160,160,160,155);}
if(msg==145){
 praca1(150,150,150,145);}      
if(msg==146){
 praca1(145,145,145,140);}
if(msg==147){
 praca1(140,140,140,135);}
if(msg==148){
 praca1(135,135,135,130);}
if(msg==149){
 praca1(130,130,130,125);}
if(msg==70){
 praca1(125,125,125,120);}
if(msg==71){
 praca1(120,120,120,115);}
if(msg==72){
 praca1(115,115,115,110);}
if(msg==73){
 praca1(110,110,110,100);}



 if(msg==150){
 praca1(1000,1000,1000,1000);}
if(msg==151){
 praca1(185,190,190,185);}
if(msg==152){
 praca1(175,180,180,175);}
if(msg==153){
 praca1(165,170,170,165);}
if(msg==154){
 praca1(155,160,160,155);}
if(msg==155){
 praca1(145,150,150,145);}      
if(msg==156){
 praca1(140,145,145,140);}
if(msg==157){
 praca1(135,140,140,135);}
if(msg==158){
 praca1(130,135,135,130);}
if(msg==159){
 praca1(125,130,130,125);}
if(msg==80){
 praca1(120,125,125,120);}
if(msg==81){
 praca1(115,120,120,115);}
if(msg==82){
 praca1(110,115,115,110);}
if(msg==83){
 praca1(100,110,110,100);}
     

if(msg==160){
 praca1(1000,1000,1000,1000);}
if(msg==161){
 praca1(185,185,190,190);}
if(msg==162){
 praca1(175,175,180,180);}
if(msg==163){
 praca1(165,165,170,170);}
if(msg==164){
 praca1(155,155,160,160);}
if(msg==165){
 praca1(145,145,150,150);}      
if(msg==166){
 praca1(140,140,145,145);}
if(msg==167){
 praca1(135,135,140,140);}
if(msg==168){
 praca1(130,130,135,135);}
if(msg==169){
 praca1(125,125,130,130);}
if(msg==90){
 praca1(120,120,125,125);}
if(msg==91){
 praca1(115,115,120,120);}
if(msg==92){
 praca1(110,110,115,115);}
if(msg==93){
 praca1(100,100,110,110);}  


if(msg==170){
 praca1(1000,1000,1000,1000);}
if(msg==171){
 praca1(190,190,185,185);}
if(msg==172){
 praca1(180,180,175,175);}
if(msg==173){
 praca1(170,170,165,165);}
if(msg==174){
 praca1(160,160,155,155);}
if(msg==175){
 praca1(150,150,145,145);}      
if(msg==176){
 praca1(145,145,140,140);}
if(msg==177){
 praca1(140,140,135,135);}
if(msg==178){
 praca1(135,135,130,130);}
if(msg==179){
 praca1(130,130,125,125);}
if(msg==94){
 praca1(125,125,120,120);}
if(msg==95){
 praca1(120,120,115,115);}
if(msg==96){
 praca1(115,115,110,110);}
if(msg==97){
 praca1(110,110,100,100);}



 if(msg==180){
 praca1(1000,1000,1000,1000);}
if(msg==181){
 praca1(190,185,185,190);}
if(msg==182){
 praca1(180,175,175,180);}
if(msg==183){
 praca1(170,165,165,170);}
if(msg==184){
 praca1(160,155,155,160);}
if(msg==185){
 praca1(150,145,145,150);}      
if(msg==186){
 praca1(145,140,140,145);}
if(msg==187){
 praca1(140,135,135,140);}
if(msg==188){
 praca1(135,130,130,135);}
if(msg==189){
 praca1(130,125,125,130);}
 if(msg==84){
 praca1(125,120,120,125);}
if(msg==85){
 praca1(120,115,115,120);}
if(msg==86){
 praca1(115,110,110,115);}
if(msg==87){
 praca1(110,100,100,110);}
 
 







Serial.println(msg);
mySerial.flush();//clear the serial buffer for unwanted inputs
delay(2);
Serial.println("100");
}

void zyroskop(){
{if(x>500&y<500&y>-200){
 dron=1;}
if(x<-200&y<500&y>-200){
 dron=2;}
if(y>500&x<500&x>-200){
 dron=3;}
if(y<-200&x<500&x>-200){
 dron=4;}
if(y>500&x<-200){
 dron=5;}
if(y<-200&x<-200){
 dron=6;}
if(y<-200&x>500){
 dron=7;}
if(y>500&x>500){
 dron=8;}
if(y<500&y>-200&x<500&x>-200){
 dron=0;}

if(dron=1&&pwm4>100){
 pwm4=pwm4-10;}
if(dron=2&&pwm2>100){
 pwm2=pwm2-10;}
 if(dron=3&&pwm1>100){
 pwm1=pwm1-10;}
 if(dron=4&&pwm3>100){
 pwm3=pwm3-10;}
 
if(dron=5&&pwm2>100&pwm1>100){
 pwm2=pwm2-10;
 pwm1=pwm1-10;}
 if(dron=6&&pwm2>100&pwm3>100){
 pwm2=pwm2-10;
 pwm3=pwm3-10;}
 if(dron=7&&pwm3>100&pwm4>100){
 pwm3=pwm3-10;
 pwm4=pwm4-10;}
 if(dron=8&&pwm4>100&pwm1>100){
 pwm4=pwm4-10;
 pwm1=pwm1-10;}
}}
int praca(int pwm1,int pwm2,int pwm3, int pwm4)
{zyroskop();
 analogWrite(servo1,pwm1);
analogWrite(servo2,pwm2);
analogWrite(servo3,pwm3);
analogWrite(servo4,pwm4);
}
int praca1(int pwm1, int pwm2, int pwm3, int pwm4)
{zyroskop();
 analogWrite(servo1,pwm1);
analogWrite(servo2,pwm2);
analogWrite(servo3,pwm3);
analogWrite(servo4,pwm4);
}
void getGyroValues(){

 byte xMSB = readRegister(L3G4200D_Address, 0x29);
 byte xLSB = readRegister(L3G4200D_Address, 0x28);
x = ((xMSB << 8) | xLSB);

 byte yMSB = readRegister(L3G4200D_Address, 0x2B);
 byte yLSB = readRegister(L3G4200D_Address, 0x2A);
 y = ((yMSB << 8) | yLSB);

 byte zMSB = readRegister(L3G4200D_Address, 0x2D);
 byte zLSB = readRegister(L3G4200D_Address, 0x2C);
 z = ((zMSB << 8) | zLSB);
 
}

int setupL3G4200D(int scale){
 //From  Jim Lindblom of Sparkfun's code

 // Enable x, y, z and turn off power down:
 writeRegister(L3G4200D_Address, CTRL_REG1, 0b00001111);

 // If you'd like to adjust/use the HPF, you can edit the line below to configure CTRL_REG2:
 writeRegister(L3G4200D_Address, CTRL_REG2, 0b00000000);

 // Configure CTRL_REG3 to generate data ready interrupt on INT2
 // No interrupts used on INT1, if you'd like to configure INT1
 // or INT2 otherwise, consult the datasheet:
 writeRegister(L3G4200D_Address, CTRL_REG3, 0b00001000);

 // CTRL_REG4 controls the full-scale range, among other things:

 if(scale == 250){
   writeRegister(L3G4200D_Address, CTRL_REG4, 0b00000000);
 }else if(scale == 500){
   writeRegister(L3G4200D_Address, CTRL_REG4, 0b00010000);
 }else{
   writeRegister(L3G4200D_Address, CTRL_REG4, 0b00110000);
 }

 // CTRL_REG5 controls high-pass filtering of outputs, use it
 // if you'd like:
 writeRegister(L3G4200D_Address, CTRL_REG5, 0b00000000);
}

void writeRegister(int deviceAddress, byte address, byte val) {
   Wire.beginTransmission(deviceAddress); // start transmission to device
   Wire.write(address);       // send register address
   Wire.write(val);         // send value to write
   Wire.endTransmission();     // end transmission
}

int readRegister(int deviceAddress, byte address){

   int v;
   Wire.beginTransmission(deviceAddress);
   Wire.write(address); // register to read
   Wire.endTransmission();

   Wire.requestFrom(deviceAddress, 1); // read a byte

   while(!Wire.available()) {
       // waiting
   }

   v = Wire.read();
   return v;
}

Oddzielnie radio jak i żyroskop wraz ze swoimi programami działają bez problemu a razem poprostu w powyższym momencie program się zawiesza.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości