Controlling CC3D with Arduino
« on: October 04, 2018, 08:12:52 pm »
Hello Guys!

I've got some problems controlling the CC3D with an Arduino Mega 2560
Im using Visual Studio Code with PlatformIO with the library LibrePilotSerial from https://github.com/MarcProe/LibrePilot.arduino
I changed some code in this lib. that it is abled to use HardwareSerial, because of any reason it does not work with SoftwareSerial in my case.

I am using UAVTalk via the Main Port of the CC3D. I am able to receive a MANUALCONTROLCOMMAND_OBJID and I can also configure the Throttle. When I request the same Object again, I am able to see that the value of the float "Throttle" changed. But in the System tab of the GCS Software nothing has changed and the drone is doing nothing.

My configuration:
The Main Port of the CC3D is set to telementry and the Input-types are set to DSM(MainPort), it also works if I set it to GCS. The Rx and Tx Pins are connected to the Mega2560(Serial2) pins. I am using a HC-05 bluetooth-module on the Mega2560(Serial3) pins to send an Integer for my switch-case in the code.

My question:
What do i have to change/do, to give the throttle a value, that the drone lifts up?
 

Code: [Select]
#include <Arduino.h>
#include <LibrePilotSerial.h>
#include <manualcontrolsettings.h>
#include <manualcontrolcommand.h>

LibrePilotSerial lps(&Serial2);
char state = '0';

void setup() {

  lps.serial->begin(9600);

  Serial3.begin(9600);

  Serial.begin(9600);
 
}
 
void loop() {
   
    lps.request(MANUALCONTROLCOMMAND_OBJID);

    if(lps.receive(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr)) {
   
        while(state == '0')
        {
            if(Serial3.available()) {
                state = (char)Serial3.read();
                Serial.println(state);
            }
        }

        switch(state) {
            case '1':
                //Serial.println("State wurde auf 1 gesetzt");
                ManualControlCommandDataUnion.data.Throttle = 0.7;
                lps.send(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200);
                state = '0';
                //Serial.println("State wurde auf 0 zurückgesetzt, warte auf nächste abfrage");
                break;
            case '2':
                //Serial.println("State wurde auf 2 gesetzt");
                ManualControlCommandDataUnion.data.Throttle = -0.2;
                lps.send(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200);
                //Serial.println("State wurde auf 0 zurückgesetzt, warte auf nächste abfrage");
                state = '0';
                break;
        }
    }
}

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Controlling CC3D with Arduino
« Reply #1 on: October 04, 2018, 10:07:18 pm »
Hi,

Prior to increase Throttle you may need to arm the board or the motors cannot start.

This can be achieved using the AccessoryDesired uavo and a Accessory0 configured as arming switch.
You can also do a arming sequence using Yaw left or something similar. (Both options need a negative value of Throttle)

Re: Controlling CC3D with Arduino
« Reply #2 on: October 05, 2018, 08:33:36 pm »
Hi,

thank you for your help. I wrote a simple sequenz to try if I can arm it with Yaw-left. Unfortunately it did not solve the problem. The drone still does not react on my commands.

Enclosed you can find some more screenshots an the code.

Code: [Select]
    char sequence = '0'
    while(sequence != '3')
    {
        if(sequence == '0')
        {
        lps.request(MANUALCONTROLCOMMAND_OBJID);
        if(lps.receive(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200))
            {
                Serial.println("Throttle auf negativ");
                ManualControlCommandDataUnion.data.Throttle = -1.0;
                lps.send(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200);
                sequence = '1';
            }
        }
        lps.request(MANUALCONTROLCOMMAND_OBJID);
        if(sequence == '1')
        {
            if(lps.receive(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200))
            {
                Serial.println("Yaw negativ");
                ManualControlCommandDataUnion.data.Yaw = -1;
                lps.send(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200);
                sequence = '2';
            }
        }
       
        lps.request(MANUALCONTROLCOMMAND_OBJID);
        if(sequence == '2'){
            delay(5000);
            if(lps.receive(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200))
                {
                    Serial.println("Yaw neutral, Throttle neutral");
                    ManualControlCommandDataUnion.data.Yaw = 0.0;
                    ManualControlCommandDataUnion.data.Throttle = 0.0;
                    lps.send(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200);
                    sequence = '3';
                }
            }
    }

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Controlling CC3D with Arduino
« Reply #3 on: October 05, 2018, 11:41:12 pm »
Red alarm (Critical) with INPUT will prevent arming.
Try setting some valid settings in Input tab (like PPM+some channel for all controls + flightmode) and get at least INPUT Orange alarm.


