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)

kamocat 24-11-2010 15:58

Re: Using a DS to control a FRC robot
 
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.

Well, I've tried this out. I can send and receive messages, but something isn't working.
I know it's receiving them, because I receive messages at exactly the rate I chose to send them. (This works down to 1 millisecond)

I think I'm missing the system watchdog.
I remember that the system watchdog works off TCP communication. That means if I want the robot to be enabled, I have to send another message in addition to these UDP datagrams. Do you have any information on that TCP message?

Peter Johnson 24-11-2010 19:23

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

Originally Posted by kamocat (Post 981861)
I think I'm missing the system watchdog.
I remember that the system watchdog works off TCP communication. That means if I want the robot to be enabled, I have to send another message in addition to these UDP datagrams. Do you have any information on that TCP message?

I don't see any TCP traffic in my testing so far. However, I do see occasional (every 3 seconds) UDP traffic between port 750 on the DS and port 17185 on the robot. 64 bytes are sent from the DS to the robot, and the robot responds with 36 bytes. I have not yet decoded the contents of these packets.

kamocat 24-11-2010 20:07

Re: Using a DS to control a FRC robot
 
Hmmm.
Perhaps we could check with the owner of this thread.

kamocat 25-11-2010 01:18

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

Originally Posted by kamocat (Post 981861)
Well, I've tried this out. I can send and receive messages, but something isn't working.
I know it's receiving them, because I receive messages at exactly the rate I chose to send them. (This works down to 1 millisecond)

I think I'm missing the system watchdog.
I remember that the system watchdog works off TCP communication. That means if I want the robot to be enabled, I have to send another message in addition to these UDP datagrams. Do you have any information on that TCP message?

I tried decoding the messages I receive. I'm pretty sure I'm not sending the correct message, since I'm getting almost empty data in reply.
Here's the nonzero data that I get:
  • control bit: binary 01000000 (this does not change whether it's enabled or disabled, teleop or autonomous)
  • battery (integer): decimal 55 (same as 0x37)
  • battery (fractional): decimal 55
  • mac address: 0x00802F118478
  • FPGA version: 3474020444623351856
  • packetIndex: 33680 (this does not change with the packet number I send)

I'm assuming you've gotten this to work yourself.

So, what I'm going to do is upload a message that I might send, and ask you to check if it is valid by recreating the message using the settings I provide:
Alliance Position: Red1
Control state: Teleop disabled
Team ID: 8557
all joystick axis and buttons are zero.

AustinSchuh 25-11-2010 01:43

Re: Using a DS to control a FRC robot
 
Having gotten it working myself, I'd recommend trying to use your code that fills up a packet to recreate a packet that you get back from the bot. If you can recreate the packet from the inputs that the packet is begin given entirely from "scratch", it should work. I found that I wasn't checksumming right, and that was causing problems.

There is no TCP traffic.

kamocat 25-11-2010 16:52

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

Originally Posted by AustinSchuh (Post 981909)
Having gotten it working myself, I'd recommend trying to use your code that fills up a packet to recreate a packet that you get back from the bot. If you can recreate the packet from the inputs that the packet is begin given entirely from "scratch", it should work. I found that I wasn't checksumming right, and that was causing problems.

There is no TCP traffic.

Perhaps I misunderstand you.
The robot sends back a different packet than it receives, using information other than that in the packet that is received.

Are you saying using this returned packet to fix my checksumming?

I suppose I could also open up the "Start DS Communication" VI and see if my packets are being received properly.

AustinSchuh 25-11-2010 22:30

Re: Using a DS to control a FRC robot
 
I'm saying that you should try to regenerate a packet that you snoop from the DS. This would be an "offline" test. Snoop packet A, deduce what inputs were used to generate A (through either code or by hand), feed those to your code, and then check to see if A = what you generated. This will let you know if you can generate a valid packet from known inputs. And valid is easy to check, since you know what the packet should be if you do all your math right.

kamocat 25-11-2010 23:21

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

Originally Posted by AustinSchuh (Post 981963)
I'm saying that you should try to regenerate a packet that you snoop from the DS. This would be an "offline" test. Snoop packet A, deduce what inputs were used to generate A (through either code or by hand), feed those to your code, and then check to see if A = what you generated. This will let you know if you can generate a valid packet from known inputs. And valid is easy to check, since you know what the packet should be if you do all your math right.

Oh, I see. That's a good idea.

kamocat 26-11-2010 03:25

Re: Using a DS to control a FRC robot
 
So, I got everything in the packet correct, except for the last four bytes.
I think somethings wrong with my Alder-32 algorithm. (The checksum doesn't give me any hints to my error).

I've tested it with very short samples, but I don't have anything large enough to roll over the divisor.

Or, perhaps I'm wrong, and the DS actually uses CRC32.

AustinSchuh 26-11-2010 12:13

Re: Using a DS to control a FRC robot
 
Run your checksum including the last 4 bytes with the last 4 bytes set to 0.

kamocat 26-11-2010 13:22

Re: Using a DS to control a FRC robot
 
I've double-checked, and I am doing that.
Alder32 IS the correct checksum, isn't it?

Peter Johnson 26-11-2010 15:07

Re: Using a DS to control a FRC robot
 
I've uploaded my Python version to the RobotPy repo. http://git.tortall.net/cgit.cgi/RobotPy.git/tree/sim

The netcomm directory contains all the heavy lifting Python source:
  • frccomm.py: Packet data structures and packetizing/depacketizing.
  • robotcomm.py: Threaded UDP server implementation equivalent to the NetworkCommunication module on the cRIO.
  • dscomm.py: Threaded UDP client/server implementation equivalent to the Driver Station.

The dspy directory implements a very basic driver station with tkinter GUI.

Running robotcomm.py directly creates a very basic robot emulator (for testing).

I've done basic (enable/disable, etc) interoperability testing between these and the official DS and cRIO. However, a number of things are still untested/unimplemented, such as enhanced IO, resynchronization (switching between official DS and dspy), etc.

kamocat 27-11-2010 02:56

Re: Using a DS to control a FRC robot
 
Okay, guys.
I've checked my Adler32 algorithm and it functions correctly.
I've successfully made the robot think my computer is running the Driver Station by sending it a series of DS I've saved. (This confirms that I'm saving the data correctly)
I don't think I'm manipulating the data incorrectly, since it is such a simple manipulation.

This leaves me with the conclusion that the DS does not use Adler32. (Adler32 is the checksum used by zlib)
Then what does it use?
It's been referred to as a Cyclic Redundancy Check. CRC32 would make sense. Is it the IEEE standard, or is it something else?

AustinSchuh 27-11-2010 03:25

Re: Using a DS to control a FRC robot
 
If I'm reading my code right, it's a CRC with the polynomial = 0xEDB88320L. I'm not nearly as certain about that as I am about other parts.

Peter Johnson 27-11-2010 04:07

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

Originally Posted by kamocat (Post 982110)
This leaves me with the conclusion that the DS does not use Adler32. (Adler32 is the checksum used by zlib)
Then what does it use?
It's been referred to as a Cyclic Redundancy Check. CRC32 would make sense. Is it the IEEE standard, or is it something else?

No, it's not Adler32. It's CRC32. In Python I use zlib.crc32(). The zlib implementation can be found at http://www.stillhq.com/gpg/source-mo...lib/crc32.html.

I believe http://www.libpng.org/pub/png/spec/1...CAppendix.html is a non-table-based version of the same algorithm, but I've not tested that implementation.


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