$200 prize for whoever can make this mod

Parrot SDK, Linux SDK, Java, PC, Mac, scripts for Parrot drones... etc.
strangerjle
Battery Charged
Posts: 9
Joined: 11 Feb 2011, 19:05

Re: $200 prize for whoever can make this mod

Post by strangerjle » 06 Sep 2013, 14:16

Is this the complete codes ? Or I'm missing something. I'm trying to learn Arduino now but when I punch these code in and trying to verify it and it gave me bunch of errors. Do I have to hook up all the ESC and motors before I'm running these codes ? How do I hook up the aftermarket ESC onto the Ardrone 2.0 board ? I'm sorry but I'm to learn and need some guidance how to start the project.

He uploaded two sketch in the zip file. ARMOTOR & ARMOTOR_CALB. Thanks.



// Pawelsky 20130616
// Note that this code is experimental, it may behave unexpectedly and cause potential damage (spinning props can be dangerous)!
// USE AT YOUR OWN RISK!!!
#include <Servo.h>

//////////////////////////////////////////////////////////////////////////////
// YOU MUST SET THIS VALUE DEPNENDING ON WHICH MOTOR YOU LISTEN THE DATA FROM
// IF SET INCORRECTLY INCORRECT PWM COMMANDS PARSING WILL RETURN RUBBISH DATA!!!
//////////////////////////////////////////////////////////////////////////////
#define DATA_SOURCE_MOTOR MOTOR_RL
//////////////////////////////////////////////////////////////////////////////

// Min/max pulse values for ESC
#define ESC_MIN_PULSE 1000 // should be low enough to fully stop the motor (usually 1000)
#define ESC_MAX_PULSE 2000 // max value ESC can understand (usually 2000)

// You can modify gains for Roll/Pitch/Yaw/Throttlw to better match the new motrs
// The range is from 0.0f to 1.0f, where 1.0f equals 100%, 0.0f equals 0%, 0.5f equals 50% etc.
// Note the 'f' at the end f the number denotes float value
float RGAIN = 1.0f;
float PGAIN = 1.0f;
float YGAIN = 1.0f;
float TGAIN = 1.0f;


//////////////////////////////////////////////////////////////////////////////
// Values below should not be modified, unless you know what you are doing

#define MOTOR_FL 0 // front left motor id
#define MOTOR_FR 1 // front right motor id
#define MOTOR_RR 2 // rear right motor id
#define MOTOR_RL 3 // rear left motor id

#define LED_PIN 13
#define DEBUG_ON_PIN 2
#define ADJUST_ON_PIN 3

uint8_t motorPin[4] = {9, 10, 11, 12}; // FL, FR, RR, FL - DO NOT USE PIN 13! It is used to drive the LED
Servo motor[4];
int motorPWM[4];
uint8_t motorAliveReq[4] = {0x89, 0x8A, 0x8B, 0x8C};

uint8_t byteNo = 0;
int inputBytes[5];
uint8_t waitForMulticast = 0;
uint8_t skip = 0;
uint8_t debug = 0;
uint8_t adjust = 0;

// will be set to Serial1 if you are using Micro or Leonardo board, or to Serial otherwise (ATmega328P based boards)
#if defined(__AVR_ATmega32U4__)
#define SERIAL_PORT Serial1
#elif defined(__AVR_ATmega328P__)
#define SERIAL_PORT Serial
#else
#error "Unsupported processor"
#endif

uint8_t adjustmentPin[4] = {A0, A1, A2, A3}; // RGAIN, PGAIN, YGAIN, TGAIN

