Go Down

Topic: not a robot .... but the same size motor and esc? (Read 1 time) previous topic - next topic

Dravin21

trying to move things from loop left me with a plane that read the pot once and pegged full throttle ... that propeller is not kind to the fingers lol ....
reading the pot value and outputting it to the esc needs to be a looping function so the board keeps checking for changes and the motor changes speed accordingly

slipstick

I was sort of assuming you'd set the pot once and then leave it set and just plug the battery in to start the flight. That's how the simple C/L timers work.

But never mind, if you want to be able to keep adjusting the speed while the motor is running that's possible and as you say you'll have to leave the motor control in loop(). So how are you planning on starting the timer...is it still time starts when the battery is plugged in so time spent adjusting the motor reduces your flight time? Or something else? It may make the timer code more complicated because delay() will probably no longer work for you.

Steve




Dravin21

would setting a timed event in loop using if millis() .....setting pot value to zero ... stop the plane and land it or loop?
and how would i set it for minutes rather than miliseconds?
 ... the engine speed needs to be adjusted with the motor running and speed dialed in with a tachometer or by ear so being in loop helps
the arduino and esc power up as soon as the battery is connected and motor starts as soon as the pot value changes above zero ...with a few degrees of rotation on the pot free incase i dont turn it down all the way

Dravin21

#include <Servo.h>

Servo ESC;     

int potValue;

void setup() {

  Serial.begin(9600);
 
  ESC.attach(9,1000,2000);
}

void loop() {
  potValue = analogRead(A0);   
  potValue = map(potValue, 0, 1023, 0, 180);   
  ESC.write(potValue);
    if (millis()> 40000){
      ESC.write(0);

      for(;;){}
    }
}





this seems to work so far, plane powered up, motor went to speed for 4 sec then shut off and hasnt so much as twitched since ... i have been reading more as i can and watching alot of youtube ... i will report back if its good or a total fail after testing on a full battery

Dravin21

from my limited understandiing the if(millis()>set time) is the length of time the arduino waits, the esc write says to go to zero and stop the motor and "for (;;){}" having no increment or decrement and empty brackets sets the arduino looping a whole lot of nothing ... so that should work lol i hope

slipstick

That's not the normal way of using millis() because what you're testing is the time since the Arduino powered up, nothing to do with the motor starting. But if you're comfortable with that it should work for you. BTW the conventional way of getting an infinite loop is "while(1) {}", I've never tried your "for" version.

But it might be better to use:
Code: [Select]

if (millis() < 4000) // or whatever runtime you want
  ESC.write(potValue);
else
  ESC.write(0);

Then you don't need any infinite loop. Loop() will keep going round writing either 0 or potValue depending on the value of millis().

But if you really want it to time the motor run (i.e. after you've moved the pot from 0) you'll need to save the value of millis() as you write(potValue) and then check each time round if the current millis() - savedMillis() >= runtime).

Steve


Dravin21

The mustang all finished, a Corsair started and I put one of my robots in for fun lol


slipstick


Go Up