Permalink
Switch branches/tags
Nothing to show
Find file Copy path
9076b88 Feb 11, 2018
2 contributors

Users who have contributed to this file

@thomasroefer @ahasselbring
85 lines (73 sloc) 2.66 KB
#ifndef SPLSTANDARDMESSAGE_H
#define SPLSTANDARDMESSAGE_H
#include <stdint.h>
#define SPL_STANDARD_MESSAGE_STRUCT_HEADER "SPL "
#define SPL_STANDARD_MESSAGE_STRUCT_VERSION 7
/*
* Minimal MTU a network can set is 576 byte.
* We have to subtract the IP header of 60 bytes and the UDP data 8 bytes.
* So we have 576 - 60 - 8 = 508 safe size. From this we have to subtract the prefix to the data - 34 bytes.
* So we have in the end 508 - 34 = 474 bytes free payload.
*
* See also https://stackoverflow.com/a/23915324
*/
#define SPL_STANDARD_MESSAGE_DATA_SIZE 474
/*
* Important remarks about units:
*
* For each parameter, the respective comments describe its unit.
* The following units are used:
*
* - Distances: Millimeters (mm)
* - Angles: Radian
* - Time: Seconds (s)
*/
struct SPLStandardMessage
{
char header[4]; // "SPL "
uint8_t version; // has to be set to SPL_STANDARD_MESSAGE_STRUCT_VERSION
uint8_t playerNum; // [MANDATORY FIELD] 1-6 in normal games as well as in mixed team games
uint8_t teamNum; // [MANDATORY FIELD] the number of the team (as provided by the organizers)
uint8_t fallen; // [MANDATORY FIELD] 1 means that the robot is fallen, 0 means that the robot can play
// [MANDATORY FIELD]
// position and orientation of robot
// coordinates in millimeters
// 0,0 is in center of field
// +ve x-axis points towards the goal we are attempting to score on
// +ve y-axis is 90 degrees counter clockwise from the +ve x-axis
// angle in radians, 0 along the +x axis, increasing counter clockwise
float pose[3]; // x,y,theta
// ball information
float ballAge; // seconds since this robot last saw the ball. -1.f if we haven't seen it
// position of ball relative to the robot
// coordinates in millimeters
// 0,0 is in center of the robot
// +ve x-axis points forward from the robot
// +ve y-axis is 90 degrees counter clockwise from the +ve x-axis
float ball[2];
// number of bytes that is actually used by the data array
uint16_t numOfDataBytes;
// buffer for arbitrary data, teams do not need to send more than specified in numOfDataBytes
uint8_t data[SPL_STANDARD_MESSAGE_DATA_SIZE];
#ifdef __cplusplus
// constructor
SPLStandardMessage() :
version(SPL_STANDARD_MESSAGE_STRUCT_VERSION),
playerNum(-1),
teamNum(-1),
fallen(-1),
ballAge(-1.f),
numOfDataBytes(0)
{
const char* init = SPL_STANDARD_MESSAGE_STRUCT_HEADER;
for(unsigned int i = 0; i < sizeof(header); ++i)
header[i] = init[i];
pose[0] = 0.f;
pose[1] = 0.f;
pose[2] = 0.f;
ball[0] = 0.f;
ball[1] = 0.f;
}
#endif
};
#endif // SPLSTANDARDMESSAGE_H