Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #15 on: December 06, 2017, 09:04:02 pm »
I am not an expert in this area but there are several places where ManualControlCommand gets set, and if you don't disable those in the firmware or with some setup, your values may be overwritten.

I would suggest you search the firmware source code for places where ManualControlCommand gets set and examine the statements.

The code tries to be safe, and that means that things have to be configured correctly for flight for ManualControlCommand values to be used to actually run the motors.  Being configured correctly means that ManualControlCommand is already getting values from somewhere else.

My initial thought about this is that I would have the Pi pretend it is an RC receiver and send some simple protocol (PPM, SBUS, etc.) to the FC receiver input.  Each protocol has pluses and minuses.  PPM is simple, but requires precise timing (is there a driver for PPM for RPi?)  SBus is a serial protocol, but needs to be inverted in hardware (next has an option to skip the inversion).  Maybe send telemetry packets like you are a GCS with a joystick.  Maybe someone else can suggest other ways.
« Last Edit: December 06, 2017, 09:08:01 pm by TheOtherCliff »

Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #16 on: December 09, 2017, 09:56:39 am »
Hi theOtherCliff,

Thank you for your reply. I am going to investigate where the ManuelControlCommnad is used and how it is configured. If there is someone else who knows how the settup the input it would be great.

About your suggestion to pretend it is an RC receiver. We have already tried that. We have had the PPM working, but we didn't get the timing stable with a software only. We didn't know about the Sbus option, can you tell me more about that option?

Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #17 on: December 09, 2017, 08:13:19 pm »
SBus is a Futaba protocol that can be implemented with simple serial transmit functions.  The problem is that the signal polarity is actually backwards at the hardware level.  That needs a simple hardware inverter, or disable the hardware inverter on the CC3D (hardware mod or simple change to firmware), or use the unreleased development version called "next" (you usually want to build it yourself) because it has an option to do the non-inverted SBus.

You could look at the LP code to see how SBus is decoded and make a matching encoder for your project, or find an SBus (S.Bus) protocol description on the internet somewhere.

To make a hardware change to skip inverting the SBus, look at the schematic, find the external inverter chip connected to MainPort, note that a signal line tells it whether to invert it or not, cut the line, permanently tie the line high or low, I don't know which without doing this research.

I would guess that someone has written an RPi driver to do PPM accurately, but it would require driver privileges and interrupts/DMA, not application privileges and bit banging.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #18 on: December 09, 2017, 08:49:08 pm »
Here is a example where the Python script take control over RC inputs.
At the beginning and end the sticks move according to Rc radio.



Code is here
Hope this helps.

sallyc

  • *
  • 47
Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #19 on: December 14, 2017, 12:26:32 pm »
The range is [-1,1], but everything from [-1,0] is throttle off, maps to -1.

Beware of exactly zero, I recall that it is throttle off, but maps to 0 where negative values all map to -1.  This may no longer be true.
Hello TheOtherCliff,
I see in ManualControlCommand, the range is [-1,1], but in AttitudeState, the unit is degree. How can I map them?

sallyc

  • *
  • 47
Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #20 on: December 14, 2017, 03:54:30 pm »
Here is a example where the Python script take control over RC inputs.
At the beginning and end the sticks move according to Rc radio.



Code is here
Hope this helps.
How can I do this while code running on pi and GCS running on computer?

Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #21 on: December 14, 2017, 04:43:20 pm »
Stabilization->Basic->Bank#->Attitude is the maximum bank angle in degrees in Attitude mode.

By default it is 55, so [-1.0f,1.0f] corresponds to [-55.0f,55.0f].

You could go through the hassle of reading the StabilizationSettingsBank# .RollMax .PitchMax (.YawMax) or set these to what you need and assume they are the value you set.

A note here.  See the .YawMax?  It is almost never used, but you can actually set yaw to Attitude mode and set this to maybe 180.

If I recall correctly, ManualControlCommand feeds StabilizationDesired and StabilizationDesired is scaled in degrees for Attitude mode or degrees per second for Rate mode.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #22 on: December 14, 2017, 09:05:00 pm »
Quote
How can I do this while code running on pi and GCS running on computer?
This is done connecting GCS to USB and python using a USBSerial connected to MainPort.
Not sure a CC3D can handle this at same time.

sallyc

  • *
  • 47
Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #23 on: December 14, 2017, 10:20:59 pm »
Stabilization->Basic->Bank#->Attitude is the maximum bank angle in degrees in Attitude mode.

By default it is 55, so [-1.0f,1.0f] corresponds to [-55.0f,55.0f].

You could go through the hassle of reading the StabilizationSettingsBank# .RollMax .PitchMax (.YawMax) or set these to what you need and assume they are the value you set.

A note here.  See the .YawMax?  It is almost never used, but you can actually set yaw to Attitude mode and set this to maybe 180.

If I recall correctly, ManualControlCommand feeds StabilizationDesired and StabilizationDesired is scaled in degrees for Attitude mode or degrees per second for Rate mode.
Sorry i don't understand, i wanna to map the attitudeState to [-1,1], so that i can give ManualControlCommand correct to the controller.

Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #24 on: December 15, 2017, 01:26:42 am »
AttitudeState .Roll .Pitch .Yaw are in degrees

I recall that roll is +-180, pitch is +-90, and yaw is +-180

Or use the quaternion q1:q2:q3:q4 which will be in radians

Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #25 on: December 18, 2017, 03:28:56 pm »
Here is a example where the Python script take control over RC inputs.
At the beginning and end the sticks move according to Rc radio.



Code is here
Hope this helps.
Thanks for the example! I tried it and it runs without errors, but the motors doesn't move.... I don't understand why it doesn't, the board gets armed through your program..

EDIT: Sorry my fault! I just didn't set the thrust value high enough! Thanks it works!
« Last Edit: December 18, 2017, 03:48:51 pm by NXTNiklas »

sallyc

  • *
  • 47
Re: Low level (Attitude mode) stabilization on the CC3D and navigation in Pi
« Reply #26 on: January 09, 2018, 08:22:51 pm »
Here is a example where the Python script take control over RC inputs.
At the beginning and end the sticks move according to Rc radio.



Code is here
Hope this helps.

Hi,
here is my code, i only chance something in driveServo.
I get AttitudeState and AccelState and sensor data(I added myself), and use then to be the inputs of a function, getting the outputs of this function and give to ManualControlCommand.
I want it to run in a rate of 50HZ, but i dont know how to achieve that. can anyone help me?
also, the sensor stops sensor after a while here but in the example code it continue sensing.