Visualizza messaggio singolo
Vecchio 03 maggio 20, 23:58   #73 (permalink)  Top
Smsteves
User
 
Data registr.: 03-05-2020
Residenza: milano
Messaggi: 47
eccolo ripulito...



Prooooova



#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 5 // out rear servo sx endpoint if inverted with postdx it reverse
#define Postdx 175 //-- out rear servo dx endpoint if inverted with postsx it reverse
#define Center 0 //-- add or subtract xx value to center steering
#define Tolerance 5 //-- if poor quality servo vibrates try 5
#define Max_gain 100 //-- gain steering reduction by throttle if reverse add -
#define Slowlimit 1700 //-- slow forward without endpoint correction
#include <Servo.h>
Servo myservo;
unsigned long Rxpulse;//pulsin restituisce un long
unsigned long Gaspulse ;
unsigned long Gain;//Giusto per.. mettiamo long
signed long NewPos, OldPos;
int Stato;
byte debug = 1;
unsigned int Course;

void setup() {
pinMode(7, INPUT); //-- throttle signal in pin
pinMode(8, INPUT); //-- front servo signal in pin
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
Gaspulse = constrain (Gaspulse, Neutral, Maxspeed);//riduce valori dal canale gas
Gain = map(Gaspulse, Neutral, Maxspeed, 0, Max_gain);
Course = (Postdx - Postsx) ; //corsa in gradi da dx a sx
Course = Course * Gain / 100 ; //calcola i gradi di escursione in base all'accelleratore
NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + (Course / 2) ), (Postdx - (Course / 2)));
}

if (Stato == 2) {
//scrittura
if (abs(NewPos - OldPos) > Tolerance) {
OldPos = NewPos;
myservo.write(NewPos + Center);
}
}
// Incrementa stato per il prossimo loop
++Stato;
if (Stato == 3) {
// riparte da 0
Stato = 0;
}
//ritardo esecuzione cicli/stati
delay(1);
}

Ultima modifica di Smsteves : 04 maggio 20 alle ore 00:05
Smsteves non รจ collegato   Rispondi citando