float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void adjustMotorPWM()
{
// If adjustement via potentiometers is enabled, read the adjustment values
if(adjust > 0)
{
RGAIN = mapFloat(analogRead(adjustmentPin[0]), 0, 1023, 0, 1);
PGAIN = mapFloat(analogRead(adjustmentPin[1]), 0, 1023, 0, 1);
YGAIN = mapFloat(analogRead(adjustmentPin[2]), 0, 1023, 0, 1);
TGAIN = mapFloat(analogRead(adjustmentPin[3]), 0, 1023, 0, 1);
}

// store the PWM values before adjustment (FL - front left, FR - front right, RR - rear right, RL rear left)
float FLO = (float)motorPWM[MOTOR_FL];
float FRO = (float)motorPWM[MOTOR_FR];
float RRO = (float)motorPWM[MOTOR_RR];
float RLO = (float)motorPWM[MOTOR_RL];

// calculate original Roll/Pitch/Yaw/Throttle and mdify it with gain
float Roll = (FLO - FRO - RRO + RLO) * RGAIN / 4;
float Pitch = (FLO + FRO - RRO - RLO) * PGAIN / 4;
float Yaw = (FLO - FRO + RRO - RLO) * YGAIN / 4;
float Throttle = (FLO + FRO + RRO + RLO) * TGAIN / 4;

// replace the original PWM values with adjusted ones
motorPWM[MOTOR_FL] = (int)(Throttle + Pitch + Roll + Yaw);
motorPWM[MOTOR_FR] = (int)(Throttle + Pitch - Roll - Yaw);
motorPWM[MOTOR_RR] = (int)(Throttle - Pitch - Roll + Yaw);
motorPWM[MOTOR_RL] = (int)(Throttle - Pitch + Roll - Yaw);
}

void SerialPrintPWM()
{
SERIAL_PORT.print(motorPWM[MOTOR_FL]); SERIAL_PORT.print(","); SERIAL_PORT.print(motorPWM[MOTOR_FR]); SERIAL_PORT.print(",");
SERIAL_PORT.print(motorPWM[MOTOR_RR]); SERIAL_PORT.print(","); SERIAL_PORT.print(motorPWM[MOTOR_RL]);
}

void SerialPrintGains()
{
SERIAL_PORT.print(RGAIN); SERIAL_PORT.print(","); SERIAL_PORT.print(PGAIN); SERIAL_PORT.print(",");
SERIAL_PORT.print(YGAIN); SERIAL_PORT.print(","); SERIAL_PORT.print(TGAIN);
}

void setMotorPWM()
{
if(debug > 0)
{
SerialPrintPWM(); SERIAL_PORT.print("->");
}
adjustMotorPWM();
if(debug > 0)
{
SerialPrintGains(); SERIAL_PORT.print("->");
SerialPrintPWM(); SERIAL_PORT.println("");
}
// Map PWM commands range to servo (ESC) range and send them to ESC
for(int i = 0; i < 4; i++)
{
motor.writeMicroseconds(map(motorPWM, 0, 511, ESC_MIN_PULSE, ESC_MAX_PULSE));
}
}

void parsePWMcommand()
{
// PWM command format: 001aaaaa aaaabbbb bbbbbccc ccccccdd ddddddd0
// a - motor 1, b - motor 2, c - motor 3, d - motor 4
if(((inputBytes[0] & 0xE0) == 0x20) && ((inputBytes[4] & 0x01) == 0x00))
{
digitalWrite(LED_PIN, HIGH); // turn the led on to signal PWM command parsed correctly
motorPWM[MOTOR_FL] = ((inputBytes[0] & 0x1F) << 4) | ((inputBytes[1] & 0xF0) >> 4);
motorPWM[MOTOR_FR] = ((inputBytes[1] & 0x0F) << 5) | ((inputBytes[2] & 0xF8) >> 3);
motorPWM[MOTOR_RR] = ((inputBytes[2] & 0x07) << 6) | ((inputBytes[3] & 0xFC) >> 2);
motorPWM[MOTOR_RL] = ((inputBytes[3] & 0x03) << 7) | ((inputBytes[4] & 0xFE) >> 1);
setMotorPWM();
digitalWrite(LED_PIN, LOW); // turn the led off
}
}

void initMotors()
{
for(int i = 0; i < 4; i++)
{
motor.attach(motorPin, ESC_MIN_PULSE, ESC_MAX_PULSE);
motor.writeMicroseconds(ESC_MIN_PULSE);
}
}

