I want to make a RC mixer mixing two channels of a receiver.
What I have: a delta model plane, two servos, a receiver and a Arduino Nano.
So I'd like to mix the aileron (two channels) with the elevator(one channel).
EDIT: What I've done: I read the input of the receiver and wrote it to the servos. The problem: The servo stutters and the arduino displays false inputs.
int pin = A0;
int pin1 = A1;
unsigned long duration;
unsigned long dur;
unsigned long duration2;
unsigned long dur2;
#include <Servo.h>
Servo myservo;
Servo myservo2;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
}
void loop()
{
duration = pulseIn(pin, HIGH);
dur = duration;
Serial.println(dur);
myservo.writeMicroseconds(dur);
delay(50);
// duration2 = pulseIn(pin1, HIGH);
// dur2 = duration2-980/4-200;
// Serial.println(dur2);
// myservo2.write(dur2);
}
-
Apparently no access to google?user6569– user65692015年05月13日 13:01:23 +00:00Commented May 13, 2015 at 13:01
-
Can you give me a good instruction how to do that???linuscl– linuscl2015年05月13日 14:01:27 +00:00Commented May 13, 2015 at 14:01
-
"This question does not show any research effort" is a reason for downvoting. Please show us what you tried and how far you got.Joris Groosman– Joris Groosman2015年05月13日 14:30:38 +00:00Commented May 13, 2015 at 14:30
-
That is NOT how we do it. Flying a delta plane should not require anything between the receiver and servos, you just have to program the radio correctly. Almost all the popular RC radios today have built-in delta mixing. The SAFE system planes from E-Flite do the mixing on-board, but it doesn't require any additional hardware.Jasmine– Jasmine2015年05月13日 19:59:30 +00:00Commented May 13, 2015 at 19:59
1 Answer 1
You do not need to use long for values from pulseIn, using int will be sufficient.
Your code is not complete, at least there is a missing '}' at the end of setup.
The slower the baud rate (9600) actually the more it interferes with timing code, to a point. PWM is all timing code. I would suggest 57,600.
You never set the servos to any pins. And is using Servo lib needed? I have always used analogWrite with no problems.
You are not using parenthesis on your math (currently commented). It will not give you the result you expect. But you are somewhat on the right track, subtract 1500 from each pulse read, that will give you -/+ range. How you mix that depends on how your radio is setup (servo reversing, which channel is which). Keep in mind ailerons is 1 channel, so left aileron = -rightAileron. Elevator up = that + elevator. so;
aileronLeft = airleronChannel + elevatorChannel
aileronRight = -airleronChannel + elevatorChannel
You do realize this a 3ドル part?
update: I have always used analogWrite, but I also always use good equipment. I see cautions that cheapo servos might be damaged with analogWrite. You can read more here. It has always worked for me.
-
How to disable the bad stuttering?? :( And can you say me how to use a servo with analogWrite()? Thank you!linuscl– linuscl2015年05月13日 18:03:55 +00:00Commented May 13, 2015 at 18:03