Arduino+Brushless Motor Problem

User avatar
Bazinga+
Exalted Member
Exalted Member
Posts: 383
Joined: March 8th, 2014, 7:10 am
Division: C
State: NY
Has thanked: 0
Been thanked: 0

Arduino+Brushless Motor Problem

Post by Bazinga+ »

So I've been working with brushless motors for about 2 months now and still cant quite get the hang of controlling them from an Arduino. I originally had an arduino UNO connected to a DC motor and an encoder and it worked quite well (disregarding the fact that it was slow as pigeon). I decided to get a Brushless Motor/ESC combo for 60$ and did some research on controlling it from the arduino(control like a servo through servo.write). Unfortunately, when I went over a certain speed (for servo.write() it was 120 and for servo.writemilliseconds() it was 1750) the car would speed up without stopping, and we had to manually catch it every run. At first I thought it was a problem with the arduino/motor esc combo/connection and I replaced the arduino and the motor/esc with a more expensive one, and the problem was still there. I then assumed the problem came up because of the encoder, namely the interrupts, which leave the main task to add a count to the encoder and then come back, which was making the esc receive a longer delay between the HIGH and LOW signals in the servo.write command, therefore making it go faster, turn the encoder faster, and lead to a chain reaction. I decided to try the program out without the encoder, and made a new program with no interrupts, and everything was written on delays. This time, the problem was still happening, but at a higher speed. I am planning to replace the arduino UNO with a better processor (arduino DUE) but im not sure if that will fix the problem which I still dont know the exact cause of. I have a theory that the esc cant handle sudden changes in speed (straight from 100 to 140) so it freaks out, but im not sure. Does anyone know the root of this problem? Has anyone else had this problem and how have you fixed it? If you have never had this problem then what is your brushless motor-esc-arduino set up? Thanks!
(P.S., I've been searching around the internet for a while for similar problems and haven't found anything helpful)
Innovation =/= success
iwonder
Admin Emeritus
Admin Emeritus
Posts: 1115
Joined: May 10th, 2011, 8:25 pm
Division: Grad
State: TX
Has thanked: 0
Been thanked: 1 time

Re: Arduino+Brushless Motor Problem

Post by iwonder »

So if I understand correctly you still have the issue when you use only servo.h and run the vehicle, timing with a delay? And it's that the vehicle speeds up, not simply runs too long?

In case it isn't obviously speeding up, Id run the vehicle in the air (the motor should jump straight to the target speed quickly), and see if it is actually commanding a faster speed at a certain point.

Ideally you could use an oscilloscope to view the PWM being sent from the arduino to the ESC and find if the arduino has the issue or the ESC. The next option might be to run it on a remote control and see if the ESC can handle that fine. You might have to adjust the full speed/full reverse setting on the ESC (usually this involves a few buttons, sending full throttle and then full reverse to the ESC), but it's been a while since I had to do something like that.

If it's the arduino, definitely switch to the Due and start troubleshooting with that, it seems fruitless to spend time troubleshooting the UNO when you might solve the problem with the Due anyways.
'If you're the smartest person in the room, you're in the wrong room' - Unknown
User avatar
Bazinga+
Exalted Member
Exalted Member
Posts: 383
Joined: March 8th, 2014, 7:10 am
Division: C
State: NY
Has thanked: 0
Been thanked: 0

Re: Arduino+Brushless Motor Problem

Post by Bazinga+ »

iwonder wrote:So if I understand correctly you still have the issue when you use only servo.h and run the vehicle, timing with a delay? And it's that the vehicle speeds up, not simply runs too long?

In case it isn't obviously speeding up, Id run the vehicle in the air (the motor should jump straight to the target speed quickly), and see if it is actually commanding a faster speed at a certain point.

Ideally you could use an oscilloscope to view the PWM being sent from the arduino to the ESC and find if the arduino has the issue or the ESC. The next option might be to run it on a remote control and see if the ESC can handle that fine. You might have to adjust the full speed/full reverse setting on the ESC (usually this involves a few buttons, sending full throttle and then full reverse to the ESC), but it's been a while since I had to do something like that.

If it's the arduino, definitely switch to the Due and start troubleshooting with that, it seems fruitless to spend time troubleshooting the UNO when you might solve the problem with the Due anyways.
Ive controlled it without servo.h (manually with delays and signals) and still had this problem. I've tried switching PMW pins and all that and im pretty sure that the signal is fine, but the esc is just receiving it in some weird way and misinterpreting the signal sometimes. The interesting thing is that this problem doesnt seem to happen when the vehicle is in the air, so it only happens when there is a load on the motor. I've considered gearing more down (right now gear ratio is like 10 to 1), but not sure if that will actually help. DO you know if anyone else has had this problem when just using servo.h to control the esc, because i couldn't find anything online so i'm guessing not many people have this problem even though many people control esc's from arduinos. Any idea what they could be doing differently, i've tried practically everything.
Innovation =/= success
User avatar
windu34
Staff Emeritus
Staff Emeritus
Posts: 1384
Joined: April 19th, 2015, 6:37 pm
Division: Grad
State: FL
Has thanked: 2 times
Been thanked: 42 times