void initPins()
{
for(int i = 0; i < 4; i++)
{
pinMode(adjustmentPin, INPUT);
digitalWrite(adjustmentPin, HIGH); // enable pullup to set default state high
}
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // make sure the LED is off at start

pinMode(DEBUG_ON_PIN, INPUT);
digitalWrite(DEBUG_ON_PIN, HIGH); // enable pullup to set default state high
if(digitalRead(DEBUG_ON_PIN) == LOW) debug = 1;

pinMode(ADJUST_ON_PIN, INPUT);
digitalWrite(ADJUST_ON_PIN, HIGH); // enable pullup to set default state high
if(digitalRead(ADJUST_ON_PIN) == LOW) adjust = 1;
}

void setup()
{
initPins();
initMotors();
SERIAL_PORT.begin(115200);
}

void loop()
{
if(SERIAL_PORT.available() > 0)
{
inputBytes[byteNo] = SERIAL_PORT.read();
if(waitForMulticast < 6) // Waiting for 6 0xA0 in a row denoting start of multicast for motors
{
if(inputBytes[byteNo] == 0xA0)
{
waitForMulticast++;
}
else
{
waitForMulticast = 0;
}
}
else if(skip > 0)
{
skip--; // If there were any bytes to skip do it and decrease skip counter
}
else
{
if(byteNo == 0)
{
if(inputBytes[0] == motorAliveReq[DATA_SOURCE_MOTOR])
{
// skip next two bytes as these are responses to motor alive request
// and that can fool the PWM command detector
skip = 2;
}
else if((inputBytes[0] & 0xE0) == 0x20) // beginning of the PWM command, start collecting other 4 bytes
{
byteNo = 1;
}
}
else
{
byteNo++;
}
if(byteNo >= 5) // all 5 bytes of the PWM command collected, start parsing, and go back to listening for another one.
{
byteNo = 0;
parsePWMcommand();
}
}
}
}

pawelsky
Serious flight time
Posts: 1272
Joined: 02 Aug 2012, 22:01
Drone Type: Bebop
Location: Poland
Contact:

Re: $200 prize for whoever can make this mod

Post by pawelsky » 06 Sep 2013, 14:44

strangerjle wrote:Is this the complete codes ?
Yes
strangerjle wrote:I'm trying to learn Arduino now but when I punch these code in and trying to verify it and it gave me bunch of errors.
You probably selected wrong board in Arduino IDE
strangerjle wrote:Do I have to hook up all the ESC and motors before I'm running these codes ?
No
strangerjle wrote:I'm sorry but I'm to learn and need some guidance how to start the project.
I would suggest to start with tutorials and examples from Arduino website first
http://arduino.cc/en/Guide/HomePage
http://arduino.cc/en/Tutorial/HomePage

Schlauncha
Charged up again
Posts: 1102
Joined: 21 Jun 2011, 03:50
Drone Type: AR.Drone 2

Re: $200 prize for whoever can make this mod

Post by Schlauncha » 06 Sep 2013, 15:31

pawelsky wrote:I would suggest to start with tutorials and examples from Arduino website first
http://arduino.cc/en/Guide/HomePage
http://arduino.cc/en/Tutorial/HomePage
Definitely the way to go. You don't have to learn all about Arduino or how to write programs or any of that stuff, you just need a little bit of the introduction part where they show you the basics of how to set up the Arduino software on your computer, hook your Arduino to the computer, select the right Com port and Arduino board type, and then compile/download the program. After that it's just a matter of hooking up wires in accordance with Pawelsky's wiring diagram. To hook up your ESC's, put the white signal wires of each onto the corresponding Arduino pins, and then get a row of pins (probably on the shelf near the Arduino at Radio Shack) and solder a wire along them so the pins form an electrical comb shape, and then push this into the black ground side of the ESC's pwm cables (or "servo connectors" you might call them). Then hook that ground to one of the ground pins on the Arduino. Then wire up your four ESC's power wires together, and get a plug simulating the AR Drone's battery pack (mini tamiya) soldered in too, then solder your battery pack connector of choice on there, so then when hooking up a 3s Lipo (not 4s!), the power goes to the four ESC's as well as the AR Drone, and then from the AR Drone, 5v comes out along with a ground and data wire to the Arduino, and that's where it gets its power to run. If you want to run 4s, you will need a separate 3s lipo for the AR Drone to run on, wired separately from the ESC's power which comes from that 4s, if you're using 4s.

