Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Using a DS to control a FRC robot (http://www.chiefdelphi.com/forums/showthread.php?t=87584)

Greg McKaskle 22-11-2010 20:30

Re: Using a DS to control a FRC robot
 
There are two choices for getting the images.

What I'd recommend is to put the camera on the external switch beside the cRIO. With that, you can make direct requests to the camera requesting a JPEG. The Axis website documents the syntax of the request -- it is part of the VAPIX API.

The way the camera has been used the last few years is to put it behind the cRIO soft-switch. The command to the camera is then made on the cRIO, and the contents are retransmitted to the DS.

There is actually a third way, involving making a pass-thru for the cRIO TCP stack, but again, I'd suggest the first approach.

Greg McKaskle

kamocat 22-11-2010 23:12

Re: Using a DS to control a FRC robot
 
For the system disable, I would suggest a deadman using the L button, so the robot is only enabled while the L button is pressed.

Robototes2412 23-11-2010 01:01

Re: Using a DS to control a FRC robot
 
so something like this:

Code:

while(keysDown() & KEY_L) {
    scanKeys();
    //do the funky robot controlling stoofe
}


kamocat 23-11-2010 01:12

Re: Using a DS to control a FRC robot
 
No, not quite.
You still want to *communicate* with the robot regardless of its state. Just use the L key to determine whether the robot is enabled or not.

Robototes2412 23-11-2010 01:16

Re: Using a DS to control a FRC robot
 
or then:

Code:

while (1) { //in nds programming, while (1) loops are common
    scanKeys();
    if (lButton()) {
        enabled = 1;
    }
    if (enabled && upDPad()) {
        send(dir_FORWARD);
    }
    if (enabled && downDPad()) {
        send(dir_BACKWARD);
    }
}

all of this assuming that enabled is a bool and that send is a void

kamocat 23-11-2010 01:32

Re: Using a DS to control a FRC robot
 
Could it be that the driver station simply sends a flattened string of this datatype?

Peter Johnson 23-11-2010 01:58

Re: Using a DS to control a FRC robot
 
Quote:

Originally Posted by kamocat (Post 981689)
Could it be that the driver station simply sends a flattened string of this datatype?

Essentially, yes. The first 80 bytes of the packet are indeed the FRCCommonControlData structure. The packet size is 1024 bytes, however; the last 4 bytes is a CRC32 of the entire packet. Most of the rest of the packet is normally 0, but last year dynamic blocks were added into this space for the DriverStationEnhancedIO stuff. The CRC32 is the standard one found in zlib, and is calculated over the entire packet with the CRC32 field equal to 0.

The packet needs to be sent to port 1110 on the robot; the standard DS does this every 20 ms.

The robot->DS packet is quite different. I'll post the full info once I've double-checked it in my Python implementation.

kamocat 23-11-2010 13:29

Re: Using a DS to control a FRC robot
 
Well, here's what I've guessed so far:

name – datatype – length (bytes)
battery – sgl – 4
dsDigitalOut – u8 – 1
updateNumber – u8 – 1
userDataHigh – string – 0<980*
userDataHighLength – i32 – 4
userDataLow – string – 0<980*
userDataLowLength – i32 – 4
errorData – string – 0<980*
errorDataLength – i32 – 4


subtotal: 18

* the length of userDataHigh + userDataLow + errorData may be no greater than 980 bytes.

total: 980 + subtotal = 998

I know the total SHOULD be 1024, so this leaves 26 bytes unaccounted for.

Robototes2412 23-11-2010 13:40

Re: Using a DS to control a FRC robot
 
as far as a protocol for controlling the robot, what would you suggest?

my thoughts are sending signals like "f" for forward, etc.

kamocat 23-11-2010 14:13

Re: Using a DS to control a FRC robot
 
1 Attachment(s)
Quote:

Originally Posted by Peter Johnson (Post 981690)
Essentially, yes. The first 80 bytes of the packet are indeed the FRCCommonControlData structure. The packet size is 1024 bytes, however; the last 4 bytes is a CRC32 of the entire packet. Most of the rest of the packet is normally 0, but last year dynamic blocks were added into this space for the DriverStationEnhancedIO stuff. The CRC32 is the standard one found in zlib, and is calculated over the entire packet with the CRC32 field equal to 0.

The packet needs to be sent to port 1110 on the robot; the standard DS does this every 20 ms.

The robot->DS packet is quite different. I'll post the full info once I've double-checked it in my Python implementation.

I looked up the CRC32 in zlib, and found it's actually Adler-32.
It's really easy to make. (I've attached a LabVIEW implementation)

