Du må være registrert og logget inn for å kunne legge ut innlegg på freak.no
X
LOGG INN
... eller du kan registrere deg nå
Dette nettstedet er avhengig av annonseinntekter for å holde driften og videre utvikling igang. Vi liker ikke reklame heller, men alternativene er ikke mange. Vær snill å vurder å slå av annonseblokkering, eller å abonnere på en reklamefri utgave av nettstedet.
  8 3932
Hei

Fant denne koden og har modifisert så den funker, men skulle gjerne hatt 30% oppstart i 5-10 sek, før den gir bånn gass. Nå gir den bånn gass rett etter arming av ESC.

Har lagt inn int sppatupvalue som er ca 30%, men hvordan få den til å gå først 5 sek før speedvalue slår inn ?

// This sketch arms the Platinum ESC
int escPin = 9;
int arm = 1000; // pulse width in microseconds for arming
int startupvalue = 1300; //pulse width in microseconds for startup
int speedvalue = 1900; // pulse width in microseconds for operation
void setup()
{

// It appears that the ESC will accept a range of values for the arming
// sequence. This provides 10 pulses with a pulse width of 1000 us with
// with a 20 ms delay between pulses.
pinMode(escPin, OUTPUT);
for (int count = 0; count < 150; count++){
digitalWrite(escPin, HIGH);
delayMicroseconds(arm);
digitalWrite(escPin, LOW);
delay(20);
}
}

void loop()
{
// Once armed the ESC needs to receive a pulse train to operate the
// the motor. The motor speed is controlled by the duration of the
// pulse width.
// This simple loop provides a pulses width a width of 1350 us and a
// separation of 20 ms.
digitalWrite(escPin, HIGH);
delayMicroseconds(speedvalue);
digitalWrite(escPin, LOW);
delay(20);
}
Sikkerhetsklarert
sleng inn en delay(5000) der du ønsker at den skal vente 5 sekunder.

Er dette forresten hele koden din?
Du definerer variablen "startupvalue" og gir den verdi 1300, men den brukes ikke noe sted i koden din.
Sist endret av Pjukern; 24. februar 2017 kl. 14:07.
Sitat av Pjukern Vis innlegg
sleng inn en delay(5000) der du ønsker at den skal vente 5 sekunder.

Er dette forresten hele koden din?
Du definerer variablen "startupvalue" og gir den verdi 1300, men den brukes ikke noe sted i koden din.
Vis hele sitatet...

Det som jeg lurer på. Trenger 2 looper.

Loop 1.
void loop()
{
// This simple loop provides a pulses width a width of 1300 ( Ca 30%, skal kjøres i 5 sek ).
// separation of 20 ms.
digitalWrite(escPin, HIGH);
delayMicroseconds(startupvalue);
digitalWrite(escPin, LOW);
delay(20);
}


Loop 2.
void loop()
{
// This simple loop provides a pulses width a width of 1900 us and a
// separation of 20 ms.
digitalWrite(escPin, HIGH);
delayMicroseconds(speedvalue);
digitalWrite(escPin, LOW);
delay(20);
}

Hvordan syr man det sammen så programmet starter på loop 1, og etter 5 sek fortsetter uendelig på loop 2 ?
Sist endret av Markula; 27. februar 2017 kl. 08:59.
Sitat av Markula Vis innlegg
Det som jeg lurer på. Trenger 2 looper.

Loop 1.
void loop()
{
// This simple loop provides a pulses width a width of 1300 ( Ca 30%, skal kjøres i 5 sek ).
// separation of 20 ms.
digitalWrite(escPin, HIGH);
delayMicroseconds(startupvalue);
digitalWrite(escPin, LOW);
delay(20);
}


Loop 2.
void loop()
{
// This simple loop provides a pulses width a width of 1900 us and a
// separation of 20 ms.
digitalWrite(escPin, HIGH);
delayMicroseconds(speedvalue);
digitalWrite(escPin, LOW);
delay(20);
}

Hvordan syr man det sammen så programmet starter på loop 1, og etter 5 sek fortsetter uendelig på loop 2 ?
Vis hele sitatet...
Tror ikkje du for resultatet du ønsker med den koden. Arduino har egne PWM porter som kan brukes til akkurat slike formål. Koden du ønsker er som følgende.

Kode

int armWidth = 1000;
int escPin = 9;
int startupValue = 77;
int speedValue = 255;

