DC motor mixer

Post date: Jul 14, 2015 5:40:47 AM

The stick neutral zone:

From my previous code i notice that the 4 pot got different neutral value and that the noise of each pot is different.

So i wrote a little code to serial print the analog value of each pot for more than a minute at 9600 bps and then import it to excel to determine the maximal and minimal value for the neutral zone for each potentiometer.

Here is the result:

From this table i can estimate what is the neutral value and range of each pot.

It appear that the pitch potentiometer is a bit noisy at neutral position with a differential of 108.

So my neutral zone for each pot is going to be the avg value of each pot -55 for the negative value and the avg value of each pot +55

I wrote a code to control:

motor1 and motor2 on Pitch pot value with Pitch <453 then Motor a reversed and motor sped is (analogValuePitch - 512)/2 if pots value >563

and (511 analogValuePitch)/2 if pot value<453

motor3 and motor4 on Thrust pot value with Thrust <454 then Motor a reversed and motor sped is (analogValueThrust - 512)/2 if pots value >564

and (511 - analogValuePitch)/2 if pot value<454

/* Connections: * BOARD -> ARDUINO

* 1A -> 2

* 1B -> 4

* E1 -> 3

* 2A -> 7

* 2B -> 8

* E2 -> 5

* 3A -> 6

* 3B -> 10

* 3E -> 11

* 4A -> 13

* 4B -> 12

* 4E -> 9

* Yaw -> A0

* Pitch -> A3

* Roll -> A2

* Thrust -> A1

##############################################################################*/

// Define constants and variablesconst int DirM1a = 2;

Conclusion: It work!!!

const int DirM1b = 4;const int Motor1 = 3;const int DirM2a = 7;const int DirM2b = 8;const int Motor2 = 5;const int DirM3a = 6;const int DirM3b = 10;const int Motor3 = 11;const int DirM4a = 13;const int DirM4b = 12;const int Motor4 = 9;const int Yaw = A0; const int Roll = A2; const int Pitch= A3; const int Thrust = A1; int analogValueYaw = 0; int analogValueRoll = 0; int analogValuePitch = 0;int analogValueThrust = 0;byte pwmMotor1 = 0;byte pwmMotor2 = 0;byte pwmMotor3 = 0;byte pwmMotor4 = 0;// Initializationvoid setup() { pinMode(DirM1a, OUTPUT); pinMode(DirM1b, OUTPUT); pinMode(Motor1, OUTPUT); pinMode(DirM2a, OUTPUT); pinMode(DirM2b, OUTPUT); pinMode(Motor2, OUTPUT); pinMode(DirM3a, OUTPUT); pinMode(DirM3b, OUTPUT); pinMode(Motor3, OUTPUT); pinMode(DirM4a, OUTPUT); pinMode(DirM4b, OUTPUT); pinMode(Motor4, OUTPUT); }// main loopvoid loop() { // read potentiometers values analogValueYaw = analogRead(Yaw); analogValueRoll = analogRead(Roll); analogValuePitch = analogRead(Pitch); analogValueThrust = analogRead(Thrust); // apply direction adjustment for Pitch if(analogValuePitch > 563) { digitalWrite(DirM1a, HIGH); // Motor direction are reversed between M1 and M2 both forward digitalWrite(DirM1b, LOW); digitalWrite(DirM2a,LOW); digitalWrite (DirM2b,HIGH); pwmMotor1 = (analogValuePitch - 512)/2; // evaluate new pwm value pwmMotor2 = (analogValuePitch - 512)/2; } else if (analogValuePitch < 453) { digitalWrite(DirM1a, LOW);// Motor direction are reversed between M1 and M2 both backward

The motors stop when the sticks are in neutral zone and the props are free to run, no more buzz sound on the motors when stopped.

The motors sped increase or decrease according to the pot values and the motor rotation direction shift when passing the neutral zone.

Remarque: The Pitch pot is not only noisy it seem not to be mechanically centered. I need to push it a bit on the left to reach the maximal value.

Now t's time to work on the mixer/

DC motors mixer:

This is the mixer table corresponding to each stick position:

Pitch=M1++ M2++ (forward) or M1-- M2-- (backward)

Thrust= M3++ M4++(Down) or M3-- M4-- (Up)

Yaw= M1++ M2-- (Right) or M1-- M2++ (Left)