kamocat 23-11-2010 14:15

Re: Using a DS to control a FRC robot
 
Quote:

Originally Posted by Robototes2412 (Post 981728)
as far as a protocol for controlling the robot, what would you suggest?

my thoughts are sending signals like "f" for forward, etc.

For controlling the robot, I would use the touchscreen. Send to the robot the location on the touchscreen. However, scale it to be like axis 1 and 2 of Joystick 1.

Robototes2412 23-11-2010 14:17

Re: Using a DS to control a FRC robot
 
ok, can you please include the code in line-based format? i cannot read labview files or code

kamocat 23-11-2010 14:27

Re: Using a DS to control a FRC robot
 
It's right on the wikipedia page.
Code:

#define MOD_ADLER 65521
 
unsigned long adler32(unsigned char *data, int len) /* where data is the location of the data in physical memory and len is the length of the data in bytes */
{
    unsigned long a = 1, b = 0;
    int index;
 
    /* Process each byte of the data in order */
    for (index = 0; index < len; ++index)
    {
        a = (a + data[index]) % MOD_ADLER;
        b = (b + a) % MOD_ADLER;
    }
 
    return (b << 16) | a;
}


Peter Johnson 23-11-2010 22:24

Re: Using a DS to control a FRC robot
 
Quote:

Originally Posted by kamocat (Post 981726)
Well, here's what I've guessed so far:

<SNIP>

I know the total SHOULD be 1024, so this leaves 26 bytes unaccounted for.

Robot -> DS direction:
DS Dst Port 1150
1024 bytes (1152 if setUserDsLcdData() called)
Sent immediately after DS packet received (in response)

0x0: current control byte (echoed copy of FRCCommonControlData.control)
0x1: Battery voltage (integer portion in BCD)
0x37 if no code
0x2: Battery voltage (fractional portion in BCD)
0x37 if no code
0x3: DS Digital outputs
0x4-0x7: ?
0x8-0x9: teamID (big endian integer)
0xa-0xf: cRIO MAC address, in order, as bytes (e.g. 00,80,2f,11,4d,ac)
0x10-0x17: FPGA version? "06300800"
0x18-0x1d: ?
0x1e-0x1f: current command packet index (echoed copy of FRCCommonControlData.packetIndex)
0x20: User Data update number (from setStatusData())
0x21-0x24: User string length (32-bit big endian)
0x25 - X: User string - setStatusData() userDataHigh
X+1 - X+4: Error string length (32-bit big endian)
X+5 - Y: Error string - setErrorData()
Y+1 - Y+4: User data length (32-bit big endian)
Y+5 - 0x3d7: User data - setStatusData() userDataLow
0x3d8 - 0x3f7: overrideIOConfig() data (DSEIO status_block_t), followed by 0s
0x3f8 - 0x3fb: 0
0x3fc - 0x3ff: big endian CRC32 of 0-0x3ff (with 0 in CRC field)

If setUserDsLcdData() called:
0x400: 0x9f
0x401: 0xff
0x402 - 0x47f: LCD contents, padded with spaces (0x20)
split into 6 lines of 21 chars, top-to-bottom, left-to-right

This is copy and paste from my work in progress doc on the subject.

kamocat 23-11-2010 22:43

Re: Using a DS to control a FRC robot
 
For the DS->robot message, I'm uncertain about what to do with the last several elements in the FRCCommonControlData.
EDIT: to answer my own question, here are the values for the v20 image:

  • cRIO checksum (u64) - 0
  • FPGA checksum1 (u64) - 0
  • FPGA checksum2 (u64) - 0
  • vMonth1 (u8) - 49
  • vMonth2 (u8) - 48
  • vDay1 (u8) - 48
  • vDay2 (u8) - 50
  • vYear1 (u8) - 48
  • vYear2 (u8) - 56
  • vRev1 (u8) - 48
  • vRev2 (u8) - 48


All times are GMT -5. The time now is 23:14.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi