2
respostas

Library VarSpeedServo não funciona

A inclusão da Library VarSpeedServo com as alterações sugeridas não compila e não exibe mensagem clara de erro.

#include <VarSpeedServo.h>

#include <Servo.h>


#define ANGULO_INICIAL_MOTOR 90

int auxBase = ANGULO_INICIAL_MOTOR; 
int auxBraco1 = ANGULO_INICIAL_MOTOR;
int auxBraco2 = ANGULO_INICIAL_MOTOR;
int auxGarra = ANGULO_INICIAL_MOTOR;

//--- Mapeamento dos Joysticks ---
#define joystick1X A0
#define joystick1Y A1
#define joystick2X A2
#define joystick2Y A3


// --- Mapeamento dos Servos ---
VarSpeedServo motorBase; 
VarSpeedServo motorBraco1; 
VarSpeedServo motorBraco2;
VarSpeedServo motorGarra;



// --- Inicialização ---
void setup() {
  mapearPinosDosMotores();
  inicializarAngulosDosMotores();
  mapearJoysticksComoInput();
}



//--- Loop Infinito ---
void loop() {
  moverBase();
  moverBraco1();
  moverBraco2();
  moverGarra();
  delay(100);
}   


//---Funçãoes Auxiliares ---

//Mapear Pinos dos Servos Motores
void mapearPinosDosMotores(){
  motorBase.attach(5);
  motorBraco1.attach(6);
  motorBraco2.attach(9);
  motorGarra.attach(10);  
}

//Inicializar Angulos iniciais dos Motores
void inicializarAngulosDosMotores(){
  motorBase.write(ANGULO_INICIAL_MOTOR);
  motorBraco1.write(ANGULO_INICIAL_MOTOR);
  motorBraco2.write(ANGULO_INICIAL_MOTOR);
  motorGarra.write(ANGULO_INICIAL_MOTOR);
}

//Mapear os pinos do Joystick como INPUT
void mapearJoysticksComoInput(){
  pinMode(joystick1X, INPUT);
  pinMode(joystick1Y, INPUT);
  pinMode(joystick2X, INPUT);
  pinMode(joystick2Y, INPUT);  
}

//Mover Base
void moverBase(){
  int pos1X = analogRead(joystick1X);
  pos1X = map(pos1X, 0, 1023, 0, 180); //Aqui a mágica acontece
  if(pos1X > 100){ 
      auxBase+=10;
      motorBase.write(auxBase,50);
  }else if(pos1X <80){
    auxBase-=10;
    motorBase.write(auxBase,50);
  }
}

//Mover Braco1
void moverBraco1(){
  int pos1Y = analogRead(joystick1Y);
  pos1Y = map(pos1Y, 0, 1023, 45, 135); //Aqui a mágica acontece
  if(pos1Y > 100){ 
      auxBraco1+=10;
      motorBraco1.write(auxBraco1,50);
  }else if(pos1Y <80){
    auxBraco1-=10;
    motorBraco1.write(auxBraco1,50);
  }     
}

//Mover Braco2
void moverBraco2(){
  int pos2X = analogRead(joystick2X);
  pos2X = map(pos2X, 0, 1023, 50, 90); //Aqui a mágica acontece
  if(pos2X > 100){ 
      auxBraco2+=10;
      motorBraco2.write(auxBraco2,50);
  }else if(pos2X <80){
    auxBraco2-=10;
    motorBraco2.write(auxBraco2,50);
  } 
} 

//Mover Garra
void moverGarra() {
  int pos2Y = analogRead(joystick2Y);
  pos2Y = map(pos2Y, 0, 1023, 70, 130);
  if(pos2Y > 100){ 
      auxGarra+=10;
      motorGarra.write(auxGarra,50);
  }else if(pos2Y < 80){
    auxGarra-=10;
    motorGarra.write(auxGarra,50);
  }  
}
2 respostas

Oi Victor, tudo bem?

Por gentileza, cole aqui o log dos erros que estão sendo gerados para que possamos analisar.

Fico no aguardo para te ajudar, tá bom?

Olá Nádia, Então o IDE está apresentando a seguinte mensagem de errro:

Arduino: 1.8.13 (Windows 10), Placa:"Arduino Uno"





















In file included from C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:63:0,

                 from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:3:

C:\Program Files (x86)\Arduino\libraries\Servo\src/avr/ServoTimers.h:57:16: error: redeclaration of '_timer1'

 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

                ^~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:1:0:

C:\Users\User\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:112:16: note: previous declaration 'timer16_Sequence_t _timer1'

 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

                ^~~~~~~

In file included from C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:63:0,

                 from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:3:

C:\Program Files (x86)\Arduino\libraries\Servo\src/avr/ServoTimers.h:57:25: error: redeclaration of '_Nbr_16timers'

 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

                         ^~~~~~~~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:1:0:

C:\Users\User\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:112:25: note: previous declaration 'timer16_Sequence_t _Nbr_16timers'

 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

                         ^~~~~~~~~~~~~

In file included from C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:63:0,

                 from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:3:

C:\Program Files (x86)\Arduino\libraries\Servo\src/avr/ServoTimers.h:57:41: error: conflicting declaration 'typedef enum timer16_Sequence_t timer16_Sequence_t'

 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t;

                                         ^~~~~~~~~~~~~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:1:0:

C:\Users\User\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:112:41: note: previous declaration as 'typedef enum timer16_Sequence_t timer16_Sequence_t'

 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

                                         ^~~~~~~~~~~~~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:3:0:

C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:97:3: error: conflicting declaration 'typedef struct ServoPin_t ServoPin_t'

 } ServoPin_t   ;

   ^~~~~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:1:0:

C:\Users\User\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:133:3: note: previous declaration as 'typedef struct ServoPin_t ServoPin_t'

 } ServoPin_t   ;

   ^~~~~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:3:0:

C:\Program Files (x86)\Arduino\libraries\Servo\src/Servo.h:102:3: error: conflicting declaration 'typedef struct servo_t servo_t'

 } servo_t;

   ^~~~~~~

In file included from C:\Users\User\Documents\Arduino\braco_alura\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent\bracoRoboticoAluraPosFinalSemComent.ino:1:0:

C:\Users\User\Documents\Arduino\libraries\VarSpeedServo/VarSpeedServo.h:140:3: note: previous declaration as 'typedef struct servo_t servo_t'

 } servo_t;

   ^~~~~~~

exit status 1

Erro compilando para a placa Arduino Uno



Este relatório teria mais informações com
"Mostrar a saida detalhada durante a compilação"
opção pode ser ativada em "Arquivo -> Preferências"