Show Posts
|
|
Pages: [1]
|
|
2
|
International / Portugues / Re: Biblioteca PID bugada?
|
on: October 03, 2012, 07:40:45 pm
|
#include <PID_v1.h>
#define echoPin 22 #define trigPin 24
double Setpoint, Input, Output, min=0, max=255; int led=7; long distancia,dist;
PID myPID(&Input, &Output, &Setpoint,1,2,3, DIRECT);
void setup() { Serial.begin(9600); pinMode(echoPin, INPUT); pinMode(trigPin, OUTPUT); Input = dist; Setpoint = 15;
//turn the PID on myPID.SetMode(AUTOMATIC); myPID.SetOutputLimits(min, max); }
void loop() { //sonar digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin,HIGH); distancia = duration /29 / 2 ; if( distancia >0 && distancia <=100) { dist=distancia; }
Input = dist; myPID.Compute(); digitalWrite(led, Output);
Serial.print(Input); Serial.print(Setpoint); Serial.println(Output); delay(250); }
ae galera esse é o codigo so que ele não sai uma onda quadrada igual as do pwm obs: estou utilizando o mega então a saida 7 é PWM.
|
|
|
|
|
3
|
International / Portugues / Biblioteca PID bugada?
|
on: September 26, 2012, 08:54:40 pm
|
ae galera estou utilizando a biblioteca pid, verifiquei o proprio exemplo da bilioteca e da erro, tudo indica que não inclui a bilbioteca, os erros são os seguintes: PID_Basic.pde:-1: error: 'PID' does not name a type PID_Basic.cpp: In function 'void setup()': PID_Basic.pde:-1: error: 'myPID' was not declared in this scope PID_Basic.pde:-1: error: 'AUTOMATIC' was not declared in this scope PID_Basic.cpp: In function 'void loop()': PID_Basic.pde:-1: error: 'myPID' was not declared in this scope Alguem já passou por isso? estou utilizando a versão 1.0.1 e essa bilbioteca. http://www.arduino.cc/playground/Code/PIDLibraryalguem pode me dar um help?? 
|
|
|
|
|
4
|
International / Portugues / Ajuda com geração de sinal PWM
|
on: September 11, 2012, 02:00:01 pm
|
|
Estou usando a biblioteca servo.h para gerar um pulso minimo e uma máximo para uma saída pwm do Arduíno, pelo que me parece essa biblioteca é meio bugada, alguém conhece uma biblioteca melhor ou uma função na qual eu consigo gerar pulsos (mínimos e máximos) para uma saída pwm?
OBS: Preciso gerar um sinal aonde eu controlo o mim e o max em milissegundos.
|
|
|
|
|
6
|
International / Portugues / Giroscópio SD740 comunicação SPI não funciona
|
on: August 28, 2012, 07:13:44 pm
|
Estou precisando comunicar através de SPI esse sensor giroscópio SD740 com o arduino, através do código do fabricante ele da um erro de leitura, já verifiquei as pinagens e o código não entendi muito alguém poderia me ajudar? Link sensor: http://www.dfrobot.com/index.php?route=product/product&path=36_59&product_id=517#.UD1bQMGPXfILink programação e ligação: http://www.dfrobot.com/wiki/index.php?title=Tri-Axis_Gyro_Breakout-SD740_(SKU:_SEN0095) esse código não apresenta nenhum erro quando verificado, já o código do I2C apresenta vários erros. alguem poderia me dar um HELP.... =x /* Gyroscope SD740 SPI connection Version 1.0 Lauren <Lauran.pan@gmail.com> Pin connection to the Arduino board: CSN -> digital pin 10(D10) MOSI/SDA -> digital pin 11(D11) MISO/ADDR -> digital pin 12(D12) SCL -> digital pin 13(D13) Operating Supply Voltage V 2.6 - 5% - 3.3 + 5% Full Scale Range (digital output) °/s 1024 Sensitivity Accuracy % ± 5 Sensitivity Error Over Temperature % ± 5 Signal Update Rate KHz 10 SPI Communication Speed MHz 40 Full scale range is factory defined. Please contact SensorDynamics for setting different ranges. Maximum full scale factor is 4096°/s Bandwidth is factory defined. Please contact SensorDynamics for setting different ranges. Maximum bandwidth is 150Hz */
#include <SPI.h>
#define DataRegister 0x00 #define CS_Pin 10 //chip selection pin
char receiveData[128]; //data array int x,y,z; float xg,yg,zg; float absHeading = 0; // calculate the absolute heading unsigned long iTime = 0;
void setup(){
Serial.begin(57600);
SPI.begin(); SPI.setDataMode(SPI_MODE0);
pinMode(CS_Pin, OUTPUT);// init the chip selection pin digitalWrite(CS_Pin, HIGH);
checkGyroStatus(); }
void checkGyroStatus(){
readRegister(20,1,receiveData); Serial.print("check lock state:\t"); Serial.println(receiveData[0],BIN);//bin; 110 means works well if(bitRead(receiveData[0],1) == 0 || bitRead(receiveData[0],2) == 0){ Serial.println("Chip start error! You could reset the arduino board"); while(1){ } }
readRegister(70,1,receiveData); Serial.print("check standby bit:\t"); Serial.println(receiveData[0],BIN);//check bit0 0->normal 1->standby }
void loop(){ readRegister(DataRegister, 6, receiveData);
x = ((int)receiveData[0]<<8)|(int)receiveData[1]; y = ((int)receiveData[2]<<8)|(int)receiveData[3]; z = ((int)receiveData[4]<<8)|(int)receiveData[5];
float scale = 0.03125;// scale: 1024 / 2^15
xg = x * scale; yg = y * scale; zg = z * scale; float pastTime = float(micros() - iTime) / float(1000000); absHeading += zg * pastTime; iTime = micros();
/* Serial.print(x, DEC); Serial.print(','); Serial.print(y, DEC); Serial.print(','); Serial.println(z, DEC); Serial.print((float)xg,2); Serial.print("\t"); Serial.print((float)yg,2); Serial.print("\t"); Serial.print((float)zg,2); Serial.println(" °/s"); */ Serial.print("Heading:"); Serial.println(absHeading);//Axis Z absolute heading
delay(10);
}
void writeRegister(char registerAddress, char value){
digitalWrite(CS_Pin, LOW); SPI.transfer(registerAddress); SPI.transfer(value); digitalWrite(CS_Pin, HIGH);
}
void readRegister(char registerAddress, int numBytes, char * values){
char address = 0x80 | registerAddress; digitalWrite(CS_Pin, LOW); SPI.transfer(address); for(int i=0; i<numBytes; i++){ values[i] = SPI.transfer(0x00); } digitalWrite(CS_Pin, HIGH);
}
|
|
|
|
|
7
|
International / Portugues / Re: Controlando ESC com arduino ** problema**
|
on: August 20, 2012, 09:38:21 am
|
verifiquei novamente a programação, acertei os pontos que faltava, enfim agora com a ajuda de um controle remoto está tudo ok, oque não está funcionando é o seguinte: Cada ESC liga em uma valor da pwm e eu não estou conseguindo resolver isso.  #include <IRremote.h>
int motorPin = 7; int motor2Pin = 6; int motor3Pin = 5; int motor4Pin = 9; int RECV_PIN = A8; unsigned long int vlRec = 0; float gx=0; float gy=0; float gz=0; float ax=0; float ay=0; float az=0; float erroax=0; float erroay=0; float erroaz=0; float errogx=0; float errogy=0; float errogz=0;
IRrecv irrecv(RECV_PIN); decode_results results;
#define VELMIM 135 #define VELDIR 255
int VELMEDIA = 145;
void setup() { Serial.begin(9600); irrecv.enableIRIn();
pinMode(motorPin , OUTPUT); pinMode(motor4Pin , OUTPUT); pinMode(motor2Pin , OUTPUT); pinMode(motor3Pin , OUTPUT); arm(); }
void arm() { analogWrite(motorPin, VELMIM ); analogWrite(motor4Pin, VELMIM ); analogWrite(motor2Pin, VELMIM ); analogWrite(motor3Pin, VELMIM ); }
void liga() { analogWrite(motorPin, VELMEDIA ); analogWrite(motor3Pin, VELMEDIA ); analogWrite(motor4Pin, VELMEDIA ); analogWrite(motor2Pin, VELMEDIA ); }
void desliga() { analogWrite(motorPin, VELMIM ); analogWrite(motor4Pin, VELMIM ); analogWrite(motor2Pin, VELMIM ); analogWrite(motor3Pin, VELMIM ); }
void loop() {
if (irrecv.decode(&results)) { vlRec = results.value; if(vlRec == 16753245) //(on) { liga(); Serial.println("ligado"); } if(vlRec == 16748655 ) //(+) { VELMEDIA += 1; liga(); Serial.print("Velocidade aumentando "); Serial.print(VELMEDIA); Serial.println(" "); if(VELMEDIA >= 245) { VELMEDIA = 245; Serial.println(VELMEDIA); } } if(vlRec == 16754775) //(-) { VELMEDIA -= 1; Serial.print("Velocidade diminuindo "); Serial.print(VELMEDIA); Serial.println(" "); if(VELMEDIA <= 140) { VELMEDIA = 140; Serial.println(VELMEDIA); } liga(); } if(vlRec == 16736925 ) //(MODE) { desliga(); VELMEDIA = 140; Serial.println("Desligado"); } else { Serial.println(vlRec); } irrecv.resume(); } }
|
|
|
|
|
9
|
International / Portugues / Re: Controlando ESC com arduino ** problema**
|
on: August 06, 2012, 10:31:53 am
|
|
Tirei os delay´s, ja estava sem antes, eu achei que poderia "tirar" essa defasagem com os delay´s. O problema continua o mesmo, realmente acho que o problema esta na freqüência mesmo, obrigado vou ler com atenção esse link.
**s pinos foi porque eu testei tanto no MEGA como no UNO.
|
|
|
|
|
10
|
International / Portugues / Controlando ESC com arduino ** problema**
|
on: August 06, 2012, 09:19:41 am
|
Estou com duvidas em como controlar um ESC com Arduíno (mega2560). Já pesquisei em vários sites e vi que é pela saída PWM, cheguei a conseguir controlar e variar a velocidade conforme eu queria. Em um belo dia, do nada, começou a funcionar um esc por vez (incrivelmente o 1° motor iniciava depois de algum tempo o 2° iniciava com velocidade inferior, e depois de algum tempo o 2° motor ficava com a velocidade maior que a do 1°). Agora não consigo ligar nenhum, troquei a programação (que antes a velocidade era controlada por um sensor IR + controle) para o teclado, mas mesmo assim não funciona mais e quando funciona não inicia os dois ao mesmo tempo. Pensei que meu Arduíno tinha estragado mas tenho um uno também e ocorre o mesmo problema. Já tentei trocar os motores, os esc, mas nada acontece, sei que eles estão funcionando porque consigo um programação que inclui a biblioteca Servo.h , consigo ligar os 2 mas eles iniciaram “Defasados”.
Agora e estou utilizar essa : int motor1 = 4; int motor2 = 7; int velocidade = 140; int dir;
void setup() { Serial.begin(9600); pinMode ( motor1, OUTPUT); pinMode ( motor2, OUTPUT); }
void liga() { analogWrite (motor1, velocidade); analogWrite (motor2, velocidade); } void desliga() { analogWrite (motor1, 0); analogWrite (motor2, 0); } void loop() { dir=Serial.read();
if( dir == 'p') { liga(); } if( dir == 'n') { desliga(); } if( dir == '+') { velocidade +=5; liga(); if(velocidade >= 250) { velocidade=245; } Serial.println(velocidade); } if( dir == '-') { velocidade -=5;
if(velocidade <= 5) { velocidade = 5; } liga(); Serial.println(velocidade); } }
Sei que não estão danificados pois essa programação funciona mas não os 2 ao mesmo tempo: #include <Servo.h>
Servo myservo; Servo myservo1;
void arm(){ setSpeed(0); delay(1500); }
void setSpeed(int speed){ int angle = map(speed, 0, 100, 0, 180); delay(100); myservo1.write(angle); delay(100); myservo.write(angle); Serial.print(angle); }
void setup() { myservo1.attach(8); myservo.attach(7); arm(); }
void loop() { int speed;
for(speed = 0; speed <= 255; speed += 10) {
setSpeed(speed); delay(2000); } setSpeed(0); delay(5000); } **manual motor :http://www.hobbyking.com/hobbyking/store/uploads/764345172X380519X32.jpg **manual ESC: http://www.hobbyking.com/hobbyking/store/uploads/8656078X637952X10.pdf
|
|
|
|
|