Autopilot system for a RC helicopter. Part 2: Takeover

    This is a continuation of the article on the development of an autopilot system for a radio-controlled helicopter.

    Since I have no plan to build a full-fledged UAV, for the most part this is still a manually controlled helicopter, and I will not completely remove the receiver from it. Therefore, you need to somehow implement the communication between the Arduino, the radio and the engine controller.

    First of all, I decided to figure out how the receiver communicates with the controller. Once the servos are connected to the receiver as well as the controller, then the principle of controlling the motors is the same as the servos, which are based on PWM.

    Then I decided to try to read the values ​​from the outputs of the receiver.

    Pin arrangement on receiver and motor controller: 1-GND, 2-VCC, 3-signal.

    image

    To do this, connect the receiver signal outputs (there are 4 in all, the top 2 are servos, the next 2 are for motor control) to the Arduino pin 5,6,7,8, one of the VCC inputs to 5v Arduino, and one of the GND inputs to GND arduino . Using the pulseIn () function, which reads the signal length at a given input, we get the values ​​produced by the receiver. By maximally deflecting the levers on the control panel, I fixed the values ​​I needed. These are values ​​from 1080 to 1800, and the values ​​displayed when the handles are in normal condition for roll, pitch and course are 1450, and for gas - 1080.

    image

    The sketch is quite simple:

    int c1;
    int c2;
    int c3;
    int c4;
    void setup() {
      pinMode(5, INPUT); 
      pinMode(6, INPUT);
      pinMode(7, INPUT);
      pinMode(8,INPUT);
      Serial.begin(9600); 
    }
    void loop() {
      c1 = pulseIn(5, HIGH, 25000);
      c2 = pulseIn(6, HIGH, 25000);
      c3 = pulseIn(7, HIGH, 25000);
      c4 = pulseIn(8, HIGH, 25000);
      Serial.print("C1:"); 
      Serial.println(c1);   
      Serial.print("C2:");
      Serial.println(c2);
      Serial.print("C3:");
      Serial.println(c3);
      Serial.print("C4:");
      Serial.println(c4);
    }
    


    Well, actually it would seem that everything can already be transferred to Arduino? We now connect the motor controller (Arduino pin 5 and 6) and the servos (Arduino pin 7 and 8) with the Arduino and write another sketch:

    #include  
    Servo right;
    Servo left;
    Servo rightmot;
    Servo nizmot;
    int rightmot_pin = 5;  
    int nizmot_pin = 6;
    int serv_left_pin=7;
    int serv_right_pin=8;
    int js_position = 800;
    int max_position = 3000;
    int spd1_now;
    void setup() 
    {
      left.attach(serv_left_pin, js_position, max_position);    
      right.attach(serv_right_pin, js_position, max_position); 
     rightmot.attach(rightmot_pin, js_position, max_position);   
        nizmot.attach(nizmot_pin, js_position, max_position);    
    } 
    void loop() 
    {
    for(int i=1080,j=1800;i<1800,j>1080;i++,j--)
    {
    left.write(i);
    right.write(j);
    }
    for(int j=1800,i=1080;j>1080,i<1800;j--,i++)
    {
    left.write(j);
    right.write(i);
    }
    }
    

    Fill it, wait, and here the problems begin. Firstly, for a long time I had to puzzle over why the controller turns on, but cannot calibrate and start working. After half an hour, I found a solution: the problem was that it turns on and blinks at any voltage, but it starts to work only when using a battery with a minimum voltage of 7.4 volts. In general, it even benefited, Arduino eats very well and works from the battery through the controller, and you won’t have to put one battery on the control and another on the motor controller (Usually, the controller has a powerful battery with a large capacity and voltage of 11.1V, and managing a small battery (850 mAh) and voltage 7.4V).

    We connect the battery, try again. Again just blinking. It took about 3 to solve this problem. It turns out that for the controller to work, it needs to somehow interact with the receiver when it is turned on. How exactly, I have not yet been able to find out, maybe the receiver sends some special values ​​to it. To solve this, we also connect the receiver to the Arduino (Arduino pin 9,10,11,12), read the values ​​coming from the remote control from it, and transfer them to the controller:

    #include  
    Servo right;
    Servo left;
    Servo rightmot;
    Servo nizmot;
    int rightmot_pin = 5;  
    int nizmot_pin = 6;
    int serv_left_pin=7;
    int serv_right_pin=8;
    int js_position = 800;
    int max_position = 3000;
    int c1;
    int c2;
    int c3;
    int c4;
    int spd1_now;
    void setup() 
    {
     pinMode(9, INPUT); 
      pinMode(10, INPUT);
      pinMode(11, INPUT);
      pinMode(12,INPUT);
      left.attach(serv_left_pin, js_position, max_position);    
      right.attach(serv_right_pin, js_position, max_position); 
     rightmot.attach(rightmot_pin, js_position, max_position);   
        nizmot.attach(nizmot_pin, js_position, max_position);    
    } 
    void loop() 
    {
      c1 = pulseIn(5, HIGH, 25000);
      nizmot.write(c1);
      c2 = pulseIn(6, HIGH, 25000);
      rightmot.write(c2);
      c3 = pulseIn(7, HIGH, 25000);
      left.write(c3);
      c4 = pulseIn(8, HIGH, 25000);
      right.write(4);
    }
    


    Fill, connect, works!

    Now the receiver is connected to the controller via Arduino, which intercepts the signal and sends it to the desired channel of the controller. Even despite the fact that the signal changes (usually the value decreases by 15-20 units), the helicopter even turns up into the air.

    Now we add the button to Arduino, when it is clamped, automatic control is turned on.

    Sketch:

    #include  
    Servo right;
    const int SEL = 2; // digital
    Servo left;
    Servo rightmot;
    Servo nizmot;
    int rightmot_pin = 5;  
    int nizmot_pin = 6;
    int serv_left_pin=7;
    int serv_right_pin=8;
    int js_position = 800;
    int max_position = 3000;
    int c1;
    int c2;
    int c3;
    int c4;
    int spd1_now;
    void setup() 
    {
      pinMode(SEL,INPUT);
      digitalWrite(SEL,HIGH);
     pinMode(9, INPUT); 
      pinMode(10, INPUT);
      pinMode(11, INPUT);
      pinMode(12,INPUT);
      left.attach(serv_left_pin, js_position, max_position);    
      right.attach(serv_right_pin, js_position, max_position); 
     rightmot.attach(rightmot_pin, js_position, max_position);   
        nizmot.attach(nizmot_pin, js_position, max_position);    
    } 
    void loop() 
    { 
     if(SEL == HIGH)
    {
      c1 = pulseIn(5, HIGH, 25000);
      nizmot.write(c1);
      c2 = pulseIn(6, HIGH, 25000);
      rightmot.write(c2);
      c3 = pulseIn(7, HIGH, 25000);
      left.write(c3);
      c4 = pulseIn(8, HIGH, 25000);
      right.write(4);
    }
    else
    {
    for(int i=1080,j=1800;i<1800,j>1080;i++,j--)
    {
    left.write(i);
    right.write(j);
    }
    for(int j=1800,i=1080;j>1080,i<1800;j--,i++)
    {
    left.write(j);
    right.write(i);
    }
    }
    }
    

    To transfer control to the Arduino, you need to connect the battery, wait until the indicator on the controller starts to light constantly, and then you can, in principle, even turn off the receiver, as after initialization, the controller may already work without a receiver.

    In this example, using the cycle (for a smooth servo), the angle of inclination of the blades is changed. In the future, the helicopter will be controlled in flight in the same way.

    Demonstration of work:


    Also popular now: