There was a lot of Google searching and I slowly figured out what I needed to do in order to get the electronic speed controllers to respond to a program from the Raspberry PI. As you'll recall from previous posts, I was wondering if there was some kind of boot sequence that each ESC goes through before they start spinning the motors. You may also recall that I mentioned some kind of programming mode in an earlier test but I had no clue what was going on. There are some helpful links I eventually found that were particularly helpful:
- https://electronics.stackexchange.com/questions/24826/activating-electronic-speed-control-with-arduino
- Look at the first answer to this question especially. The person who answered this looked to be doing something VERY similar to what I am doing so this was very helpful!
- https://www.youtube.com/watch?v=XlJzCZ7qQxk
- This video is what showed me how I accidentally entered programming mode before. It was really just a coincidence but now I know that if I don't want programming mode, I need to power the ESC's with my throttle set to low. Not high...
With this information, I started my test program. I would start the program with PWM output at 0. But I later found that this was incorrect. The ESC's wouldn't initialize. So I thought back to the test I did where I plugged in the ESC's to the RF receiver. I wasn't sure but one thought I had was that perhaps the RF receiver wasn't starting off at a PWM output of 0. I needed to figure out what it WAS sending. So I started looking into ways to read PWM signals and came across this page.
I chose to use the first option and I already had a few Arduino's lying around so I went ahead and constructed my PWM measurement device. Upon hooking this thing up, I found that my transmitter and receiver had a PWM output of about 1020 at low throttle and somewhere around 1950 at full throttle. (or something like that) So it makes sense to set the output to 1020 as well, right?
Well, when using the Adafruit library, you also get this amazing function called setPwmFreq which, as the name suggests, sets the frequency for the PWM. Apparently when I just typed in 1020 as the PWM output, I was getting a VERY different duty cycle output. After some frustration, I decided to hook up my PWM reader to my Raspberry PI and see what I'm actually sending. I was right. It was WAY off. So I did some research on what PWM frequency most ESC's use and found this page:
Basically, my program was using 60Hz but I needed to be much higher than that! According to this link, I should be more in the 300Hz - 400Hz range. So I changed my test program to use 400Hz and my output didn't match what I was typing. In code, I told the control program to output a signal of 1020 but it was too high. So leaving the output set at 1020, I brought down the frequency until the actual output matched what I saw in code. Once the PWM output was closer to 1020, I called it good. In the end, I was around 214Hz for my frequency.
For the test program, I wanted to start everything off on low and then spin up one motor at a time. I set the PWM output to be 1020 on each ESC and then set the output to be 1900. After one second, I would take it back down to 1020 and move on to the next motor. I ran the program and was extremely excited because it finally worked! The results are in the video below.
Now that I have the motors responding to signals being sent from the Raspberry PI, it's time to start using the MPU-6050 to get orientation data.