UAV Control via UAVObject
« on: July 09, 2016, 05:57:06 pm »
I've written C code that communicates UAVObjects with a Revolution board over serial. I'm trying to send control stick values to the board without using DSM, SRXL, PWM, etc. by just sending formatted UAVObjects via the UAVTalk protocol over the serial USBTelemetry connection. I know the read / write code works as I can read 45 different objects that actively poll from the hardware, as well as successfully perform a handshake using the GCSTelemetryStats and FlightTelemetryStats objects.

However, I've tried setting the Roll, Pitch, Yaw, Thrust values on the UAVObjects RateDesired, ActuatorDesired, StabilizationDesired, ManualControlCommand, but the values I set on the objects seem to be ignored, because none of the objects that are sent back reflect the changed values. Is it possible to send control stick values in this way and have the hardware reflect them as if they were sent from a controller using DSM, PWM, etc? I'm sending messages like this:

Code: [Select]
void VXTelemetrySetControlState(VXTelemetryRef this, VXControlState controlState) {
    VXLockAcquire(this->sensorLock);
    this->controlState = controlState;
    VXLockRelinquish(this->sensorLock);
    VXTelemetryRaiseSensorChanged(this, VXTelemetrySensorValueControlState);
   
    StabilizationDesiredData stabilizationDesiredData;
    stabilizationDesiredData.Roll = controlState.roll * 180.0;
    stabilizationDesiredData.Pitch = controlState.pitch * 180.0;
    stabilizationDesiredData.Yaw = controlState.yaw * 180.0;
    stabilizationDesiredData.Thrust = controlState.altitude * 100.0;
    stabilizationDesiredData.StabilizationMode.Roll = STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE;
    stabilizationDesiredData.StabilizationMode.Pitch = STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE;
    stabilizationDesiredData.StabilizationMode.Yaw = STABILIZATIONDESIRED_STABILIZATIONMODE_AXISLOCK;
    stabilizationDesiredData.StabilizationMode.Pitch = STABILIZATIONDESIRED_STABILIZATIONMODE_MANUAL;
    VXTelemetryEnqueueWriteObjectMessage(this, MESSAGE_OBJ, STABILIZATIONDESIRED_OBJID, 0, &stabilizationDesiredData);
}


Brian

  • *
  • 118
Re: UAV Control via UAVObject
« Reply #1 on: July 09, 2016, 09:22:56 pm »
You don't want to be changing those.  You want to send GCSReceiver objects.  That's what GCSReceiver is intended for.

Just set it with values similar to PPM values (typically 1000-2000 uS), and configure your inputs as GCSReceiver.

Re: UAV Control via UAVObject
« Reply #2 on: July 12, 2016, 07:59:20 pm »
These are working great now. Thanks!

marvin

  • *
  • 7
Re: UAV Control via UAVObject
« Reply #3 on: August 17, 2016, 01:45:10 pm »
These are working great now. Thanks!
HI JAMANTA. I also wanna to send  control stick values to the board. But I am a newbie to the librepilot. Can you tell me how to send GCSReceiver objects? is there any example code or how to find the related source code in the librepilot? than you very much.

Re: UAV Control via UAVObject
« Reply #4 on: August 29, 2016, 08:27:42 pm »
Sure. You will first want to read this description about UAVTalk to see the data format:
https://librepilot.atlassian.net/wiki/display/LPDOC/UavTalk

It is a sync byte followed by a message type byte, length in 2 bytes, object id in 4 bytes, instance id in 2 bytes, optional timestamp (based on message type), data, and 16-bit cyclic redundancy check.

You first open a device descriptor to the place the flight controller is attached using an open() call, then use a write() call to send bytes to the flight controller. Then send a formatted set of bytes representing the GCSReceiver object.

If you set up your flight controller to use "GCS" as the channel source for Thrust, Yaw, Pitch, Roll, and Arming, you fill out the structure like this (controlState is just a structure with 4 floats in it ranging from 0 to 1 and armed is a bool):

Code: [Select]
    GCSReceiverData gcsReceiverData;
    memset(&gcsReceiverData, 0, sizeof(gcsReceiverData));
    gcsReceiverData.Channel[0] = fmax(0.0, controlState.altitude) * 1000.0 + 1000.0;    // Throttle     ( 0.0 -> 1.0) -> (1000 -> 2000)
    gcsReceiverData.Channel[1] = (controlState.roll + 1.0) * 0.5 * 1000.0 + 1000.0;     // Roll         (-1.0 -> 1.0) -> (1000 -> 2000)
    gcsReceiverData.Channel[2] = (controlState.pitch + 1.0) * 0.5 * 1000.0 + 1000.0;    // Pitch        (-1.0 -> 1.0) -> (1000 -> 2000)
    gcsReceiverData.Channel[3] = (controlState.yaw + 1.0) * 0.5 * 1000.0 + 1000.0;      // Yaw          (-1.0 -> 1.0) -> (1000 -> 2000)
    gcsReceiverData.Channel[4] = 1000;                                                  // Flight mode
    gcsReceiverData.Channel[5] = armed ? 2000 : 1000;                           // Accessory0
    gcsReceiverData.Channel[6] = 1000;                                                  // Accessory1
    gcsReceiverData.Channel[7] = 1000;                                                  // Accessory2

Then you send this structure as the "data" part of the UAVTalk message. The actual message is filled out as:
Sync Byte: 0x3C
Message Type: 0x20
Length: 16 bytes for "data" + 10 bytes for header = 26
Object Identifier: Depends on your version of LibrePilot. Mine is: 0xCC7E1470
Instance Identifier: 0
No timestamp (message type is 0x20)
Data: As above
CRC: Calculate from the above fields as a 16-bit CRC (see Wikipedia on these if you haven't made one before)

I'd just send you code, but mine has become quite complex at this point to support other features. Good luck!

marvin

  • *
  • 7
Re: UAV Control via UAVObject
« Reply #5 on: September 02, 2016, 07:38:59 am »
JAMANTA, Thank you very much. It is really helpful to me.

gon

  • *
  • 30
Re: UAV Control via UAVObject
« Reply #6 on: April 05, 2017, 08:00:32 pm »
Hi JAMANTA,

I would like to know what steps are needed to make the GCSReceiver usable. You say something about setting GCS as the channel source. Is it under Settings -> ManualControlSettings -> Channel groups?

If I change one of those fields, the Drone becomes disarmed and I don't know how to arm it again to use the GCSReceiver then. What is that "arming" channel you said? Also, when I change one of them, the RC seems to be disconnected, even if I only change "Throttle", the FlightModeSwitch becomes ignored nor updated.

Thanks!