Re: Arduino+Brushless Motor Problem

Post by windu34 »

When I first started approaching this problem, I went to the local r/c store to see if they knew anything about what we were trying to do. They told me they had never heard of trying to control an r/c car in an autonomous fashion and told me and my partner that we would be breaking new ground in the r/c world. How much do you know about coding in C and just in general? I did pretty much the same thing so it is definetly possible. Look into the way you are implementing the code and break it down. Research drag racing and r/c car racing just to understand the dynamics. Also know the way brushless motors are normally controlled and how they operate. The most concise piece of advice that will mos likely solve your problem is to look into your control methods and implementation of them when running the motors.
Boca Raton Community High School Alumni
University of Florida Science Olympiad Co-Founder
Florida Science Olympiad Board of Directors
[email protected] || windu34's Userpage
User avatar
samlan16
Member
Member
Posts: 528
Joined: December 30th, 2013, 2:54 pm
Division: Grad
State: GA
Has thanked: 0
Been thanked: 5 times
Contact:

Re: Arduino+Brushless Motor Problem

Post by samlan16 »

windu34 wrote:When I first started approaching this problem, I went to the local r/c store to see if they knew anything about what we were trying to do. They told me they had never heard of trying to control an r/c car in an autonomous fashion and told me and my partner that we would be breaking new ground in the r/c world. How much do you know about coding in C and just in general? I did pretty much the same thing so it is definetly possible. Look into the way you are implementing the code and break it down. Research drag racing and r/c car racing just to understand the dynamics. Also know the way brushless motors are normally controlled and how they operate. The most concise piece of advice that will mos likely solve your problem is to look into your control methods and implementation of them when running the motors.
I'm confused. If the car is autonomous, why do you need RC?
Old fart who sort of did things sort of for some schools.
User avatar
windu34
Staff Emeritus
Staff Emeritus
Posts: 1384
Joined: April 19th, 2015, 6:37 pm
Division: Grad
State: FL
Has thanked: 2 times
Been thanked: 42 times

Re: Arduino+Brushless Motor Problem

Post by windu34 »

samlan16 wrote:
windu34 wrote:When I first started approaching this problem, I went to the local r/c store to see if they knew anything about what we were trying to do. They told me they had never heard of trying to control an r/c car in an autonomous fashion and told me and my partner that we would be breaking new ground in the r/c world. How much do you know about coding in C and just in general? I did pretty much the same thing so it is definetly possible. Look into the way you are implementing the code and break it down. Research drag racing and r/c car racing just to understand the dynamics. Also know the way brushless motors are normally controlled and how they operate. The most concise piece of advice that will mos likely solve your problem is to look into your control methods and implementation of them when running the motors.
I'm confused. If the car is autonomous, why do you need RC?
Brushless motors and ESC's that we use are meant to be used on r/c cars which is why there is no existing code for us to use as a template like we do with the Servo.h library in Arduino for robot arm.
Boca Raton Community High School Alumni
University of Florida Science Olympiad Co-Founder
Florida Science Olympiad Board of Directors
[email protected] || windu34's Userpage
User avatar
Bazinga+
Exalted Member
Exalted Member
Posts: 383
Joined: March 8th, 2014, 7:10 am
Division: C
State: NY
Has thanked: 0
Been thanked: 0

Re: Arduino+Brushless Motor Problem

Post by Bazinga+ »

windu34 wrote:When I first started approaching this problem, I went to the local r/c store to see if they knew anything about what we were trying to do. They told me they had never heard of trying to control an r/c car in an autonomous fashion and told me and my partner that we would be breaking new ground in the r/c world. How much do you know about coding in C and just in general? I did pretty much the same thing so it is definetly possible. Look into the way you are implementing the code and break it down. Research drag racing and r/c car racing just to understand the dynamics. Also know the way brushless motors are normally controlled and how they operate. The most concise piece of advice that will mos likely solve your problem is to look into your control methods and implementation of them when running the motors.
I'm not sure what exactly your getting at with this. I've tried almost all the possible software fixes i could think of (including manually coding the servo.write function without the servo.h library), as well as having smooth transitions from speed to speed and other things. Currently im also experimenting with read() to possibly stabilize the signal to the esc, but I doubt that will fix anything. I'm pretty sure that this problem is occurring because of a phase shift in the motor which should theoretically be fixed by gradually changing the speed, but then it should have been fixed by gradually changing the speed.
Innovation =/= success
User avatar
windu34
Staff Emeritus
Staff Emeritus
Posts: 1384
Joined: April 19th, 2015, 6:37 pm
Division: Grad
State: FL
Has thanked: 2 times
Been thanked: 42 times

Re: Arduino+Brushless Motor Problem

Post by windu34 »

