LusoRobótica - Robótica em Português
Software => Software e Programação => Tópico iniciado por: silva_p em 16 de Maio de 2009, 19:26
-
Estou a tentar programar o arduino para mover 4 servos com a nunchuck mas quando mando compilar dá este erro:
hardware\libraries\Wire/Wire.h: In function 'void loop()':
hardware\libraries\Wire/Wire.h:30: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t* loop()::TwoWire::rxBuffer'
hardware\libraries\Wire/Wire.h:31: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t loop()::TwoWire::rxBufferIndex'
hardware\libraries\Wire/Wire.h:32: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t loop()::TwoWire::rxBufferLength'
hardware\libraries\Wire/Wire.h:34: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t loop()::TwoWire::txAddress'
hardware\libraries\Wire/Wire.h:35: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t* loop()::TwoWire::txBuffer'
hardware\libraries\Wire/Wire.h:36: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t loop()::TwoWire::txBufferIndex'
hardware\libraries\Wire/Wire.h:37: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t loop()::TwoWire::txBufferLength'
hardware\libraries\Wire/Wire.h:39: error: local class 'class loop()::TwoWire' shall not have static data member 'uint8_t loop()::TwoWire::transmitting'
hardware\libraries\Wire/Wire.h:40: error: local class 'class loop()::TwoWire' shall not have static data member 'void (* loop()::TwoWire::user_onRequest)()'
hardware\libraries\Wire/Wire.h:41: error: local class 'class loop()::TwoWire' shall not have static data member 'void (* loop()::TwoWire::user_onReceive)(int)'
já utilizei ambas a bibliotecas em separado e ambas funcionam bem!
o código que estou a usar é este:
(o codigo da nunchuck é do guibot) ;)
#include <MegaServo.h>
#include "nunchuck.h"
// test sketch for MegaServo library
// this will sweep all servos back and forth once, then position according to voltage on potPin
#define gdPin 9
#define gePin 3
#define bPin 5
#define bbPin 7
MegaServo servogd; // declare variables for up to eight servos
MegaServo servoge;
MegaServo servob;
MegaServo servobb;
int val0 =0;
int val1=0;
int val2 =0;
void setup()
{
Serial.begin (9600);
nunchuk_init ();
delay(1000);
servogd.attach(gdPin); // attach a pin to the servos and they will start pulsing
servoge.attach(gePin);
servob.attach(bPin);
servobb.attach(bbPin);
}
void loop()
{
if (nunchuk_get_data()) {
if (nunchuk_button_z & nunchuk_button_c) {
int joy_x = nunchuk_joy_x;
int joy_y = nunchuk_joy_y;
if (joy_x > 215) {
val0 = val0 -1;
servob.write(val0);
Serial.println(val0);
}
else if (joy_x < 40) {
val0 =val0 +1;
servob.write(val0);
Serial.println(val0);
}
}
else {if (nunchuk_button_z) {
int joy_x = nunchuk_joy_x;
int joy_y = nunchuk_joy_y;
if (joy_x > 215) {
val1 = val1 -1;
servobb.write(val1);
Serial.println(val1);
}
else if (joy_x < 40) {
val1 =val1 +1;
servobb.write(val1);
Serial.println(val1);
}
else {if (nunchuk_button_c){
int joy_x = nunchuk_joy_x;
int joy_y = nunchuk_joy_y;
if (joy_x > 215) {
val2 = val2 -1;
servogd.write(val2);
servoge.write(val2);
Serial.println(val2);
}
else if (joy_x < 40) {
val2 =val2 +1;
servogd.write(val2);
servoge.write(val2);
Serial.println(val2);
}}
delay (20);
}}
alguém sabe o que se passa?
em anexo vai o código completo, tem mais 2 separadores
-
então pessoal? ninguém me sabe ajudar? ???
-
O problema é que ambas as funções utilizam o watchdog 2 do atmega, e assim sendo, acabam por entrar em conflito pois este já está configurado com um timing, não pode ser modificado para outro.
O melhor é utilizar um outro atmega por Serial ou SPI, visto que não poderás implementar I2C nesse se utilizares o mega servo a controlar os servos... Entretanto se conseguir arranjar maneira de ficarem as duas a correr eu digo ;)
-
eu n sei qual é o funcionamento da megaservo.h, mas uma solução que te apresento, nem que seja apenas pra experimentares pôr isso a funcionar, é fazer o controlo directo por código (sem a ultilização da biblioteca de controlo dos servos) dos servos. é capaz até de nem ficar pior.
-
então e a servoTimer2?
tb usa o watchdog 2? :(
-
Sim silva, mas antes de avançarmos mais, testa fazer analogWrite para os pins que dizem PWM escrito, com a biblioteca wire em uso ao mesmo tempo, para vermos se assim serve.