Go Down

Topic: Best way to control a brushless motor (Read 123 times) previous topic - next topic

rossi86m

Dec 06, 2018, 06:37 pm Last Edit: Dec 06, 2018, 06:37 pm by rossi86m
Hello!!!!

I am building a bicopter and I am using the servo library to control the brushless motors but i feel that the reaction is not fast enough.

I would like to get some feedback on which is the best way to control them.

Thanks in advance!!
Marco

Just in case here is the flight controller code that i am building

PaulS

Quote
but i feel that the reaction is not fast enough.
How have you determined how fast the motor changes speed as you use the Servo library to control it?

Or, are you complaining that the whole program is too slow?
The art of getting good answers lies in asking good questions.

rossi86m

I made a simple test with a code where i just take the output from the rc controller and pass it to the motors using the servo library and there i saw that the motors have a little delay.

I think that, that small delay when trying to stabilized the bicopter becomes a huge delay.

I can be wrong, so any suggestion is more than welcome.

Cheers,
Marco

vinceherman

#3
Dec 06, 2018, 06:56 pm Last Edit: Dec 06, 2018, 09:18 pm by vinceherman
I made a simple test with a code where i just take the output from the rc controller and pass it to the motors using the servo library and there i saw that the motors have a little delay.
In what way did you measure this delay?
The time frames involved look instantaneous to the human eye.
I have used RC transmitters with fast response time (Airtronics SD10G) and RC Transmitters with slow response time (Futaba 9c with a Spektrum module).
You cannot visually tell the difference.
Using these on a RC airplane, you could not tell the difference.

But using these different transmitters to fly an RC helicopter and there was a difference you could feel.

Both were flyable.  But the faster transmitter let me feel more connected to the heli.

If you have delays with your bicopter control, you need to determine if it is in your code or i the servo library.  What is the cycle time on your code?

Edit: I took a look at your code.  I see you using atan() a lot.
When I was playing with a hexapod and inverse kinematics, I determined that atan() was too slow.  I used an approximation routine to replace atan() and got better results.
And I think that I had many less calls to atan() than you do.
Put some simple time monitoring in your code. Grab millis at the top of every loop and log it to an array.  You will quickly fill the array, so stop once you put in some fixed number of entries.  Then dump them out so you can see the values.  How long does each loop take?

rossi86m

Basically I did this

void loop()
{
 
  time_loop_1 = millis();

  rc_read_values(); 
  getMpuValues();
  getHcsrValues();
  computePIDs();
  stabilize();

  time_loop_2 = millis();
  Serial.print("Time cycle: ");Serial.print(time_loop_2 - time_loop_1); Serial.print("\n");


}

I am getting between 4 and 5 milliseconds on each loop

I am using 2 atan() in the setup and 2 in the loop to get the gyro angles

Do you think that 4 or 5 millis is a reasonable number?

Thanks for the help!!

vinceherman

Well, 400 in your init, but that is in your setup so not a problem during the loop.

4 or 5 millis is quite good.  The servo library only sends a new pulse every 20 millis if my math is right.
I do understand that many in the quad hobby are going with higher refresh rates to get better (something, I don't know what).  But I think that is a relatively recent tech improvement.  Plenty of successful aircraft have been made with standard servos, ESCs and servo library.

Adam's Bicopter Slave One from 2015.


rossi86m

#6
Dec 06, 2018, 10:57 pm Last Edit: Dec 06, 2018, 11:01 pm by rossi86m
Yes I saw those guys. They are awesome. But I think they didn't shared the code to have a look at it.

Edit: I tryied using OCR1A and OCR1B. I do not have a really good understanding how that works. I think i got some conflicts or interference with other components i am using that is why i went back to the servo library

Thanks!

Go Up