strangerjle
Battery Charged
Posts: 9
Joined: 11 Feb 2011, 19:05

Re: $200 prize for whoever can make this mod

Post by strangerjle » 07 Sep 2013, 04:02

Where is the link to download the wiring diagram ?

strangerjle
Battery Charged
Posts: 9
Joined: 11 Feb 2011, 19:05

Re: $200 prize for whoever can make this mod

Post by strangerjle » 07 Sep 2013, 04:05

I have a mega2560 and need help on the wiring.

Schlauncha
Charged up again
Posts: 1102
Joined: 21 Jun 2011, 03:50
Drone Type: AR.Drone 2

Re: $200 prize for whoever can make this mod

Post by Schlauncha » 07 Sep 2013, 04:49

strangerjle wrote:Where is the link to download the wiring diagram ?
It is in the .zip file with the sketch.

strangerjle
Battery Charged
Posts: 9
Joined: 11 Feb 2011, 19:05

Re: $200 prize for whoever can make this mod

Post by strangerjle » 07 Sep 2013, 05:32

I see the diagram JPG file now but only the RL MOTOR connecting to the ARDUINO BOARD. The other 3 boards got cutoff from the diagram ? The "X" in the diagram mean they are not being used ?

Schlauncha
Charged up again
Posts: 1102
Joined: 21 Jun 2011, 03:50
Drone Type: AR.Drone 2

Re: $200 prize for whoever can make this mod

Post by Schlauncha » 07 Sep 2013, 05:45

Each motor's data wire actually is receiving the full set of the four motor commands. Like a really fast repeating line of serial data. And then we listen to that with the Arduino, magic happens, and we have the four motor values inside the Arduino sketch that we can do more magic stuff to, and then output to the four PWM outputs for the new ESC's.

