Sto provando sul tavolo con esc radio futaba 3vcs 2,4ghz esc toro con 17.5 e lipo..
Il servo e' un cinesone mg996r.
Ho provato a bypassare il comando da arduino al servo e credo che l'unica differenza sia dovuta alla libreria di arduino..
con tolleranza = 1 e un ritardo di 20 millessimi credo sia decente, dimmi cosa ne pensi.
Codice:
#define Neutral 1500 // -- minimum forward signal
#define Maxspeed 2000 // -- maximum 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 endpoint 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 xx value to center steering
#define Tolerance 0 //-- if poor quality servo vibrates try 5
#define Max_gain 950 //-- gain steering reduction by throttle if reverse add -
#define Slowlimit 1800 //-- slow forward without endpoint correction
#include <Servo.h>
Servo myservo;
unsigned int Rxpulse;
unsigned int Gaspulse ;
unsigned int Gain;
signed int NewPos, OldPos;
int Stato;
int Stato_Led=0;
boolean Cmd_Led = false;
int Ledpin=13;
int Led=0;
int Tol_cont=0;
void setup() {
pinMode(7, INPUT); //-- throttle signal in pin
pinMode(8, INPUT); //-- front servo signal in pin
pinMode(Cmd_Led, OUTPUT);
myservo.attach(10); //-- rear servo signal out pin
Stato = 0;
}
void loop() {
if (Stato == 0) {
//lettura
Rxpulse = pulseIn(8, HIGH);
delay(2);
Gaspulse = pulseIn(7, HIGH);
}
if (Stato == 1) {
//Calcolo
if (Gaspulse > Slowlimit) {
Gain = map(Gaspulse, Slowlimit, Maxspeed, 0, Max_gain );
NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + Gain), (Postdx - Gain));
Led=1;
}
else {
NewPos = map(Rxpulse, Antsx, Antdx, Postsx, Postdx);
Led=2;
}
}
if (Stato == 2) {
//scrittura
if (abs(NewPos - OldPos) > Tolerance) {
OldPos = NewPos;
delay(20);
myservo.write(NewPos + Center);
}
}
// Incrementa stato per il prossimo loop
++Stato;
// Incrementa tempo led per il prossimo loop
++Stato_Led;
if (Stato == 3) {
// riparte da 0
Stato = 0;
}
//ritardo esecuzione cicli/stati
delay(1);
if (Led == 1) {
//led veloce
if (Stato_Led>20) {
Cmd_Led= !Cmd_Led;
Stato_Led=0;
}
digitalWrite(Ledpin, Cmd_Led);
}
if (Led == 2) {
//led lento
if (Stato_Led>60) {
Cmd_Led= !Cmd_Led;
Stato_Led=0;
}
digitalWrite(Ledpin, Cmd_Led);
}
}
Non posto foto per evitare sghignazzamenti..