Hi,

I want to send sensor data as a ROS message by implementing ROSSerial on XDK and need to implement two simple functions for reading and writing a byte: read() and write() function, as described here:

As described in the XDK_Guide_USB.pdf I would like to use USB_transmit() and USB_receive() as well as implenting the USB interrupt mechanism.

However, the documentation seems not to be up to date.

Neither the names of the header files ...

USB_ih.h
URU_usbResetUtility.h

mentioned in "Code 1", nor the functions USB_init(&USBinit) and URU_init(), as shown in "Code 2" exist in XDK_3.3.1. First I thought, that those functions have moved to a different header/source (BCSD_USB.h seemed promising) but I could not find the function URU_init() anywere.

Could you support how to write USB transmit and receive functions as described in the XDK_Guide_USB.pdf with the native functions USB_transmit() and USB_receive() ?

 

Using printf and scanf is probably not what I need,  as ROS-messages are serialized and need not be ASCI-encoded.

 

Thank you.

0 (0 투표)
RE: ROSSerial on XDK - USB communication (receive and transmit)
응답
18. 3. 27 오후 2:14 as a reply to Jan Staschulat.

Hi,

 

I tried some things out, and used the

USB_init( &USBinit, (USB_rxCallback) USB_CallbackIsr);

function to initialize the callback. Is that okay, or should I rather use the following method?

 

USB_returnCode_t USB_callBackMapping(USB_rxCallback usbcallback);

(both in BCDS_USB.h)

Anything else I should consider?

Here is the code (taken from XDK_Guide_USB.pdf)

// Code 6, XDK_Guide_USB.pdf
#define USB_ENABLE_FLAG                UINT8_C(1)
#define USB_DISABLE_FLAG            UINT8_C(0)
#define USB_RECEIVE_BUFFER_LENGTH    UINT8_C(20)

static volatile uint8_t interruptHandler = USB_ENABLE_FLAG;
static char             receivedData[USB_RECEIVE_BUFFER_LENGTH];

/* Place the following code above usbInterruptHandling() */
static void reSendIncomingData(uint8_t *usbRcvBuffer, uint16_t count){
    char * outputText = "XDK received following data: ";
    char * endingTag = "\n\r";
    uint32_t textLength = strlen(outputText);
    uint32_t endingLength = strlen(endingTag);
    USB_transmitData((uint8_t*)outputText, textLength);
    USB_transmitData((uint8_t*)usbRcvBuffer, count);
    USB_transmitData((uint8_t*)endingTag, endingLength);
}

/* Place the following code above USB_CallbackIsr() */
static void usbInterruptHandling(void *callBackParam1, uint32_t count){
    /* do something with receivedData and count */
    reSendIncomingData((uint8_t*)receivedData, count);
    /* re-enable the usb interrupt flag*/
    interruptHandler = USB_ENABLE_FLAG;
}

/* Place the following code above initReceiveDataISR() */
extern void USB_CallbackIsr(uint8_t *usbRcvBuffer, uint16_t count)
{
    portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
    if (USB_ENABLE_FLAG == interruptHandler){
        interruptHandler = USB_DISABLE_FLAG;
        if(USB_RECEIVE_BUFFER_LENGTH > count){
            memcpy(receivedData, usbRcvBuffer, count);
            receivedData[count] = (char) 0;
            /* add to timer queue*/
            if(xTimerPendFunctionCallFromISR(usbInterruptHandling,
                    NULL, count, &xHigherPriorityTaskWoken)==pdPASS){
                portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
            }
            else{
                assert(0);
            }
        }
    }
}

/* Place the following code above appInitSystem() */
/*
static void initReceiveDataISR(){
URU_registerApplicationISR((URU_usbAppCallback) USB_CallbackIsr);
}
*/

/*Application Command Processor Instance */

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    AppCmdProcessorHandle = (CmdProcessor_T *) CmdProcessorHandle;
    BCDS_UNUSED(param2);
    Retcode_T returnValue = RETCODE_OK;

    //initialize USB
    USB_lineCoding_t USBinit = {
    .Baudrate = 19200,
    .dataBits = 8,
    .charFormat = 0,
    .parityType = 0,
    .dummy = 0,
    .usbRxCallback = NULL};

    CMU_ClockEnable(cmuClock_USB,true);
    USB_init( &USBinit, (USB_rxCallback) USB_CallbackIsr);

    // some other code

}

0 (0 투표)
RE: ROSSerial on XDK - USB communication (receive and transmit)
응답
18. 3. 27 오후 2:35 as a reply to Jan Staschulat.
Hello Jan,

the link you provided for the USB guide points to an older version of the USB guide. That guide is a little more than a year old, and is not applicable in XDK-Workbench version 3.x.x.

Please head over to the XDK Learning Section and download the current USB Guide there. The interface and code examples are up to date there.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 투표)
RE: ROSSerial on XDK - USB communication (receive and transmit)
응답
19. 8. 3 오전 2:58 as a reply to Alexander Sawtschuk.

Hello Jan,

I wanted to make XDK110 communicate with ROS like you, and worked through another approach. Like the one used by the https://github.com/KristofRobot/razor_imu_9dof

I have written a simple firmware for output IMU data in an ordered way: https://github.com/Lince-Facens/Xdk110RosSerial/blob/master/README.md

And written a ROS driver for publishing the messages: https://github.com/Lince-Facens/xdk110_ros

It lacks supports of all the other sensors, but it is a start. Feel free to modify and send pull requests, if you want it.

Best,

Emanuel Huber.

+1 (1 투표)