Go Down

Topic: I2C to PWM converter (Read 4182 times) previous topic - next topic


Hello, first post here so I wanted to lay my project out.  Unfortunately I have no experience programming Arduino, but I am a fast and willing learner.  I will describe my goal, and I then will be interested in what path of learning I need to take, to gain the knowledge to achieve my goal.  I'm not asking for someone to do this for me or tell me how to do this, but rather, how and where I can learn what is needed, so that I can develop and create this myself.

My goal is to take the output from the AR Drone quadcopter and adapt it to be four PWM signals that regular ESC's can use.  Currently the AR Drone outputs to four proprietary motor controller / esc / motor combos, so there is no easy interchange to use larger motors, for building bigger and better things.

Here is a link to a page that explains about this communication stream for the motors, the most I've found anywhere:

The Arduino would be tasked with several functions.  First, in order to keep the AR Drone "happy", it will need to communicate data back to the AR Drone's board in a way that supplies the information in place of motor controllers, so the AR Drone does not detect anything wrong.  If a motor controller is damaged, the AR Drone will refuse to fly - it doesn't blindly give commands to the motors unless it knows they're all working (including not stalled out).

Second, the Arduino will need to quickly monitor what the AR Drone is trying to tell the four motor controllers to do for power levels.  This will involve interpreting the I2C connection for each of the four motors.

Third, the Arduino will need to compare the motor values to each other to figure out what their differences represent, such as 45% on the left and 55% on the right actually meaning a roll left (at a certain rate), which it can then multiply by a gain (knob or variable), and apply the new PWM outputs.  The gains that would need to exist would be throttle, roll, pitch, and yaw.  For example, using this with bigger motors in a bigger airframe, we might need a gain of 90% to lower the throttle outputs, but when rolling, this would need to be applied as a greater difference between PWM outputs, in order to have it react at the same roll rate the AR Drone is expecting.  This really is a tuning scheme common to all DIY flight controllers, adjusting the response sensitivity.  It's just that here, we are trying to match it up to what the AR Drone is used to.

Finally, the Arduino will need to output to several PWM channels, which will feed ESC's for the brushless motors as desired.  There is the desire to have this be a "fast" PWM signal, such as 400hz.

I know enough to modify video games and was able to root my Android phone, so I'm not a total novice to program-minded things.  I actually can work wonders in Lego NXT-G which is a graphical interface of LabView I believe, so I think I could learn what it takes to achieve what I'm shooting for.  It will be a heck of an ordeal, but I'm willing to learn.  I expect I'll need to start out by getting the big Arduino learning kit from Radio Shanty, and after working through that, will need to start seeking out people's projects that have done the various aspects I need, such as I2C communication, PWM output, etc.

The AR Drone is a great aircraft and offers flight advantages that no other flight controller has, such as using the downward facing camera to hold horizontal position in a precise hover aided by ultrasonic height sensors.  I know of no other flight controller that could do that, short of something like an ArduPilot Mega which you would have to write the entire camera-tracking position-hold thing for.  This adapter seems like the most reasonable path for me to get more quadcopters flying just like the AR Drone, by using the AR Drone flight boards inside.

Thank you for your time and I appreciate any input you can give me.  I've tried to ask around the AR Drone forums to find somebody who knows Arduino well enough to do this, but to no avail.  So it looks like I'm going to take on this mission myself.  I look forward to the help you can give.


My only information about AR Drone comes from YouTube videos of it flying, but if I understood you correctly your main objective is to take the existing control system and use them to drive more powerful motors, perhaps in a heavier/bigger chassis. The output stage of the motor controllers will just be transistors and resistors, so it might be easiest just to reverse engineer the circuit and replace the output stage with transistors capable of handling the current/voltage ranges you require, rather than replace the whole thing.

There is a risk that your new chassis will have different inertial characteristics or different weight-to-power resulting in the closed-loop control system parameters being wrong. That might lead to under-/over-correction in some modes. You have some influence over the authority in each mode by the placement of the lift motors and the distribution of mass within your chassis so it might be possible to work around those limitations.

If you go down the 'replace the whole thing' route you have a much harder problem since you would need to reverse engineer the comms protocol for the motor controllers, analyse and compare the power levels to infer the control demands from the flight controller, map those to the control demands appropriate to your new chassis (which may not be easy to do) and then re-mix them and produce your own power levels. It's a lot of work, and you would still need to deal with the issue that the feedback parameters for the original flight controller will be wrong for your new chassis.



Thanks for the reply.  It sounds like we're mostly on the same page here, especially your last paragraph.  The issue of over/under correction I believe can be handled by an few adjustable variables multiplying against the "inferred control demands".  Once we can tell its overall hovering average is "X" amount of power, and the difference between right and left motors when tilted is "Y", then with throttle gain "A" and roll gain "B", the output to the left side PWM's would be (X*A)-(Y*B), and the right side motors would be (X*A)+(Y*B).  Later when I have more time, I can try to map up all the variables for mixing input and output, I've done this a few times in RealFlight by "programming" flight controllers by putting together servo mix after servo mix.