Roll= M3++ M4-- (Right) or M3-- M4++ (Left)

Flow chart:

digitalWrite(DirM1b, HIGH); digitalWrite(DirM2a,HIGH); digitalWrite (DirM2b,LOW); pwmMotor1 = (511 - analogValuePitch)/2; // evaluate new pwm value pwmMotor2 = (511 - analogValuePitch)/2; } else { digitalWrite(DirM1a, LOW); //Both Motors are stopped digitalWrite(DirM1b, LOW); digitalWrite(DirM2a,HIGH); digitalWrite (DirM2b,HIGH); pwmMotor1 = 0; // Stop the motors pwmMotor2 = 0; } // apply direction adjustment for Thrust if(analogValueThrust > 564) { digitalWrite(DirM3a, HIGH); // Motor direction are reversed between M1 and M2 both forward digitalWrite(DirM3b, LOW); digitalWrite(DirM4a,LOW); digitalWrite (DirM4b,HIGH); pwmMotor3 = (analogValueThrust - 512)/2; // evaluate new pwm value pwmMotor4 = (analogValueThrust - 512)/2; } else if (analogValueThrust < 454) { digitalWrite(DirM3a, LOW); // Motor direction are reversed between M1 and M2 both backward digitalWrite(DirM3b, HIGH); digitalWrite(DirM4a,HIGH); digitalWrite (DirM4b,LOW); pwmMotor3 = (511 - analogValueThrust)/2; // evaluate new pwm value pwmMotor4 = (511 - analogValueThrust)/2; } else { digitalWrite(DirM3a, LOW); //Both Motors are stopped digitalWrite(DirM3b, LOW); digitalWrite(DirM4a,HIGH); digitalWrite (DirM4b,HIGH); pwmMotor3 = 0; // Stop the motors pwmMotor4 = 0; } // apply speed adjustment analogWrite(Motor1,pwmMotor1); analogWrite(Motor2,pwmMotor2); analogWrite(Motor3,pwmMotor3); analogWrite(Motor4,pwmMotor4);}

Code:

/* Connections: * BOARD -> ARDUINO

* 1A -> 2

* 1B -> 4

* E1 -> 3

* 2A -> 7

* 2B -> 8

* E2 -> 5

* 3A -> 6

* 3B -> 10

* 3E -> 11

* 4A -> 13

* 4B -> 12

* 4E -> 9

* Yaw -> A0

* Pitch -> A3

* Roll -> A2

* Thrust -> A1

##############################################################################*/

