Ho scritto il seguente codice che serve a gestire un robot a 4 zampe:
sp4_leged_robot.ino:
#include <Servo.h>
#include "D:\Progetto sp4\software\sp4_legged_robot\funzioni.h"
#include "D:\Progetto sp4\software\sp4_legged_robot\DueTimer.h"
long duration, cmCENTRO;
long cmDX, cmSX, cm;
//variabile di stato per decidere quanto camminare
int cicli=1;
void sonar()
{
seleziona_sonar(TRIG_CENTRO);
rileva();
seleziona_sonar(TRIG_DX);
rileva();
seleziona_sonar(TRIG_SX);
rileva();
if(cmCENTRO<=40)
{
if(cmDX>=cmSX) {svolta(DX); digitalWrite(LED,LOW);}
if(cmDX<=cmSX) {svolta(SX); digitalWrite(LED,HIGH);}
}
}
void setup() {
//configurazione delle uscite PWM
braccio_dx.attach(2);
avanbraccio_dx.attach(3);
braccio_sx.attach(4);
avanbraccio_sx.attach(9);
gamba_dx.attach(6);
piede_dx.attach(7);
gamba_sx.attach(11);
piede_sx.attach(13);
//configurazione degli 8 pulsanti;
pinMode(51, INPUT);
pinMode(49, INPUT);
pinMode(47, INPUT);
pinMode(45, INPUT);
pinMode(43, INPUT);
pinMode(41, INPUT);
pinMode(39, INPUT);
pinMode(37, INPUT);
//configurazione degli I/O per gestione dei tre sonar
pinMode(LED, OUTPUT);
pinMode(ECHO_SX, INPUT);
pinMode(ECHO_DX, INPUT);
pinMode(ECHO_CENTRO, INPUT);
pinMode(TRIG_CENTRO, OUTPUT);
pinMode(TRIG_SX, OUTPUT);
pinMode(TRIG_DX, OUTPUT);
//configurazione interrupt rilevazione sonar
Timer5.attachInterrupt(sonar).start(500000); //testa presenza del segnale di eco ogni 500msec.
Timer5.start();
}
DueTimer.h:
/*
DueTimer.h - DueTimer header file, definition of methods and attributes...
For instructions, go to https://github.com/ivanseidel/DueTimer
Created by Ivan Seidel Gomes, March, 2013.
Modified by Philipp Klaus, June 2013.
Released into the public domain.
*/
#ifdef __arm__
#ifndef DueTimer_h
#define DueTimer_h
#include "Arduino.h"
#include <inttypes.h>
/*
This fixes compatibility for Arduono Servo Library.
Uncomment to make it compatible.
Note that:
+ Timers: 0,2,3,4,5 WILL NOT WORK, and will
neither be accessible by Timer0,...
*/
//#define USING_SERVO_LIB true
#ifdef USING_SERVO_LIB
#warning "HEY! You have set flag USING_SERVO_LIB. Timer0, 2,3,4 and 5 are not available"
#endif
#define NUM_TIMERS 9
class DueTimer
{
protected:
// Represents the timer id (index for the array of Timer structs)
const unsigned short timer;
// Stores the object timer frequency
// (allows to access current timer period and frequency):
static double _frequency[NUM_TIMERS];
// Picks the best clock to lower the error
static uint8_t bestClock(double frequency, uint32_t& retRC);
// Make Interrupt handlers friends, so they can use callbacks
friend void TC0_Handler(void);
friend void TC1_Handler(void);
friend void TC2_Handler(void);
friend void TC3_Handler(void);
friend void TC4_Handler(void);
friend void TC5_Handler(void);
friend void TC6_Handler(void);
friend void TC7_Handler(void);
friend void TC8_Handler(void);
static void (*callbacks[NUM_TIMERS])();
struct Timer
{
Tc *tc;
uint32_t channel;
IRQn_Type irq;
};
// Store timer configuration (static, as it's fixed for every object)
static const Timer Timers[NUM_TIMERS];
public:
static DueTimer getAvailable(void);
DueTimer(unsigned short _timer);
DueTimer& attachInterrupt(void (*isr)());
DueTimer& detachInterrupt(void);
DueTimer& start(long microseconds = -1);
DueTimer& stop(void);
DueTimer& setFrequency(double frequency);
DueTimer& setPeriod(unsigned long microseconds);
double getFrequency(void) const;
long getPeriod(void) const;
};
// Just to call Timer.getAvailable instead of Timer::getAvailable() :
extern DueTimer Timer;
extern DueTimer Timer1;
// Fix for compatibility with Servo library
#ifndef USING_SERVO_LIB
extern DueTimer Timer0;
extern DueTimer Timer2;
extern DueTimer Timer3;
extern DueTimer Timer4;
extern DueTimer Timer5;
#endif
extern DueTimer Timer6;
extern DueTimer Timer7;
extern DueTimer Timer8;
#endif
#else
#error Oops! Trying to include DueTimer on another device?
#endif
La libreria DueTimer serve a gestire un interrupt da timer.
Per favore provate a compilare il tutto cambiando il percorso degli headers con il vostro.
Come risultato della compilazione ottengo un messaggio che mi dice che non è stato dichiarato
l’ oggetto DueTimer, quindi il problema dovrebbe essere dentro al file DueTimer.h e precisamente
mi dice che Timer5 non è stato dichiarato.
Nessuno mi può aiutare a capire dov’è il problema?