Hey everyone, I am trying to make a flying wing aircraft and sadly because of my small brain not being able to understand the servo mixing stuff, I am not able to get the elevons working like i need it to. Can anyone help me to modify the code so that the servos are reversed in the aileron control and straight in the elevator one?
Thanks in advance to everybody who has taken the time to respond to my question
This is theTX code
#include <SPI.h> // nrf communication
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); //CE CSN
struct channels { //Data to be sent
int ch1 = 0;
int ch2 = 0;
int ch3 = 0;
};
channels ch;
const byte address[6] = "10000"; //address to send data
int x = A0; // potentiometer pins
int x2 = A1;
int y = A2;
int mappedx;
int mappedy;
void setup() {
Serial.begin(9600);
pinMode(x, INPUT);
pinMode(y, INPUT);
pinMode(x2, INPUT);
radio.begin(); //Beginning the radio communication
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening(); //Setting the nrf to transmitter mode
}
void loop() {
ch.ch1 = map(analogRead(x), 550, 1023, 1000, 2000); // mapping the values
ch.ch2=map(analogRead(x2),0,1023,0,180);
ch.ch3=map(analogRead(y),0,1023,0,180);
radio.write(&ch, sizeof(channels)); //Sending the data
Serial.print(ch.ch1);
Serial.print(",");
Serial.println(ch.ch2);
Serial.println(radio.isChipConnected());
}
This is the RX code
#include <ESC.h> //Include the RC ESC library
#include <Servo.h> // Servo library
#include <SPI.h> //nrf communication libraries
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(8, 7); // CE CSN
Servo s1; //Servo 1
Servo s2; //Servo 2
const byte address[6] = "10000"; //address to communicate with the other nrf module
ESC bldc(6, 1000, 2000, 690); // ESC(Pin Number,Maximum value,Minimum value,Arm value)
struct channels { //data to receive
int ch1;
int ch2;
int ch3;
};
channels data;
int servo1;
int servo2;
void setup() {
Serial.begin(9600);
radio.begin(); //Beginning the radio communication
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.startListening(); //Setting the nrf to listen mode
s1.attach(5);//attaching the servos
s2.attach(3);
Serial.println(radio.isChipConnected());//making sure the nrf module is connected
bldc.arm(); //Function to arm the ESC
delay(8000); //Delay to wait for the arming
}
void loop() {
if (radio.available()) {
radio.read(&data, sizeof(channels)); //Reading the data
s1.write(data.ch2); //writing the angles to the servo
s2.write(data.ch3);
}
if (data.ch1 > 1030) {
bldc.speed(data.ch1); //Starting the motor at the instructed speed
} else {
bldc.stop(); //stoping the motor
}
}
Here, The ch1 is for the throttle which is not important and ch2 is for elevator and ch3 for aileron control