Citazione:
Originalmente inviato da Smsteves Perdonami ma ho gettato nel lambro le medie...
Prova questo e sammi dire.. Codice: //----------- signal setup -------------------------------------
#define Neutral 1500 // -- minimum throttle forward signal
#define Maxspeed 2000 // -- maximum throttle forward signal
#define Antsx 1000 // -- in front servo signal sx
#define Antdx 2000 // -- in front servo signal dx
#define Postsx 1000 // out rear servo sx end point (if inverted with postdx it reverse)
#define Postdx 2000 //-- out rear servo dx endpoint (if inverted with postsx it reverse)
#define Center 0 //-- add or subtract your value to center steering (+- 50 or more)
//--------- user driving setup ------------------------------
#define Max_gain 600 //-- gain steering reduction width at max throttle (if reverse add (-) before value)
#define Slowlimit 1700 //-- slow forward percentage without endpoint correction
#define Tolerance 0 //-- if poor quality servo vibrates try 5
//----------------------------
#include <Servo.h>
Servo myservo;
#define N_STST 7
#define N_STGAS 7
unsigned int stSt[ N_STST ];
unsigned int stGas[ N_STGAS ];
long toStSt = 0;
long toStGas = 0;
int inSt = 0;
int inGas = 0;
unsigned int Rxpulse;
unsigned int Gaspulse ;
unsigned int Gain;
unsigned int NewPos, OldPos;
void setup() {
for ( int i=0; i<N_STST; i++ ) stSt[ i ] = 0;
for ( int i=0; i<N_STGAS; i++ ) stGas[ i ] = 0;
myservo.attach(10); //-- rear servo signal out pin
pinMode(8, INPUT); //-- front servo signal in pin
pinMode(7, INPUT); //-- throttle signal in pin
}
void loop(){
noInterrupts();
Rxpulse = pulseIn(8, HIGH);
Gaspulse = pulseIn(7, HIGH);
interrupts();
delay(5);
if (Gaspulse > Slowlimit) {
Gain = map(Gaspulse, Slowlimit, Maxspeed, 0, Max_gain );
NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + Gain), (Postdx - Gain));
}
else {
NewPos = map(Rxpulse, Antsx, Antdx, Postsx, Postdx);
}
if (abs(NewPos - OldPos)> Tolerance) {
OldPos = NewPos;
myservo.write(NewPos + Center);
}
}
Meno di cosi' non si può... Con un arduino nano da 3.50 euri... |
va molto bene
come lo hai stabilizzato senza medie?
si direi che è molto migliore
più veloce e identico nei settaggi.
ottimo direi.