void setup( )
{
        pinMode(escPin, OUTPUT);

        // Arming ESC with 10 pulses of 1000us HIGH and 20ms LOW
        for(int count = 0; count < 10; count++ )
        {
                digitalWrite(escPin, HIGH);
                delayMicroseconds(armWidth);
                digitalWrite(escPin, LOW);
                delay(20);
        }

        // Starting ESC with 30% speed and sleeping for 5000ms.      
        analogWrite(escPin, startupValue);
        delay(5000);

        // Setting ESC speed to 100%
        analogWrite(escPin, speedValue);
}

void loop( ) 
{

}
EDIT: Hvis det er en myk start du ønsker deg, så er en loop som teller fra 30 til 255 og setter den verdien på PWM porten. Og bruk ~22ms delay per runde i loopen.
Sist endret av 0xFF; 27. februar 2017 kl. 10:57.
Sitat av 0xFF Vis innlegg

// Starting ESC with 30% speed and sleeping for 5000ms.
analogWrite(escPin, startupValue);
delay(5000);

// Setting ESC speed to 100%
analogWrite(escPin, speedValue);
Vis hele sitatet...
Dette blir også feil, siden PWM-signalet ikke er separert med 20 ms.

Det går heller ikke ann å bruke to void loop() i samme program.

Jeg ville gjort noe slikt, en enkel if-test som benytter millis() for å sjekke tiden:

Kode

// This sketch arms the Platinum ESC
int escPin = 9;
int arm = 1000; // pulse width in microseconds for arming
int startupvalue = 1300; //pulse width in microseconds for startup
int startuptime = 5000; //5000 ms delay for startup
int speedvalue = 1900; // pulse width in microseconds for operation
void setup()
{

  // It appears that the ESC will accept a range of values for the arming
  // sequence. This provides 10 pulses with a pulse width of 1000 us with
  // with a 20 ms delay between pulses.
  pinMode(escPin, OUTPUT);
  for (int count = 0; count < 150; count++) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(arm);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}

void loop()
{
  // Once armed the ESC needs to receive a pulse train to operate the
  // the motor. The motor speed is controlled by the duration of the
  // pulse width.
  // This simple loop provides a pulses width a width of 1350 us and a
  // separation of 20 ms.

  // Startup in the first 5000 ms
  if (millis() < startuptime) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(startupvalue);
    digitalWrite(escPin, LOW);
    delay(20);
  }
  //Normal operation below
  else {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(speedvalue);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}
Sist endret av Ferner-Jensen; 27. februar 2017 kl. 12:44.
Sitat av Ferner-Jensen Vis innlegg
Dette blir også feil, siden PWM-signalet ikke er separert med 20 ms.

Det går heller ikke ann å bruke to void loop() i samme program.

Jeg ville gjort noe slikt, en enkel if-test som benytter millis() for å sjekke tiden:

Kode

// This sketch arms the Platinum ESC
int escPin = 9;
int arm = 1000; // pulse width in microseconds for arming
int startupvalue = 1300; //pulse width in microseconds for startup
int startuptime = 5000; //5000 ms delay for startup
int speedvalue = 1900; // pulse width in microseconds for operation
void setup()
{

  // It appears that the ESC will accept a range of values for the arming
  // sequence. This provides 10 pulses with a pulse width of 1000 us with
  // with a 20 ms delay between pulses.
  pinMode(escPin, OUTPUT);
  for (int count = 0; count < 150; count++) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(arm);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}

void loop()
{
  // Once armed the ESC needs to receive a pulse train to operate the
  // the motor. The motor speed is controlled by the duration of the
  // pulse width.
  // This simple loop provides a pulses width a width of 1350 us and a
  // separation of 20 ms.

  // Startup in the first 5000 ms
  if (millis() < startuptime) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(startupvalue);
    digitalWrite(escPin, LOW);
    delay(20);
  }
  //Normal operation below
  else {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(speedvalue);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}
Vis hele sitatet...
Takk!
Den fungerer fint, men ser det at etter 5 sek med startupvalue1300 ( 30 % ) så blir det for brått og øke til 100%. Skulle gjerne hatt at den da hadde en rolig akslasjon på 10 sek. Så 30% i 5 sek, så 30-->100% på 10 sek.
I see you...
NAPse's Avatar
Nå er det første gang jeg har gjort noe i Arduino-kode, men slik jeg kan se så funker det slik som du ønsker. Tror jeg..

Jeg la til følgende kode i slutten på "if"-statement'en i koden til Ferner-Jensen:

Kode

while(startupvalue < speedvalue){ // Så lenge "startupvalue" er mindre enn "speedvalue", gjør dette:
      digitalWrite(escPin, HIGH);
      delayMicroseconds(startupvalue);
      digitalWrite(escPin, LOW);
      startupvalue = startupvalue + acc; // akselererer med fast tempo
      delay(20);
    }