Bazinga+ wrote:
windu34 wrote:When I first started approaching this problem, I went to the local r/c store to see if they knew anything about what we were trying to do. They told me they had never heard of trying to control an r/c car in an autonomous fashion and told me and my partner that we would be breaking new ground in the r/c world. How much do you know about coding in C and just in general? I did pretty much the same thing so it is definetly possible. Look into the way you are implementing the code and break it down. Research drag racing and r/c car racing just to understand the dynamics. Also know the way brushless motors are normally controlled and how they operate. The most concise piece of advice that will mos likely solve your problem is to look into your control methods and implementation of them when running the motors.
I'm not sure what exactly your getting at with this. I've tried almost all the possible software fixes i could think of (including manually coding the servo.write function without the servo.h library), as well as having smooth transitions from speed to speed and other things. Currently im also experimenting with read() to possibly stabilize the signal to the esc, but I doubt that will fix anything. I'm pretty sure that this problem is occurring because of a phase shift in the motor which should theoretically be fixed by gradually changing the speed, but then it should have been fixed by gradually changing the speed.
How did you implement your code to gradually change your speed?
Boca Raton Community High School Alumni
University of Florida Science Olympiad Co-Founder
Florida Science Olympiad Board of Directors
[email protected] || windu34's Userpage
User avatar
Bazinga+
Exalted Member
Exalted Member
Posts: 383
Joined: March 8th, 2014, 7:10 am
Division: C
State: NY
Has thanked: 0
Been thanked: 0

Re: Arduino+Brushless Motor Problem

Post by Bazinga+ »

windu34 wrote:
Bazinga+ wrote:
windu34 wrote:When I first started approaching this problem, I went to the local r/c store to see if they knew anything about what we were trying to do. They told me they had never heard of trying to control an r/c car in an autonomous fashion and told me and my partner that we would be breaking new ground in the r/c world. How much do you know about coding in C and just in general? I did pretty much the same thing so it is definetly possible. Look into the way you are implementing the code and break it down. Research drag racing and r/c car racing just to understand the dynamics. Also know the way brushless motors are normally controlled and how they operate. The most concise piece of advice that will mos likely solve your problem is to look into your control methods and implementation of them when running the motors.
I'm not sure what exactly your getting at with this. I've tried almost all the possible software fixes i could think of (including manually coding the servo.write function without the servo.h library), as well as having smooth transitions from speed to speed and other things. Currently im also experimenting with read() to possibly stabilize the signal to the esc, but I doubt that will fix anything. I'm pretty sure that this problem is occurring because of a phase shift in the motor which should theoretically be fixed by gradually changing the speed, but then it should have been fixed by gradually changing the speed.
How did you implement your code to gradually change your speed?
Something like this
for(Pulse=1500;Pulse<1800;Pulse+=){
noInterrupts();
digitalWrite(HIGH);
delayMicroseconds(Pulse);
digitalWrite(LOW);
interrupts();
delay(20-(Pulse/1000));
}
(basically the same as servo.write)
When I tested this the encoder was missing a ton of counts because it wasn't counting from noInterrupts to interrupts, so ideally I wouldn't want to go through this loop 300 times. Would it still work well (as in not glitch out) if I went up in increments of 10 or even 50?
Innovation =/= success
User avatar
windu34
Staff Emeritus
Staff Emeritus
Posts: 1384
Joined: April 19th, 2015, 6:37 pm
Division: Grad
State: FL
Has thanked: 2 times
Been thanked: 42 times

Re: Arduino+Brushless Motor Problem

Post by windu34 »

Bazinga+ wrote:
windu34 wrote:
Bazinga+ wrote: I'm not sure what exactly your getting at with this. I've tried almost all the possible software fixes i could think of (including manually coding the servo.write function without the servo.h library), as well as having smooth transitions from speed to speed and other things. Currently im also experimenting with read() to possibly stabilize the signal to the esc, but I doubt that will fix anything. I'm pretty sure that this problem is occurring because of a phase shift in the motor which should theoretically be fixed by gradually changing the speed, but then it should have been fixed by gradually changing the speed.
How did you implement your code to gradually change your speed?
Something like this
for(Pulse=1500;Pulse<1800;Pulse+=){
noInterrupts();
digitalWrite(HIGH);
delayMicroseconds(Pulse);
digitalWrite(LOW);
interrupts();
delay(20-(Pulse/1000));
}
(basically the same as servo.write)
When I tested this the encoder was missing a ton of counts because it wasn't counting from noInterrupts to interrupts, so ideally I wouldn't want to go through this loop 300 times. Would it still work well (as in not glitch out) if I went up in increments of 10 or even 50?
That's gonn abe something you will have to experiment with. Why don't you just use the servo.h commands? worked fine for me. I don't quite understand what you are sending to the servo in this scenario because there is no writeMicroseconds() present
Boca Raton Community High School Alumni
University of Florida Science Olympiad Co-Founder
Florida Science Olympiad Board of Directors
[email protected] || windu34's Userpage
Locked

Return to “Electric Vehicle C”

Who is online

Users browsing this forum: No registered users and 1 guest