Visualizza messaggio singolo
Vecchio 04 maggio 20, 13:39   #88 (permalink)  Top
Smsteves
User
 
Data registr.: 03-05-2020
Residenza: milano
Messaggi: 47
Accidenti che belli, Chapeau

Comunque per quante prove faccia al banco (anzi al tavolo) non mi riesce di percepire il problema come fai te.

Ho provato ad inserire una smorzatura al comando, come si fa di solito sugli inverter industriali...

Prova un po' se la cosa migliora...
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 5 //-- 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;
int Media_GAS=0;
int Media_RX=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
    Media_RX=0;
    Media_GAS =0;
    Rxpulse = pulseIn(8, HIGH);   
    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) {
      if (abs(NewPos - OldPos) > Tolerance/2){
        
      }
      if (NewPos > OldPos){
         NewPos=OldPos + 15;
      }
     if (NewPos < OldPos){
         NewPos=OldPos - 15;
      }
      if (abs(NewPos - OldPos) < Tolerance/2){
        
 
      if (NewPos > OldPos){
         NewPos=OldPos + 2;
      }
     if (NewPos < OldPos){
         NewPos=OldPos - 2;
      }


      
      }
      myservo.write(NewPos + Center);
         OldPos=NewPos;
    }
  }
  // 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);
  } 
}
Smsteves non รจ collegato   Rispondi citando