I tillegg endra jeg noen int verdier til float. Jeg vet ikke om det skaper trøbbel for deg?

Ny kode blir da:
SPOILER ALERT! Vis spoiler

Kode

// This sketch arms the Platinum ESC
int escPin = 9;
int arm = 1000; // pulse width in microseconds for arming
float startupvalue = 1300; //pulse width in microseconds for startup
int startuptime = 5000; //5000 ms delay for startup
float speedvalue = 1900; // pulse width in microseconds for operation
float acc = (speedvalue-startupvalue)/500; //Deler farts-differansen med 500ms(10000ms/20ms) for å få trinnvise steg med lik akselerasjon på 10s.
void setup()
{
 
  // It appears that the ESC will accept a range of values for the arming
  // sequence. This provides 10 pulses with a pulse width of 1000 us with
  // with a 20 ms delay between pulses.
  pinMode(escPin, OUTPUT);
  for (int count = 0; count < 150; count++) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(arm);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}
 
void loop()
{
  // Once armed the ESC needs to receive a pulse train to operate the
  // the motor. The motor speed is controlled by the duration of the
  // pulse width.
  // This simple loop provides a pulses width a width of 1350 us and a
  // separation of 20 ms.
  // Startup in the first 5000 ms
  if (millis() < startuptime) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(startupvalue);
    digitalWrite(escPin, LOW);
    delay(20);
    while(startupvalue < speedvalue){ // Så lenge "startupvalue" er mindre enn "speedvalue", gjør dette:
      digitalWrite(escPin, HIGH);
      delayMicroseconds(startupvalue);
      digitalWrite(escPin, LOW);
      startupvalue = startupvalue + acc; // akselererer med fast tempo
      delay(20);
    }
  }

  //Normal operation below
  else {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(speedvalue);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}
Sitat av NAPse Vis innlegg
Nå er det første gang jeg har gjort noe i Arduino-kode, men slik jeg kan se så funker det slik som du ønsker. Tror jeg..

Jeg la til følgende kode i slutten på "if"-statement'en i koden til Ferner-Jensen:

Kode

while(startupvalue < speedvalue){ // Så lenge "startupvalue" er mindre enn "speedvalue", gjør dette:
      digitalWrite(escPin, HIGH);
      delayMicroseconds(startupvalue);
      digitalWrite(escPin, LOW);
      startupvalue = startupvalue + acc; // akselererer med fast tempo
      delay(20);
    }
I tillegg endra jeg noen int verdier til float. Jeg vet ikke om det skaper trøbbel for deg?

Ny kode blir da:
SPOILER ALERT! Vis spoiler

Kode

// This sketch arms the Platinum ESC
int escPin = 9;
int arm = 1000; // pulse width in microseconds for arming
float startupvalue = 1300; //pulse width in microseconds for startup
int startuptime = 5000; //5000 ms delay for startup
float speedvalue = 1900; // pulse width in microseconds for operation
float acc = (speedvalue-startupvalue)/500; //Deler farts-differansen med 500ms(10000ms/20ms) for å få trinnvise steg med lik akselerasjon på 10s.
void setup()
{
 
  // It appears that the ESC will accept a range of values for the arming
  // sequence. This provides 10 pulses with a pulse width of 1000 us with
  // with a 20 ms delay between pulses.
  pinMode(escPin, OUTPUT);
  for (int count = 0; count < 150; count++) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(arm);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}
 
void loop()
{
  // Once armed the ESC needs to receive a pulse train to operate the
  // the motor. The motor speed is controlled by the duration of the
  // pulse width.
  // This simple loop provides a pulses width a width of 1350 us and a
  // separation of 20 ms.
  // Startup in the first 5000 ms
  if (millis() < startuptime) {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(startupvalue);
    digitalWrite(escPin, LOW);
    delay(20);
    while(startupvalue < speedvalue){ // Så lenge "startupvalue" er mindre enn "speedvalue", gjør dette:
      digitalWrite(escPin, HIGH);
      delayMicroseconds(startupvalue);
      digitalWrite(escPin, LOW);
      startupvalue = startupvalue + acc; // akselererer med fast tempo
      delay(20);
    }
  }

  //Normal operation below
  else {
    digitalWrite(escPin, HIGH);
    delayMicroseconds(speedvalue);
    digitalWrite(escPin, LOW);
    delay(20);
  }
}
Vis hele sitatet...

Takk for hjelpen! Her en test med en mer aggresiv start.

https://www.facebook.com/pg/eMantafo...=page_internal
I see you...
NAPse's Avatar
Den så jo snedig ut!
Kanskje det er mulig å dele ut noen rabatter til de som har hjulpet på freak.