Visualizza messaggio singolo
Vecchio 03 maggio 20, 18:29   #58 (permalink)  Top
Smsteves
User
 
Data registr.: 03-05-2020
Residenza: milano
Messaggi: 47
Brutta cosa non poterlo provare in diretta...

Ho rivisto il tutto, ho aggiunto il calcolo automatico dell'escursione in base al gain
ti mando un msg.

#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 3 //-- 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 int Rxpulse;
unsigned int Gaspulse ;
unsigned int Course;
unsigned int Gain;

unsigned int NewPos, OldPos;
byte Stato = 0;
void setup() {
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() {

if (Stato == 0) {
//lettura
Rxpulse = pulseIn(8, HIGH);
Gaspulse = pulseIn(7, HIGH);
}


if (Stato == 1) {
//Calcolo
Gaspulse = constrain (Slowlimit, 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/2 ;//dimezza la corsa in gradi per ciascun lato
Course= Course*Gain/100 ;//calcola i gradi di escursione in base all'accelleratore
NewPos = map(Rxpulse, Antsx, Antdx, (Postsx + Course ), (Postdx - Course));
}

if (Stato == 2) {
//scrittura
if (abs(NewPos - OldPos) > Tolerance) {
OldPos = NewPos;
myservo.write(NewPos + Center);
}
}

//ritardo esecuzione cicli/stati
delay(3);

// Incrementa stato per il prossimo loop
++Stato;

if (Stato == 3) {
// riparte da 0
Stato = 0;
}


}
Smsteves non รจ collegato   Rispondi citando