FLO /* Front left original throttle value
FRO /* Front right original throttle value
RLO /* Rear left original throttle value
RRO /* Rear right original throttle value
FLN /* Front left new throttle value
FRN /* Front right new throttle value
RLN /* Rear left new throttle value
RRN /* Rear right new throttle value
RGAIN /* Roll gain variable
PGAIN /* Pitch gain variable
YGAIN /* Yaw gain variable
TGAIN /* Throttle gain variable

/* Determining underlying commands of pitch, roll, yaw, throttle


/* Mixing
/* Pitch+Roll
FLPR /* Front left pitch roll mix
FRPR /* Front right pitch roll mix
RLPR /* Rear left pitch roll mix
RRPR /* Rear right pitch roll mix


/* Yaw mix-in
FLPRY /* Front left PR yaw mix
FRPRY /* Front right PR yaw mix
RLPRY /* Rear left PR yaw mix
RRPRY /* Rear right PR yaw mix


/* Throttle mix-in

Then output FLN, FRN, RLN, and RRN to their respective PWM channels.  Adjust multiplying factors of Gains as needed for over/undercorrecting.


Well, I tried looking through all the motor code in that first post's link, and I'm losing confidence that there is enough information there.  I guess I had thought it was like one wire would be streaming a code of information over and over, and I could monitor that wire and there would be so many number of blocks of information, and I'd just have to pick out block 26 for one motor, block 27 for the next, etc.  But the more I look at it, the less this looks like the case.  I guess from being a newbie to advanced programming, I can't find anything in that information that clearly tells me how I can tap into the control stream.

Another idea I've had is to leave all four original motor controllers on there to do their whole fancy talking with the AR Drone mainboard, and then use the Arduino to monitor their motor output signals.  I would actually leave the motors on there, just not hooked to anything, and would need a way to monitor the frequency (or pulse duration more likely) of the three leads going to each motor.  This would add some slight lag to the system, but overall the new aircraft to be built will be much larger and therefore will have some mass to help slow down / smooth out any instabilities.  So then I need to figure out what a brushless motor signal looks like (the part actually going to the motor, not to its ESC) and then figure out how to have an Arduino monitor this to derive what throttle value it is at.


For a really stupid idea, could you just wire 4x motors with blades to just handle straight lifting with no pitch/turn capability but to just slightly negatively balance the heavy load and leave the 4x ARdrone motors with blades to handle the rest.
Basically the 4x new motors will handle the heavy lifting but the original drone blades will continue to steer the load.
Don't PM me for help as I will ignore it.


I think you should reconsider the approach of replacing the output drivers on the existing ESCs so that they can cope with your new motors. It's not a perfect solution (because the closed-loop feedback parameters will not be quite right) but it seems the simplest way to get it off the ground.


Riva - I have thought about that, and there's a few different approaches that I've come up with. 

One would be to use the entire existing airframe and then have framework extend outward to hold another four motors / props / esc's, with bigger batteries used and a knob to output the throttle speed for those other motors, so you could start off on a scale and increase the payload motors until it is sitting at only its original weight, and then tell the Drone to lift off, which it would now do like normal due to the relative "neutral buoyancy" the payload motors and all have created.

Another approach would be to put the add-on framework with its motors, batteries, everything, mounted on a ball joint located at the CG of the AR Drone (and the CG of this new payload frame).  So long as the CG's are all aligned, the Drone can tilt and roll without upsetting the payload frame, and the payload frame's flight controller keeps it holding level.  There would be issues with making sure the Drone cannot articulate into collision with the payload frame, but I feel this is doable.  I actually already have a quadcopter (in parts) coming in the mail to attempt this.

Another approach would be like that, but a "flying semi truck", which would use a hitch located at the CG of the Drone and of the payload airframe well behind it, and then a flight controller keeping the payload airframe level, and then an AFS gyro on the hitch beam that will send that angle (the height difference between the Drone and the payload frame) to be a throttle adjustment to the payload airframe, keeping it level with the Drone.

Those would be two very building-intensive (though no programming needed) ways to expand the AR Drone.  I'll work on those too.


PeterH - Sorry I ran out of time to post my reply to you earlier.  If you think it would be possible to take an existing motor controller and more or less solder a big 25 Amp ESC on there so that instead of running little 15 Watt motors, now we could run 250 Watt motors, I would gladly send you a motor unit to work on.  But I hate to phrase it like that, copping out and asking someone else to do it.  But if you could help me learn what it will take to do that solder-surgery myself, I'd be all for it.  The existing motor controllers are all surface-mount components, so it's pretty daunting to think of starting to rewire in that, plus the huge power difference would need completely parallel (and much larger)power lines running to it.


Feb 03, 2013, 05:12 am Last Edit: Feb 03, 2013, 06:11 pm by Schlauncha Reason: 1
Not seeking to cross-post, but maybe somebody could move this thread over to the section where I can offer $200 for somebody to program this for me?  I have posted this reward to entice somebody on the AR Drone Flyers forum, but nobody there has done it yet, not really the place since this requires more Arduino programming skill, than it does AR Drone knowledge.  Based off the information on this I2C to read/adapt, it really can probably be done without a programmer even having an AR Drone or having used one before.  I'll pay $200 USD by paypal to somebody who can produce code that works for this, upon my ability to replicate their results.  Not saying the aircraft has to fly perfect or anything, but just to where it works enough I can start tuning the gains to my airframe.  No hardware needed to send me, I have Arduino boards I can use, I just need the sketch.

Here is my thread on that forum, and all the talk there about it: http://www.ardrone-flyers.com/forum/viewtopic.php?f=8&t=4529

I have attached a program I found for converting I2C to PWM for the MikroKopter board, so maybe it's just as simple as changing which I2C bits it reads, and adding the motor comparison / remix math I listed above, so the outputs are on adjustable gains. 


Hello friend
I wonder if you can help me with a project I have, which is to manage the drivers esc with motors with arduino but understand that generated signal to move, but I think they are bytes would like to know how to do it
Sorry for the bad english

Go Up