Python Connectionmanager
« on: November 12, 2017, 04:00:39 pm »
Hello everyone,

I'm trying to connect the CC3D to a Raspberry Pi.
I tried the steps explained here: https://forum.librepilot.org/index.php?action=profile;area=showposts;u=4390

First it worked, but after a while it stopped working... Now I can't get it to connect anymore.
I tried to get the newest firmware, but the GCS download is older than the bitbucket one.
Is there a way to get more control of which UAVObjects are used? Or an easy way to get matching firmwares?

Another question is, whether the CC3D needs to be fully set up (e.g. after upgrade and erase)?

Thanks in advance!


Re: Python Connectionmanager
« Reply #1 on: November 12, 2017, 06:37:28 pm »
All versions must match to communicate well.

When you change a UAVO (XML file or header file produced from XML) you must rebuild everything so that it knows the new checksum of the new UAVO.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Python Connectionmanager
« Reply #2 on: November 13, 2017, 10:41:55 am »
Latest Next build is LibrePilot-16.09+r541-g8935906_i686.exe and will match the current bitbucket Next

Re: Python Connectionmanager
« Reply #3 on: November 14, 2017, 03:52:48 am »
Another question is, whether the CC3D needs to be fully set up (e.g. after upgrade and erase)?

The exact definition of that is whether any UAVO (xml source file) setting that you have non-default settings in (as set by GCS) got modified by code changes (in the xml file) from one version to the other version.

If you know for sure where all your non-default settings are (in GCS) you can just look at them to make sure they look correct, for instance, if you see non-default PIDs, you know it got them and you don't need to check each PID individually.

If you do this wrong then you will simply get default settings for the changed UAVOs.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Python Connectionmanager
« Reply #4 on: November 14, 2017, 10:12:43 am »
Quote
Another question is, whether the CC3D needs to be fully set up (e.g. after upgrade and erase)?

If you do a Upgrade&Erase the CC3D will lost the USB VCP setting.
The python code works only using a serial port (connected to Main/Flexi port) or VCP set as USB telemetry.

https://forum.librepilot.org/index.php?topic=749.msg12347#msg12347

Re: Python Connectionmanager
« Reply #5 on: November 21, 2017, 10:48:29 pm »
Thank you very much! Got the System connected now! Now I'm trying to change the ManualControlCommand.Thrust value, but unfortunally it doesn't affect the Motors. My aim is to set the Thrust via USB, is it possible to do so?
Do you have an example for me, if it's possible?

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Python Connectionmanager
« Reply #6 on: November 21, 2017, 10:55:08 pm »
Look the driveServo function inside example.py file.

Board need to be armed first if you want to run motors.

Re: Python Connectionmanager
« Reply #7 on: November 21, 2017, 11:00:56 pm »
Yes, I looked into example.py, and the driveServoFunction works. But I would like to set the Throttle/Thrust value, so the Board keeps in stabilisation mode, rather than controlling every single Motor...

Thanks for the fast reply!

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Python Connectionmanager
« Reply #8 on: November 21, 2017, 11:10:59 pm »
yes, didn't make sense controlling every motor...

Try ManualControlCommand

Re: Python Connectionmanager
« Reply #9 on: November 21, 2017, 11:15:33 pm »
I tried:
Code: [Select]
        self.objMan.ManualControlCommand.metadata.access = UAVMetaDataObject.Access.READONLY
        self.objMan.ManualControlCommand.metadata.updated()
        print "Got it!"
        while True:
            self.objMan.ManualControlCommand.Thrust.value = 0
            self.objMan.ManualControlCommand.updated()
            time.sleep(1)
            print "sleep"
            self.objMan.ManualControlCommand.Thrust.value = 1
            self.objMan.ManualControlCommand.updated()
            time.sleep(1)

But it just doesn't power the Motors... (Thrust should be -1 ; 1)

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Python Connectionmanager
« Reply #10 on: November 21, 2017, 11:27:26 pm »
Is the board Armed ?

Remove propellers !

Re: Python Connectionmanager
« Reply #11 on: November 21, 2017, 11:29:59 pm »
if i do:

Code: [Select]
print self.objMan.FlighStatus.Armed.value

it returns 0 which is unarmed... So maybe there is the Problem...
Is it possible to set this value to armed?

EDIT:

Now armed it via Remote Control, it returns 2, but still the motors don't move... But
Code: [Select]
   self.objMan.ManualControlCommand.metadata.access = UAVMetaDataObject.Access.READONLY seems to work, can't control via remote until reboot
« Last Edit: November 21, 2017, 11:34:55 pm by NXTNiklas »

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Python Connectionmanager
« Reply #12 on: November 21, 2017, 11:38:01 pm »
Set how the board is armed in GCS: Config > Input > Arming settings

At Low Throttle (-1), "move" one stick you choose for arming
Apply Throttle.
Board will still Armed or disarm after a timeout if Throttle returns to -1

Re: Python Connectionmanager
« Reply #13 on: November 21, 2017, 11:54:58 pm »
Tried to do what you said:

Code: [Select]
def driveServo(self):
        print "Taking control of self.actuatorCmd"
        self.objMan.ActuatorCommand.metadata.access = UAVMetaDataObject.Access.READONLY
        self.objMan.ActuatorCommand.metadata.updated()
        self.objMan.ManualControlCommand.metadata.access = UAVMetaDataObject.Access.READONLY
        self.objMan.ManualControlCommand.metadata.updated()
        print "Got it!"
        print "starting Arming:"
        self.objMan.ManualControlCommand.Throttle.value = -1
        self.objMan.ManualControlCommand.updated()
        self.objMan.ManualControlCommand.Pitch.value = -1
        self.objMan.ManualControlCommand.updated()
        self.objMan.ManualControlCommand.Throttle.value = 1
        self.objMan.ManualControlCommand.updated()

        time.sleep(1)
        while True:
            print self.objMan.FlightStatus.Armed.value
            self.objMan.ManualControlCommand.Throttle = 1
            self.objMan.ManualControlCommand.updated()
            time.sleep(1)
            print "sleep"
            self.objMan.ManualControlCommand.Thrust.value = 1
            self.objMan.ManualControlCommand.updated()
            time.sleep(1)



(Arming Settings: Pitch forward) Arming doesn't work... I don't know why :/

Could it be, that there is a problem with failsafe settings? Because I don't use a Remote Control...
« Last Edit: November 22, 2017, 04:40:59 pm by NXTNiklas »

Re: Python Connectionmanager
« Reply #14 on: November 22, 2017, 04:46:50 pm »
Okay, I tried something else:
When i remove
Code: [Select]
self.objMan.ManualControlCommand.metadata.access = UAVMetaDataObject.Access.READONLY
the motors start to move a little...

The values get erased immediatly
« Last Edit: November 22, 2017, 06:41:43 pm by NXTNiklas »