Re: Controlling CC3D with Arduino
« Reply #4 on: October 05, 2018, 11:46:24 pm »
You mean like this?
That also does not help  :(

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Controlling CC3D with Arduino
« Reply #5 on: October 05, 2018, 11:49:49 pm »
Did you set PPM input in Hardware tab and reboot ?
INPUT alarm still Red or is Orange ?

Re: Controlling CC3D with Arduino
« Reply #6 on: October 05, 2018, 11:52:09 pm »
It is still Red. I am using the main port, there is no option for ppm

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Controlling CC3D with Arduino
« Reply #7 on: October 05, 2018, 11:57:14 pm »
Set PPM_Pin8+OneShot for Receiver port or PPM for FlexiPort in Hardware tab and Reboot.

Re: Controlling CC3D with Arduino
« Reply #8 on: October 06, 2018, 12:01:03 am »
If I try to use the Flexi-Port with this configuration, the light change to orange. The new problem is, if I use this configuration, the UAVTalk does not work

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Controlling CC3D with Arduino
« Reply #9 on: October 06, 2018, 12:25:09 am »
I think you may need some code changes in armhandler.c and change the okToArm() behaviour to allow arming with Input alarm.
What GCS version do you use ?

Re: Controlling CC3D with Arduino
« Reply #10 on: October 06, 2018, 12:32:16 am »
Now i moved a step forward ^^
I set the flexi-port to ppm and also the inputs, as you said. The lamp is orange.
I can still use UAVTalk via the main-port.

But the drone still does not arm ^^.

I recognized that in the System-tab I get some values now.


Re: Controlling CC3D with Arduino
« Reply #11 on: October 06, 2018, 02:44:08 am »
I think the UAVTalk objects that I send to the cc3d from my arduino gets ignored.

For example:

If I send an object like bellow and I receive another ManualControlCommand_OBJ, the value changed to 1.

ManualControlCommandDataUnion.data.Throttle = 1;
lps.send(MANUALCONTROLCOMMAND_OBJID, ManualControlCommandDataUnion.arr,200);

But in the GCS System-tab the value is still -1, nothing changed.

Since the alarm lamp changed to orange I am able to arm the drone if I use always armed.
But if I do an arming sequenz in my code, nothing happens.

Do you know what causes the problem?

Re: Controlling CC3D with Arduino
« Reply #12 on: October 06, 2018, 05:20:58 am »
I have not coded things like this before, but I imagine that whatever color the input is, that you have two sources of input that are fighting.  Your Arduino commands may be received, but right after that the normal input overwrites the ManualCommand.

You should read the input code.  I recall that there is a ManualCommandReadOnly() that is used to tell it to avoid reading input and setting ManualCommand:
flight/modules/Receiver/receiver.c:        if (ManualControlCommandReadOnly()) {

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Controlling CC3D with Arduino
« Reply #13 on: October 06, 2018, 11:27:49 am »
ManualCommandReadOnly() do not set something, this is a check function returning the uavo status

You will need something similar to the python example script here to take control of ManualControlCommand.


Re: Controlling CC3D with Arduino
« Reply #14 on: October 06, 2018, 11:43:32 am »
Quote
I have not coded things like this before, but I imagine that whatever color the input is, that you have two sources of input that are fighting.  Your Arduino commands may be received, but right after that the normal input overwrites the ManualCommand.

That could be a possibillity, but why do I receive a changed value when I send and receive the package again, if the other source overrides it?

Quote
You will need something similar to the python example script here to take control of ManualControlCommand.

Is there no other way?