Wireless data transfer

Hi,
I’m currently working on a projekt where I want to controll the movements of three 3pi (equipped with wixels) from my computer also connected to a wixel.

Its kind of the reverse from the example wireless_tilt_mouse example with the difference that the wixel connected to the computer does the sending.

But when I try to use the wireless_tilt_mouse app with the modification that the sender and receiver changes the status of the red light every time they send/receive data.

The problem is that the sender keeps swithching the led (ie sending) while the receiver doesn’t change at all.

I thought the radioQueueRxDoneWithPacket(); had to be excecuted at the receiving end before the sender was done with the data transmition, is this incorrect?

Anybody have any ideas why there seems to be no data incomming to the receiving end and why the sender keeps sending even if nothing is received?

the code i use for the sender is:

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <usb_hid_constants.h>
#include <radio_queue.h>
#include <math.h>

#define TX_INTERVAL 1000 // time between transmissions (ms)

int32 CODE param_invert_x = 0;
int32 CODE param_invert_y = 0;
int32 CODE param_speed = 100;


void updateLeds()
{
    usbShowStatusWithGreenLed();
    LED_YELLOW(vinPowerPresent());
}

void txMouseState()
{
    uint8 XDATA * txBuf;
    static uint32 lastTx = 0;

    if ((uint32)(getMs() - lastTx) > TX_INTERVAL && (txBuf = radioQueueTxCurrentPacket()))
    {
        float fx, fy, multiplier;
        int8 x, y;

        fx = -((float)adcRead(2 | ADC_BITS_12) - 1024) / 128;  // fx = Acceleration in X direction (floating point)
        fy =  ((float)adcRead(1 | ADC_BITS_12) - 1024) / 128;  // fy = Acceleration in Y direction
        multiplier = sqrtf(fx * fx + fy * fy) * param_speed/100;

        // Compute the x and y mouse change values to send.
        x = (int8)(fx * multiplier);
        y = (int8)(fy * multiplier);
        if (param_invert_x){ x = -x; }
        if (param_invert_y){ y = -y; }

        // Construct a packet and transmit it on the radio.
        txBuf[0] = 3;  // Packet length in bytes.
        txBuf[1] = 1;
        txBuf[2] = 1;
        txBuf[3] = 0;
        radioQueueTxSendPacket();

        LED_RED(!LED_RED_STATE);
        lastTx = getMs();
    }
}

void main()
{
    systemInit();
    usbInit();

    radioQueueInit();

    // disable pull-ups on accelerometer outputs
    setDigitalInput(1, HIGH_IMPEDANCE);
    setDigitalInput(2, HIGH_IMPEDANCE);

    while(1)
    {
        updateLeds();
        boardService();
        usbComService();

        txMouseState();

    }
}

The code for the receiver:

#include <wixel.h>
#include <usb.h>
#include <usb_hid.h>
#include <radio_queue.h>

void updateLeds()
{
    usbShowStatusWithGreenLed();
}

void rxMouseState(void)
{
    uint8 XDATA * rxBuf;

    if (rxBuf = radioQueueRxCurrentPacket())
    {

        radioQueueRxDoneWithPacket();
        if((uint32)getMs()%500==0){ // atmost every 0.5s wouldnt notice if blinking/receiveing was to fast.
        	LED_RED(!LED_RED_STATE);
        }

    }
}

void main()
{
    systemInit();
    usbInit();

    radioQueueInit();

    while(1)
    {
        updateLeds();
        boardService();
        //usbHidService();

        rxMouseState();
    }
}

Thankfull for any help I can get!

/Simon Larson

Hello, Simon.

I think the receiver isn’t blinking its red LED because this condition is usually false:

if((uint32)getMs()%500==0){

I would just remove that condition.

But also I have a suggestion for your overall project. Instead of writing your own Wixel apps and 3pi firmware, you could just use the 3pi’s serial-slave program and the Wixel’s Wireless Serial App. The Wixels can be set up as a wireless serial link between your comptuer and the 3pi, and then you can write a program on your computer to send serial commands to the 3pi.

Correct.

–David

Thank you!
=) I’ll try it out as soon as I can.

I have been planning on using a modification of the master-slave app on the 3pi and I took a look at the wireless-serial link but did not understand how to modify it to poll between different robots and send larger amounts of data.

Have you got any idea how to achieve this?

My plan was that all the robots receive the data but only the one that has an ID that matches the last dataelement responds with confirmation of the transmission and returns a bit to the wixel connected to the computer.

Thankfull for any help I get
/Simon

It works! Sort of at least, the receiver blinks as supposed to (only if the sender is running). But the sender blinks even if the receiver isn’t running, that is to say if it doesn’t get a data transfer confirmation.

Any ideas why?

The Wireless Serial App only supports communication between two devices (point-to-point). It sounds like you will have more than 2 devices so I guess it won’t work for you.

The radioQueue library is a very simple library that does not support data transfer confirmation. It just sends the packets that you tell it to. If you want confirmation you’ll have to build that on top of radioQueue, or you could use radioLink but that only supports two devices talking to eachother.

You can find out much more by reading the documentation of these libraries:

pololu.github.com/wixel-sdk/

–David