Thunderbots Project
Loading...
Searching...
No Matches
constants.h
1#pragma once
2#include <math.h>
3
4// Some platformio targets don't support STL, so we can't
5// use unordered_map, string, .... We guard all networking stuff with
6#ifndef PLATFORMIO_BUILD
7#include <string>
8#include <unordered_map>
9
10// Networking
11// the IPv6 multicast address, only ff02 is important, the rest is random
12// see https://en.wikipedia.org/wiki/Solicited-node_multicast_address for why ff02 matters
13static const std::unordered_map<int, std::string> ROBOT_MULTICAST_CHANNELS = {
14 {0, "ff02::c3d0:42d2:bb00"}, {1, "ff02::c3d0:42d2:bb01"},
15 {2, "ff02::c3d0:42d2:bb02"}, {3, "ff02::c3d0:42d2:bb03"},
16 {4, "ff02::c3d0:42d2:bb04"}, {5, "ff02::c3d0:42d2:bb05"},
17 {6, "ff02::c3d0:42d2:bb06"}, {7, "ff02::c3d0:42d2:bb07"},
18 {8, "ff02::c3d0:42d2:bb08"}, {9, "ff02::c3d0:42d2:bb08"},
19 {10, "ff02::c3d0:42d2:bb10"}, {11, "ff02::c3d0:42d2:bb11"},
20 {12, "ff02::c3d0:42d2:bb12"}, {13, "ff02::c3d0:42d2:bb13"},
21 {14, "ff02::c3d0:42d2:bb14"}, {15, "ff02::c3d0:42d2:bb15"}};
22
23// PlotJuggler's default host and port
24// Should be updated to your local machine's IP address if
25// you want to plot from the robot
26static const std::string PLOTJUGGLER_GUI_DEFAULT_HOST = "127.0.0.1";
27static const short unsigned int PLOTJUGGLER_GUI_DEFAULT_PORT = 9870;
28
29// ProtoLogger constants for replay files
30static const std::string REPLAY_FILE_EXTENSION = "replay";
31static const std::string REPLAY_METADATA_DELIMITER = ",";
32static const std::string REPLAY_FILE_VERSION_PREFIX = "version:";
33static const unsigned int REPLAY_FILE_VERSION = 2;
34
35#endif // PLATFORMIO_BUILD
36
37// Redis default server connections properties
38#define REDIS_HOST_LENGTH 10
39static const char REDIS_DEFAULT_HOST[REDIS_HOST_LENGTH] = "127.0.0.1";
40static const short unsigned int REDIS_DEFAULT_PORT = 6379;
41
42// the UDP port robots are listening to for primitives
43static const short unsigned int PRIMITIVE_PORT = 42070;
44
45// the port the AI receives msgs from the robot
46static constexpr short unsigned int ROBOT_STATUS_PORT = 42071;
47static constexpr short unsigned int ROBOT_LOGS_PORT = 42072;
48static constexpr short unsigned int ROBOT_CRASH_PORT = 42074;
49static constexpr short unsigned int NETWORK_COMM_TEST_PORT = 42075;
50static constexpr short unsigned int ROBOT_TO_FULL_SYSTEM_IP_NOTIFICATION_PORT = 42073;
51static constexpr short unsigned int FULL_SYSTEM_TO_ROBOT_IP_NOTIFICATION_PORT = 42076;
52
53// maximum transfer unit of the network interface
54// this is an int to avoid Wconversion with lwip
55static const short unsigned int MAXIMUM_TRANSFER_UNIT_BYTES = 1500;
56
57// This file contains all constants that are shared between our software (AI)
58// and firmware code. Since this needs to be compiled by both C and C++, everything
59// should be defined in a way that's compatible with C.
60
61/* Game Rules */
62// The max allowed speed of the ball, in metres per second
63// https://robocup-ssl.github.io/ssl-rules/sslrules.html#_ball_speed
64static const double BALL_MAX_SPEED_METERS_PER_SECOND = 6.5;
65// The safe max speed of the ball that we should shoot at, in metres per second
66static const double BALL_SAFE_MAX_SPEED_METERS_PER_SECOND =
67 BALL_MAX_SPEED_METERS_PER_SECOND - 0.5;
68// The distance that the ball has to travel for it to be considered in play
69// after a kick-off, free kick, or penalty kick.
70// https://robocup-ssl.github.io/ssl-rules/sslrules.html#_ball_in_and_out_of_play
71static const double BALL_IN_PLAY_DISTANCE_THRESHOLD_METERS = 0.05;
72// The max allowed height of the robots, in metres
73static const double ROBOT_MAX_HEIGHT_METERS = 0.15;
74// The max allowed radius of the robots, in metres
75static const double ROBOT_MAX_RADIUS_METERS = 0.09;
76// The distance from the center of the robot to the front face (the flat part), in meters
77static const double DIST_TO_FRONT_OF_ROBOT_METERS = 0.078;
78// The approximate radius of the ball according to the SSL rulebook
79static const double BALL_MAX_RADIUS_METERS = 0.0215;
80// According to the rules, 80% of the ball must be seen at all times. Robots may not
81// cover more than 20% of the ball
82static const double MAX_FRACTION_OF_BALL_COVERED_BY_ROBOT = 0.2;
83
84// The radius of a circle region where ball placement is acceptable (in meters).
85constexpr double BALL_PLACEMENT_TOLERANCE_RADIUS_METERS = 0.15;
86// The radius of the outer region where robots are not allowed to be during ball
87// placement (in meters)
88constexpr double BALL_PLACEMENT_ROBOT_AVOID_RADIUS_METERS = 0.5;
89// The time limit for ball placement in seconds
90constexpr int BALL_PLACEMENT_TIME_LIMIT_S = 30;
91
92// The mass of a standard golf ball, as defined by https://en.wikipedia.org/wiki/Golf_ball
93constexpr double BALL_MASS_KG = 0.004593;
94// The max allowed speed of the robot when the stop command is issued, in meters per
95// second
96static const double STOP_COMMAND_ROBOT_MAX_SPEED_METERS_PER_SECOND = 1.5;
97// The margin by which the speed of the robot should stay below the maximum allowed speed
98// when the stop command is issued
99static const double STOP_COMMAND_SPEED_SAFETY_MARGIN_METERS_PER_SECOND = 0.2;
100// The max allowed speed of the robot before collisions would incur a foul
101static const double COLLISION_ALLOWED_ROBOT_MAX_SPEED_METERS_PER_SECOND = 0.5;
102// The minimum distance from the ball all robots must be when the stop command is issued
103// https://robocup-ssl.github.io/ssl-rules/sslrules.html#_stop
104static const double STOP_COMMAND_BALL_AVOIDANCE_DISTANCE_M = 0.5;
105// The maximum speed attainable by enemy robots
106static const double ENEMY_ROBOT_MAX_SPEED_METERS_PER_SECOND = 3.0;
107// The maximum acceleration achievable by enemy robots, in metres per seconds squared.
108static const double ENEMY_ROBOT_MAX_ACCELERATION_METERS_PER_SECOND_SQUARED = 4.0;
109
110static const double ACCELERATION_DUE_TO_GRAVITY_METERS_PER_SECOND_SQUARED = 9.81;
111// The minimum distance the non-placing team must keep to avoid ball placement
112// interference
113static const double ENEMY_BALL_PLACEMENT_DISTANCE_METERS = 0.5;
114
115/*Simulator Constants*/
116
117// these values are set in coordination with other objects the ball will collide with.
118// the resulting coefficient of friction is the product of both objects friction value.
119
120// the sliding friction the ball experiences in Newtons
121constexpr double BALL_SLIDING_FRICTION_NEWTONS = 1.0;
122// the restitution of the ball
123constexpr double BALL_RESTITUTION = 1.0;
124// the transition factor where the ball goes from sliding to rolling
125constexpr double FRICTION_TRANSITION_FACTOR = 5.0 / 7.0;
126// the stationary ball speed in m/s
127constexpr double STATIONARY_BALL_SPEED_METERS_PER_SECOND = 0.01;
128// the acceleration the ball experiences due to rolling friction in m/s^2
129constexpr double BALL_ROLLING_FRICTION_DECELERATION_METERS_PER_SECOND_SQUARED = -0.5;
130// the acceleration the ball experiences due to sliding friction in m/s^2
131constexpr double BALL_SLIDING_FRICTION_DECELERATION_METERS_PER_SECOND_SQUARED =
132 -BALL_SLIDING_FRICTION_NEWTONS / BALL_MASS_KG;
133
134/* Unit Conversion */
135static const double MILLIMETERS_PER_METER = 1000.0;
136static const double METERS_PER_MILLIMETER = 1.0 / 1000.0;
137static const double CENTIMETERS_PER_METER = 100.0;
138static const double METERS_PER_CENTIMETER = 1.0 / 100.0;
139
140static const double CENTIRADIANS_PER_RADIAN = 100.0;
141static const double RADIANS_PER_CENTIRADIAN = 1.0 / 100.0;
142
143static const double NANOSECONDS_PER_MILLISECOND = 1000000.0;
144static const double NANOSECONDS_PER_SECOND = 1000000000.0;
145static const double MICROSECONDS_PER_MILLISECOND = 1000.0;
146static const double MICROSECONDS_PER_SECOND = 1000000.0;
147static const double MILLISECONDS_PER_SECOND = 1000.0;
148static const double SECONDS_PER_MICROSECOND = 1.0 / 1000000.0;
149static const double SECONDS_PER_NANOSECOND = 1.0 / 1000000000.0;
150static const double SECONDS_PER_MILLISECOND = 1.0 / 1000.0;
151static const double MILLISECONDS_PER_MICROSECOND = 1.0 / 1000.0;
152static const double MILLISECONDS_PER_NANOSECOND = 1.0 / 1000000.0;
153static const double SECONDS_PER_MINUTE = 60.0;
154
155static const double DEFAULT_SIMULATOR_TICK_RATE_SECONDS_PER_TICK =
156 1.0 / 60.0; // corresponds to 60 Hz
157static const double DEFAULT_SIMULATOR_TICK_RATE_MILLISECONDS_PER_TICK =
158 DEFAULT_SIMULATOR_TICK_RATE_SECONDS_PER_TICK * 1000;
159
160// The total number of robot ids on one team
161static const unsigned int MAX_ROBOT_IDS_PER_SIDE = 8;
162// The total number of possible robot ids between two teams
163static const unsigned int MAX_ROBOT_IDS = MAX_ROBOT_IDS_PER_SIDE * 2;
164
165// How many robots are allowed in each division
166static const unsigned int DIV_A_NUM_ROBOTS = 11;
167static const unsigned int DIV_B_NUM_ROBOTS = 6;
168
169// The maximum time in seconds given to Full System to cleanly exit the process.
170static const double MAX_TIME_TO_EXIT_FULL_SYSTEM_SEC = 0.5;
171
172// Battery Constants
173static const unsigned NUM_CELLS_IN_BATTERY = 3;
174static const unsigned NUM_BATTERIES_IN_SERIES = 2;
175static const double MAX_SINGLE_CELL_VOLTAGE = 4.2;
176static const double MIN_SINGLE_CELL_VOLTAGE = 3.5 + 0.1; // +0.1v headroom
177
178static const double MIN_BATTERY_VOLTAGE =
179 MIN_SINGLE_CELL_VOLTAGE * NUM_CELLS_IN_BATTERY * NUM_BATTERIES_IN_SERIES;
180static const double MAX_BATTERY_VOLTAGE =
181 MAX_SINGLE_CELL_VOLTAGE * NUM_CELLS_IN_BATTERY * NUM_BATTERIES_IN_SERIES;
182static const double BATTERY_WARNING_VOLTAGE = MIN_BATTERY_VOLTAGE + 1.0; // 1V headroom
183
184// Chick Capacitor Constants
185static const double MIN_CAPACITOR_VOLTAGE = 0;
186static const double MAX_CAPACITOR_VOLTAGE = 250.0 + 50.0; // +50v headroom
187
188static const unsigned int ROBOT_CHIP_ANGLE_DEGREES = 45;
189static const double CHICKER_TIMEOUT = 3 * MILLISECONDS_PER_SECOND;
190
191// Kick Spd to Pulse Width Safety Constraint Constants
192
193static const int MAX_KICK_CONSTANT = 850;
194static const double MAX_KICK_COEFFICIENT = 0.4;
195
196// Arduino
197
198// UART baud rate used to communicate between system and arudino
199static const long ARDUINO_BAUD_RATE = 115200;
200
201/*
202 * each estop message is one byte and is defined as follows
203 * bit 0 (least significant bit): estop state, a value of 1 is play, 0 is stop
204 * bit 1-7: set to 0
205 * any other message received is considered a EstopState::STATUS_ERROR
206 */
207static const int ESTOP_MESSAGE_SIZE_BYTES = 1;
208
209static const unsigned char ESTOP_PLAY_MSG = 0;
210static const unsigned char ESTOP_STOP_MSG = 1;
211
212// Number of times to send a STOP primitive when robot is disconnected from Manual Control
213static const unsigned int NUM_TIMES_SEND_STOP = 10;
214// How long a robot should receive no RobotStatus messages for until it is considered
215// disconnected
216static const double DISCONNECT_DURATION_MS = 1 * MILLISECONDS_PER_SECOND;
217
218// product and vendor id for Arduino Uno Rev3 (retrieved from
219// http://www.linux-usb.org/usb.ids )
220#define ARDUINO_ID_LENGTH 5
221static const char ARDUINO_VENDOR_ID[ARDUINO_ID_LENGTH] = "2341";
222static const char ARDUINO_PRODUCT_ID[ARDUINO_ID_LENGTH] = "0043";
223
224// Number of times thunderloop should tick per second
225static const unsigned THUNDERLOOP_HZ = 300u;
226
227static const unsigned NUM_GENEVA_ANGLES = 5;
228
229// Jetson Nano Constants
230static const double MAX_JETSON_TEMP_C = 97;