The X can also mean "unplug this pin from the connector". Unfortunately right now we have to keep the four AR Drone motor boards wired up (mostly) and aboard the aircraft, but once you're into bigger motors and props, you now can spare some payload for it. So we unplug the red wires (which are 12v pos) so the AR Drone motors won't waste power spinning (you can even clip them off but that's a one-way street kind of). The other wires shown X'd are the "emergency" line which lets each motor controller board report things like "Hey, we got like NO prop load here, what's going on? Emergency stop!" so we unplug that to keep things flying.

pawelsky
Serious flight time
Posts: 1272
Joined: 02 Aug 2012, 22:01
Drone Type: Bebop
Location: Poland
Contact:

Re: $200 prize for whoever can make this mod

Post by pawelsky » 07 Sep 2013, 11:41

strangerjle wrote:I have a mega2560 and need help on the wiring.
Sketch will not accept mega2560 board. It is meant for 32U4 and 328P based boards.

For mega you would have to mess with this part of the sketch.

Code: Select all

// will be set to Serial1 if you are using Micro or Leonardo board, or to Serial otherwise (ATmega328P based boards)
#if defined(__AVR_ATmega32U4__) 
#define SERIAL_PORT Serial1
#elif defined(__AVR_ATmega328P__)
#define SERIAL_PORT Serial
#else
#error "Unsupported processor"
#endif

strangerjle
Battery Charged
Posts: 9
Joined: 11 Feb 2011, 19:05

Re: $200 prize for whoever can make this mod

Post by strangerjle » 07 Sep 2013, 13:15

I guess that's answer my question when I verify the codes and gave me whole bunch of errors. I have ordered the exact Arduino Board & FTDI Breakboard in the diagram. So let me get this straight. We are going to wire all the "white wires" together and then go to the 5V on the Arduino Board which also going to solder that onto one side of the 10K POT, total of 4. Wire the "black wirers" together onto the ground on the Arduino Board which also going to solder that onto the other side of the 10K POT, total of 4. Does it matter which side is data and which side is ground on the 10K POT ? Last is to wire the "yellow, orange, blue & green" together and solder to RX0 on the Arduino Board ?

The D10, D11, D12, D13 each going to the WHITE WIRES of each new ESC accordingly.

Where are we going to hook the red & black wires from the side of the NEW ESC ? The small black & red wires. I know the big wires will supply to the battery as it's large so it needs a lot of current which is our main battery 3S 11V I'm using. I will buy the 4 ways distributor.

Schlauncha
Charged up again
Posts: 1102
Joined: 21 Jun 2011, 03:50
Drone Type: AR.Drone 2

Re: $200 prize for whoever can make this mod

Post by Schlauncha » 07 Sep 2013, 15:08

strangerjle wrote:Where are we going to hook the red & black wires from the side of the NEW ESC ? The small black & red wires. I know the big wires will supply to the battery as it's large so it needs a lot of current which is our main battery 3S 11V I'm using. I will buy the 4 ways distributor.
From each ESC you have a plug that has white / red / black. The white hooks up like you've mentioned, then the red hooks to nothing, and the black will hook to common ground with the Arduino. The red wire on the PWM plug of an ESC (at least most every brushless ESC that is) does not need to be supplied with voltage - rather, if the ESC has a BEC in it, you would see +5v coming from the ESC there. Which you don't need, and especially don't want to hook in parallel to the red wires of the other ESC's.

The big red and black wires of the four esc's, for the power input, will get hooked together in parallel. Solder them into a bundle, use a power distribution board, there are different ways to do this. You then also want a mini tamiya female connector soldered on in parallel there for the AR Drone mainboard to plug into (or you could cut the plug off the AR Drone and solder the wires directly) and then you also need a new battery plug soldered on to all this, to run your 3s lipo into. Check polarity on everything over and over.

Regarding the debug, pots, etc: I don't use them much. I just went with stock gains and gave it a go, and it worked, so either I got lucky, and/or the AR Drone is really good at compensating for flight behavior deviations. I would just fly, observe, land, hook up the Arduino and download a sketch with slightly adjusted gain values, and repeat. For the first few "flights" I wouldn't put propellers on the motors! But you'll have to lift the aircraft by hand, or it's UltraSonic sensors will see "hey, motors are on, but we're still on the ground! Emergency stop!" after a second or two. So then once you have it held in the air with prop-less motors spinning you can tilt it and make sure the correct corresponding motors speed up, and the others slow down. Basically, the lowest motors should spin faster, the highest motors should spin slower. You have to play that by ear. And if you turn the aircraft clockwise, the Front Left and Rear Right motors should speed up, and the Front Right and Rear Left motors should slow down. Once you verify everything is spinning the right direction (stock AR Drone and most quadcopter layout - props "scooping into the front and back, scooping out from the sides") and once you verify everything is correcting the way it should, then you're ready to put props on it, take it to somewhere with lots of room and very few people / objects to endanger, get yourself decently FAR BACK from it, then hit Launch and hope for the best. Whatever happens, just remember to get it on film!

pawelsky
Serious flight time
Posts: 1272
Joined: 02 Aug 2012, 22:01
Drone Type: Bebop
Location: Poland
Contact:

Re: $200 prize for whoever can make this mod

Post by pawelsky » 07 Sep 2013, 16:05

strangerjle wrote:I have ordered the exact Arduino Board & FTDI Breakboard in the diagram.
You can still use mega, try changing

Code: Select all

#elif defined(__AVR_ATmega328P__)
to

Code: Select all

#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega2560__)
Note that I don't have mega board, this is based on what I can see in documentation, so use at your own risk!
strangerjle wrote:The D10, D11, D12, D13 each going to the WHITE WIRES of each new ESC accordingly.
That should be D9, D10, D11, D12, not D10, D11, D12, D13!!!

strangerjle
Battery Charged
Posts: 9
Joined: 11 Feb 2011, 19:05

Re: $200 prize for whoever can make this mod

Post by strangerjle » 08 Sep 2013, 13:55

Okay. I have all the parts ordered. The only thing I have on hand right now is the AR DRONE 2.0 & the GPS Flight Recorder. Will this GPS Function still work after the mod ? The flight recorder let me draw my pathways and the AR DRONE 2.0 just fly there plus it has the flight to home option. My current drone fly very far and very high as I extended using the WRT54GSV2 router with 9 dbi extended antenna....I'm in the process of using it further with my 2 watts WIFI BOOSTER this will go even further. I can't even see the drone when flying it so high and as it getting too high I'm afraid it won't be stable because of the wind up there that's the reason I'm in need of upgrading to a stronger motors and high current ESC. When it's so high I can see the wind up there trying to push it a little bit and it cannot withstand the wind up there with the weak motors.

Back to the wiring....so if we cut the other RED wires on the current motor, this mean we don't have emergency stop option...am I right ? The current ECS came with the ad drone stay on board with the NEW ESC. I just have to cut the stock motors off the board. I will keep the original plug that on the old ESC. I will just cut the two wires on each board as instructed and them tab into the the other three and will wire them together going back to the ARDUINO BOARD according to the diagram PAWELSKY provided.

How do I power the FTDI BREAKOUT BOARD & the ARDUINO BOARD. I power it right now when testing the code using the USB CABLE as if I'm in the field then USB is not the cable to power it up. I know it need 5V to power it up will tab in the Ar Drone batter balance tab to have 6V...will this burn the board ? If not then which are these wires going to onto the ARDUINO BOARD & FTDI BREAKOUT BOARD ?

Schlauncha
Charged up again
Posts: 1102
Joined: 21 Jun 2011, 03:50
Drone Type: AR.Drone 2

Re: $200 prize for whoever can make this mod

Post by Schlauncha » 08 Sep 2013, 14:36

strangerjle wrote:Will this GPS Function still work after the mod ?
Yes. This mod is entirely "downstream" of the AR Drone, and the AR Drone doesn't really even know it's there. You could even add the r/c mod, since that interfaces with the AR Drone in a completely different way, and to reiterate, this PWM output mod is unaffected by such things by being completely "downstream".
strangerjle wrote:so if we cut the other RED wires on the current motor, this mean we don't have emergency stop option...am I right ?
Removing the red wires from the four AR Drone motorboards keeps them from spinning the motors you won't be using anymore (or even may remove). Removing the other wires indicated in the diagram (unique color to each board) is only to keep the motor boards from being able to cause Emergency stops. If a motor controller board isn't plugged in at all, the AR Drone mainboard gets upset and won't run. But if it's plugged in yet without the indicated wires, it will work. So then, there are Emergency stops the motor controllers can initiate if they see a problem such as too high of current draw (I believe). But we removed that wire, so it can't send this to the AR Drone mainboard. If you tilt the aircraft too far, it will still have an angle Emergency. If you press Emergency on the screen, it will still stop all the motors.
strangerjle wrote:How do I power the FTDI BREAKOUT BOARD & the ARDUINO BOARD.
The Arduino gets its power from sharing a common ground with the AR Drone's motor wiring, and gets +5v from the white wire of the AR Drone's motor wiring, as showing in the wiring diagram.

pawelsky
Serious flight time
Posts: 1272
Joined: 02 Aug 2012, 22:01
Drone Type: Bebop
Location: Poland
Contact:

Re: $200 prize for whoever can make this mod

Post by pawelsky » 08 Sep 2013, 19:53

Schlauncha wrote:
strangerjle wrote:How do I power the FTDI BREAKOUT BOARD & the ARDUINO BOARD.
The Arduino gets its power from sharing a common ground with the AR Drone's motor wiring, and gets +5v from the white wire of the AR Drone's motor wiring, as showing in the wiring diagram.
The FTDI is powered from the connected PC. BTW everything is on the diagram.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests