Tuesday, August 30, 2011

Controlling a Brushless Motor with NETMF

2011-08-30 22.10.59
Continuing with the NETMF for Electronics Noobs Tutorials.  Today, I’ll demonstrate wiring up a brushless motor to your NETMF device.
 
If you’re building any type of R/C planes, copters, cars, boats or robots with your NETMF device then you’ll likely encounter the need to control a brushless motor.  Controlling a brushless motor is very different than controlling a regular brushed DC motor.  What makes it different is the addition of the Electronic Speed Controller (ESC).

The main reason this article exists is because the hobby parts distributors have done a terrible job of documenting these most basic of parts.  You should be able to go to the manufacturer website for the ESC you purchase and get most of this info.  However, my experience is that you can’t and they assume you know what you’re doing if you buy these parts.  Obviously, not the case or you wouldn’t be here.

If you click on the main photo, and look closely at the ESC (the blue part in the lower left corner) you will see that on one side it has three black wires.  These colors may vary from model to model.  On the other side it will have two thick red & black wires.  It will also have a bundle of two or three thinner wires depending on your model.

2011-08-30 22.12.09First connect the three black wires from the ESC to the three wires coming from your motor.  Right now you’re thinking “which wires on the motor go to which wires on the ESC?”.  Trust me, it doesn’t matter.  To understand why, study how brushless motors work and you’ll understand.  For now, just take a leap of faith.  If you find later that your motor is turning in the wrong direction, then swap any two of these wires and the direction will change.  It’s magic…
2011-08-30 22.24.17
The small bundle of three wires on my ESC are colored brown, red, and orange.  After quite a bit of digging, I finally found that the two outer wires are the important ones.  The brown wire is ground and the orange wire is the control.  The red wire in the center provides 5V power and can be used to power the microcontroller.  Most people do not recommend this due to the fact that when the motor is accelerated quickly it is possible that power could be momentarily lost.  This is an especially bad situation if you’re controlling a flying vehicle.  It’s not so bad if you’re controlling a car or plane.  If your bundle only has two wires, then you do not have the power wire.

You should wire the brown wire of the ESC bundle to any ground on your NETMF device.  For this example, I’m using a GHI Panda-II.  The orange wire should be connected to any PWM pin.  I’m using PWM1 (I/O 10).

2011-08-30 22.12.31Next, all you need to do is connect the red & black wires from the ESC to the respective wires on your battery.  If all is well, you will probably hear a series of tones from your ESC indicating that it is now armed.

NEVER TEST YOUR MOTOR WITH A PROPELLOR ATTACHED!!!

Until you have fully tested out your controls and have everything mounted securely and have a safe place to work, it is a really bad idea to attach the propellers.  If you have never worked with a brushless motor with a propeller on it, you will probably be amazed at how much power they have the first time your power it up.  Propellers are very sharp and will cut you.

Now that everything is wired up, it’s a simple thing to get the software going.  Start by downloading Chris’ Brushless Motor ESC driver class and add it to a new NETMF project.  Assuming you also used pin 10 to control your ESC, the following code should test your motor by powering it up to 20% power for about half a second and then powering it off.  Push the reset button to make it go again.

public static void Main()
{
    var m1 = new BrushlessMotor((PWM.Pin) FEZ_Pin.PWM.Di10);
    m1.Scale = 100;
    m1.SetPower(20);
    Thread.Sleep(500);
    m1.Stop();
}
If that works then you’re off and running.  Just figure out what power your project needs and when then apply where necessary.  If you need additional motors, then rinse & repeat but use a different PWM pin.

If you’re using a netduino or other NETMF device, do not be dissuaded.  It’s very easy to port Chris’ driver class to your device and to make the appropriate change to the test app.  Feel free to drop me a line if you need help.

Choulant asked for it and here they are - the parts used in this tutorial:



Have fun!

27 comments:

Anonymous said...

Nicely done. I'm curious about the wire gauge and connectors terminating the wires between the ESC and the Panda board.

Will

ianlee74 said...

Thanks. The wires between the ESC and Panda are just 18 gauge breadboard wire. You're only getting 5V and a few milliamps from the Panda. Just enough to send a signal to the processor in the ESC. So it's hard to go too small here. All the real current to the motor comes from the 16 gauge wires to the battery.

Anonymous said...

What kind of connector will you use in the final project to connect the ESC to the panda board? Will you make a shield with a specific connector type or is there some kind of terminator specifically suited to connecting to the panda port?

Will

ianlee74 said...

Will, for the Omnicopter I'm using a protoshield with a breadboard. I removed it for this article to simplify things. When I'm convinced I've got the main electronics worked out then I'll probably create a shield from a custom PCB. I'm planning to use JST connectors to connect the ESCs to the board.

Choulant said...

Hi,

Thank you, is it possible to have the link for the hardware that you use?

Thx

ianlee74 said...

I added the main components. Did I get everything you are looking for? Let me know if there's anything in particular. Thanks for visiting!

Choulant said...

type of motor, battery and dimmer?

Thank you

ianlee74 said...

Did you see the links I added to the bottom of the post? By "dimmer" I assume you mean the Electronic Speed Controller (ESC).

Austin said...