// Define constants and variablesconst int DirM1a = 2;const int DirM1b = 4;int tempDirM1a=LOW;int tempDirM1b=LOW;const int Motor1 = 3;const int DirM2a = 7;const int DirM2b = 8;int tempDirM2a=LOW;int tempDirM2b=LOW;const int Motor2 = 5;const int DirM3a = 6;const int DirM3b = 10;int tempDirM3a=LOW;int tempDirM3b=LOW;const int Motor3 = 11;const int DirM4a = 13;const int DirM4b = 12;int tempDirM4a=LOW;int tempDirM4b=LOW;const int Motor4 = 9;const int Yaw = A0; const int Roll = A2; const int Pitch= A3; const int Thrust = A1; int analogValueYaw = 0; int analogValueRoll = 0; int analogValuePitch = 0;int analogValueThrust = 0;byte pwmMotor1 = 0;byte pwmMotor2 = 0;byte pwmMotor3 = 0;byte pwmMotor4 = 0;// Initializationvoid setup() { pinMode(DirM1a, OUTPUT); pinMode(DirM1b, OUTPUT); pinMode(Motor1, OUTPUT); pinMode(DirM2a, OUTPUT); pinMode(DirM2b, OUTPUT); pinMode(Motor2, OUTPUT); pinMode(DirM3a, OUTPUT); pinMode(DirM3b, OUTPUT); pinMode(Motor3, OUTPUT); pinMode(DirM4a, OUTPUT); pinMode(DirM4b, OUTPUT); pinMode(Motor4, OUTPUT); }// main loopvoid loop() { // read potentiometers values analogValueYaw = analogRead(Yaw); analogValueRoll = analogRead(Roll); analogValuePitch = analogRead(Pitch); analogValueThrust = analogRead(Thrust); // apply direction adjustment for Pitch if (analogValuePitch > 563 ) { tempDirM1a= HIGH; tempDirM1b= LOW; tempDirM2a= LOW; tempDirM2b= HIGH; pwmMotor1 = (analogValuePitch - 512)/2; // evaluate new pwm value pwmMotor2 = (analogValuePitch - 512)/2; } else if (analogValuePitch < 453) { tempDirM1a= LOW; tempDirM1b= HIGH; tempDirM2a= HIGH; tempDirM2b= LOW; pwmMotor1 = (511 - analogValuePitch)/2; // evaluate new pwm value pwmMotor2 = (511 - analogValuePitch)/2; } // apply direction adjustment for Thrust if(analogValueThrust > 564) { tempDirM3a= LOW; tempDirM3b= HIGH; tempDirM4a= HIGH; tempDirM4b= LOW; pwmMotor3 = (analogValueThrust - 512)/2; // evaluate new pwm value pwmMotor4 = (analogValueThrust - 512)/2; } else if (analogValueThrust < 454) { tempDirM3a= HIGH; tempDirM3b= LOW; tempDirM4a= LOW; tempDirM4b= HIGH; pwmMotor3 = (511 - analogValueThrust)/2; // evaluate new pwm value pwmMotor4 = (511 - analogValueThrust)/2; } // apply direction adjustment for Yaw if (analogValueYaw > 544 ) { tempDirM1a= LOW; tempDirM1b= HIGH; tempDirM2a= LOW; tempDirM2b= HIGH; pwmMotor1 = (analogValueYaw - 512)/2; // evaluate new pwm value pwmMotor2 = (analogValueYaw - 512)/2; } else if (analogValueYaw < 434) { tempDirM1a= HIGH; tempDirM1b= LOW; tempDirM2a= HIGH; tempDirM2b= LOW; pwmMotor1 = (511 - analogValueYaw)/2; // evaluate new pwm value pwmMotor2 = (511 - analogValueYaw)/2; } // apply direction adjustment for Roll if(analogValueRoll > 543) { tempDirM3a= HIGH; tempDirM3b= LOW; tempDirM4a= HIGH; tempDirM4b= LOW; pwmMotor3 = (analogValueRoll - 512)/2; // evaluate new pwm value pwmMotor4 = (analogValueRoll - 512)/2; } else if (analogValueRoll < 433) { tempDirM3a= LOW; tempDirM3b= HIGH; tempDirM4a= LOW; tempDirM4b= HIGH; pwmMotor3 = (511 - analogValueRoll)/2; // evaluate new pwm value pwmMotor4 = (511 - analogValueRoll)/2; } if ((analogValuePitch <563 && analogValuePitch>453)&&(analogValueYaw<544 && analogValueYaw>434)) { tempDirM1a= HIGH; tempDirM1b= HIGH; tempDirM2a= LOW; tempDirM2b= LOW; pwmMotor1 = 0; // Motor1 and motor2 are freeto run pwmMotor2 = 0; } if ((analogValueThrust <564 && analogValueThrust>454)&&(analogValueRoll<543 && analogValueRoll>433)) { tempDirM3a= HIGH; tempDirM3b= HIGH; tempDirM4a= LOW; tempDirM4b= LOW; pwmMotor3 = 0; // Motor3 and motor4 arestopped and free to run pwmMotor4 = 0; } //apply motor direction digitalWrite(DirM1a, tempDirM1a); digitalWrite(DirM1b, tempDirM1b); digitalWrite(DirM2a,tempDirM2a); digitalWrite (DirM2b,tempDirM2b); digitalWrite(DirM3a, tempDirM3a); digitalWrite(DirM3b, tempDirM3b); digitalWrite(DirM4a,tempDirM4a); digitalWrite (DirM4b,tempDirM4b); // apply speed adjustment analogWrite(Motor1,pwmMotor1); analogWrite(Motor2,pwmMotor2); analogWrite(Motor3,pwmMotor3); analogWrite(Motor4,pwmMotor4); }

Conclusion:

Everything good so far. Engine turn the good direction and speed according to the sticks.

Maybe i should d increase the neutral zone not due to the pot noises but due to the minimal Duty cycle needed to start the DC motor properly otherwise there is no guaranty that the motors are going to start together at the same time. I have to serial print the value to know exactly in what range i should increase the neutral zone.