What is the status of this project so far? Were you successful in writing the code for a full quad on NETMF?

ianlee74 said...

I had some hardware issues and had to order some new ESCs from HobbyKing which took a couple months to get... In the meantime, I got distracted by a bunch of new Gadgeteer hardware. I'm planning to resume this project very soon. I can power all the motors using the remote but it is not flying stable yet. Stay tuned!

FiringFox said...

Hello and thanks for the article,
I have an Arduino Mega microcontroler, how do I port Chris' Brushless Motor ESC drvier for it ?
Thank you !

ianlee74 said...

Thanks. The programming model for Arduino is very different from that of NETMF. I believe there are probably some good drivers out there for Arduino since a majority of quadcopter projects are using Arduino. I'd check out diydrones.com. I bet someone there can point you to what you need. Good luck!

dueguard said...

Very nice article. One quick question though how would you implement a reverse method?

ianlee74 said...

Thanks, dueguard. To go in reverse, you have to have an ESC that is capable of going in reverse. Unfortunately, all of mine are built for aircraft which have no such need. So, I've been unable to test such I feature. I suspect it's as simple as knowing the correct PWM signal to send but a quick search didn't turn up anything. If you want to know more, I'd post this question in the forums at diydrones.com or tinyclr.com. Good luck!

Gabriel Wainmann said...

ianlee74, Thanks.
May I please ask how to port the code to Hydra +IO60p16?

ianlee74 said...

Gabriel, if you use the driver for the IO60P16 I currently have in development at http://netmfx.codeplex.com then it should be a snap. You'll just have to change a couple lines the IO60P16.PWM class instead of the NETMF PWM class. I'll try to work up an example later.

Gabriel Wainmann said...

Thanks. I'll be waiting for it!
Another thing: I was wondering (it's not clear from your pictures) how physically you distributed the voltage from the Turnigy battery to both the ESCs and the Gadgeteer board. The copter will not be connected to USB when it takes off...
Any suggestions?

ianlee74 said...

I'll try to get something worked up this weekend. I'm working on the PWM portion of the IO60P16 driver right now. So, this will be a good test.

Depending on your ESC, you can possibly power the Gadgeteer board using the BEC line coming from the ESC. It's the middle wire (not being used) in the three-wire cable in the first photo. If your ESC doesn't have a built in BEC then there are BECs that you can buy for just a few bucks from Hobby King that serve this purpose. Also, many people suggest that for flying vehicles you actually use a second battery to power your mainboard. This reduces the likelihood of a brown out occurring and causing your mainboard to reset. That's not much of an issue with a car or board but you don't really want that to happen with a flying vehicle :)

Gabriel Wainmann said...

Hmmm.. I see what you say about killing the Hydra board in mid-sky. Two questions, please:
1. If I use the BEC (I got it!) than I'd like dummy-proof instructions concerning the wiring: I have 4 ESCs (just one is needed? bundle the BECs?) and how do I go from one wire (BEC) to two wires (positive and negative) in the power jack?
2. Any suggestion for battery confivuration for the Hydra and some peripheral modules for a quadcopter?

Thanks!

ianlee74 said...

Basically, you just need the BEC line as your positive and your ground (negative) from the battery will be your negative to the mainboard. You'll have to add a rail somewhere on your copter so you have a way to distribute your grounds. If you're going through a DP module to power the Hydra then this probably isn't going to work since it has a minimum requirement of 7V and most BECs only supply 5V. However, you could try tying connecting the BEC directly to the 5V line of a socket (via some custom wiring or an Extender module).

Suggestions for modules? I guess that depends on what you want to do. You don't really need much to power the motors. Unfortunately, there's not a IMU module for Gadgeteer yet so you'll need an Extender to connect one of those. I wouldn't worry with adding anything else until after you have it flying :)

Gabriel Wainmann said...

Ian Lee, thanks for the elaborate answers.
I am asking about the power supply only to the Hydra, not the motors. Will a 9V do?

The rest of the setup is already done - ESCs, extender module, a 9DOF from sparkfun through the MakeBread module and a 3A Turnigy battery for the motors.

ianlee74 said...

A NEW 9V going through a DP module will work for a short time with a Hydra. I would recommend you pick up a small LiPo. It will last longer, be lighter, and more reliable.

Gabriel Wainmann said...

Thanks. What's "a small LiPo"? Voltage? Amperage?

ianlee74 said...

You'll need at least a 2S in order to get enough voltage. The rest depends on how often you want to charge it. Obviously, for a copter you want as minimal as possible to keep the weight down. Maybe a 800 mAh.

Gabriel Wainmann said...

And that's just for the Hydra? Remember, I have another LiPo for the ESCs...

ianlee74 said...

Yea. You might can find something a little smaller. I don't have any of the smaller LiPos to use for reference. Mine are all 4S 4000mAh. Shop around and compare sizes & weights. I wouldn't go less than a 500 mAh.

Personally, I wouldn't use a Hydra for this. I'd go with a Cerberus. Having only three PWMs is going to be a pain and using an IO60P16 is going to make a hard problem exponentially harder.

ianlee74 said...

Hi! Nice post!
However the link doesn't work anymore...

Brushless RC Plane

Post a Comment