Skip to content

Commit 276f281

Browse files
authored
Refactor robot constants into cpp file (#3811)
1 parent 0e4d417 commit 276f281

3 files changed

Lines changed: 102 additions & 94 deletions

File tree

src/shared/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cc_library(
2222

2323
cc_library(
2424
name = "robot_constants",
25-
srcs = [],
26-
hdrs = [":robot_constants.h"],
25+
srcs = ["robot_constants.cpp"],
26+
hdrs = ["robot_constants.h"],
2727
deps = [":constants"],
2828
)

src/shared/robot_constants.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include "shared/robot_constants.h"
2+
3+
#include "shared/constants.h"
4+
5+
namespace robot_constants
6+
{
7+
8+
#if CHECK_VERSION(2026)
9+
RobotConstants createRobotConstants()
10+
{
11+
return {
12+
.robot_radius_m = static_cast<float>(ROBOT_MAX_RADIUS_METERS),
13+
.front_wheel_angle_deg = 32.0f,
14+
.back_wheel_angle_deg = 44.0f,
15+
16+
.fr_x_pos_meters = 0.03485f,
17+
.fr_y_pos_meters = -0.06632f,
18+
.fl_x_pos_meters = 0.03485f,
19+
.fl_y_pos_meters = 0.06632f,
20+
.bl_x_pos_meters = -0.04985f,
21+
.bl_y_pos_meters = 0.05592f,
22+
.br_x_pos_meters = -0.04985f,
23+
.br_y_pos_meters = -0.05592f,
24+
25+
.front_of_robot_width_meters = 0.11f,
26+
.dribbler_width_meters = 0.07825f,
27+
28+
// Dribbler speeds are negative as that is the direction that sucks the ball in
29+
.indefinite_dribbler_speed_rpm = -10000,
30+
.max_force_dribbler_speed_rpm = -12000,
31+
32+
// Motor constant
33+
.motor_max_acceleration_m_per_s_2 = 2.0f,
34+
35+
// Robot's linear movement constants
36+
.robot_max_speed_m_per_s = 3.0f,
37+
.robot_trajectory_max_speed_m_per_s = 2.5f,
38+
39+
.robot_max_acceleration_m_per_s_2 = 4.5f,
40+
.robot_max_deceleration_m_per_s_2 = 3.0f,
41+
42+
.robot_trajectory_max_acceleration_m_per_s_2 = 3.0f,
43+
.robot_trajectory_max_deceleration_m_per_s_2 = 2.0f,
44+
45+
// Robot's angular movement constants
46+
.robot_max_ang_speed_rad_per_s = 10.0f,
47+
.robot_trajectory_max_ang_speed_rad_per_s = 7.0f,
48+
.robot_max_ang_acceleration_rad_per_s_2 = 30.0f,
49+
50+
.wheel_radius_meters = 0.03f,
51+
52+
.expected_lever_arm = 0.0749f,
53+
54+
// Kalman filter variances for robot localizer
55+
.kalman_process_noise_variance_rad_per_s_4 = 1.0f,
56+
.kalman_vision_noise_variance_rad_2 = 0.01f * 0.01f,
57+
.kalman_motor_sensor_noise_variance_rad_per_s_2 = 0.5f};
58+
}
59+
#elif CHECK_VERSION(2021)
60+
RobotConstants createRobotConstants()
61+
{
62+
return {
63+
.robot_radius_m = static_cast<float>(ROBOT_MAX_RADIUS_METERS),
64+
.front_wheel_angle_deg = 32.06f,
65+
.back_wheel_angle_deg = 46.04f,
66+
67+
.front_of_robot_width_meters = 0.11f,
68+
.dribbler_width_meters = 0.07825f,
69+
70+
// Dribbler speeds are negative as that is the direction that sucks the ball in
71+
.indefinite_dribbler_speed_rpm = -10000,
72+
.max_force_dribbler_speed_rpm = -12000,
73+
74+
// Motor constant
75+
.motor_max_acceleration_m_per_s_2 = 4.5f,
76+
77+
// Robot's linear movement constants
78+
.robot_max_speed_m_per_s = 3.000f,
79+
.robot_trajectory_max_speed_m_per_s = 3.000f,
80+
.robot_max_acceleration_m_per_s_2 = 3.0f,
81+
.robot_max_deceleration_m_per_s_2 = 3.0f,
82+
.robot_trajectory_max_acceleration_m_per_s_2 = 3.0f,
83+
.robot_trajectory_max_deceleration_m_per_s_2 = 3.0f,
84+
85+
// Robot's angular movement constants
86+
.robot_max_ang_speed_rad_per_s = 10.0f,
87+
.robot_trajectory_max_ang_speed_rad_per_s = 7.0f,
88+
.robot_max_ang_acceleration_rad_per_s_2 = 30.0f,
89+
90+
.wheel_radius_meters = 0.03f,
91+
92+
// Kalman filter variances for robot localizer
93+
.kalman_process_noise_variance_rad_per_s_4 = 0.5f,
94+
.kalman_vision_noise_variance_rad_2 = 0.01f * 0.01f,
95+
.kalman_motor_sensor_noise_variance_rad_per_s_2 = 0.5f * 0.5f};
96+
}
97+
#endif
98+
99+
} // namespace robot_constants

src/shared/robot_constants.h

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include "shared/constants.h"
4-
53
namespace robot_constants
64
{
75

@@ -140,95 +138,6 @@ struct RobotConstants
140138
*
141139
* @return robot constants for the robot
142140
*/
143-
#if CHECK_VERSION(2026)
144-
constexpr RobotConstants createRobotConstants()
145-
{
146-
return {
147-
.robot_radius_m = static_cast<float>(ROBOT_MAX_RADIUS_METERS),
148-
.front_wheel_angle_deg = 32.0f,
149-
.back_wheel_angle_deg = 44.0f,
150-
151-
.fr_x_pos_meters = 0.03485f,
152-
.fr_y_pos_meters = -0.06632f,
153-
.fl_x_pos_meters = 0.03485f,
154-
.fl_y_pos_meters = 0.06632f,
155-
.bl_x_pos_meters = -0.04985f,
156-
.bl_y_pos_meters = 0.05592f,
157-
.br_x_pos_meters = -0.04985f,
158-
.br_y_pos_meters = -0.05592f,
159-
160-
.front_of_robot_width_meters = 0.11f,
161-
.dribbler_width_meters = 0.07825f,
162-
163-
// Dribbler speeds are negative as that is the direction that sucks the ball in
164-
.indefinite_dribbler_speed_rpm = -10000,
165-
.max_force_dribbler_speed_rpm = -12000,
166-
167-
// Motor constant
168-
.motor_max_acceleration_m_per_s_2 = 2.0f,
169-
170-
// Robot's linear movement constants
171-
.robot_max_speed_m_per_s = 3.0f,
172-
.robot_trajectory_max_speed_m_per_s = 2.5f,
173-
174-
.robot_max_acceleration_m_per_s_2 = 4.5f,
175-
.robot_max_deceleration_m_per_s_2 = 3.0f,
176-
177-
.robot_trajectory_max_acceleration_m_per_s_2 = 3.0f,
178-
.robot_trajectory_max_deceleration_m_per_s_2 = 2.0f,
179-
180-
// Robot's angular movement constants
181-
.robot_max_ang_speed_rad_per_s = 10.0f,
182-
.robot_trajectory_max_ang_speed_rad_per_s = 7.0f,
183-
.robot_max_ang_acceleration_rad_per_s_2 = 30.0f,
184-
185-
.wheel_radius_meters = 0.03f,
186-
187-
.expected_lever_arm = 0.0749f,
188-
189-
// Kalman filter variances for robot localizer
190-
.kalman_process_noise_variance_rad_per_s_4 = 1.0f,
191-
.kalman_vision_noise_variance_rad_2 = 0.01f * 0.01f,
192-
.kalman_motor_sensor_noise_variance_rad_per_s_2 = 0.5f};
193-
}
194-
#elif CHECK_VERSION(2021)
195-
constexpr RobotConstants createRobotConstants()
196-
{
197-
return {
198-
.robot_radius_m = static_cast<float>(ROBOT_MAX_RADIUS_METERS),
199-
.front_wheel_angle_deg = 32.06f,
200-
.back_wheel_angle_deg = 46.04f,
201-
202-
.front_of_robot_width_meters = 0.11f,
203-
.dribbler_width_meters = 0.07825f,
204-
205-
// Dribbler speeds are negative as that is the direction that sucks the ball in
206-
.indefinite_dribbler_speed_rpm = -10000,
207-
.max_force_dribbler_speed_rpm = -12000,
208-
209-
// Motor constant
210-
.motor_max_acceleration_m_per_s_2 = 4.5f,
211-
212-
// Robot's linear movement constants
213-
.robot_max_speed_m_per_s = 3.000f,
214-
.robot_trajectory_max_speed_m_per_s = 3.000f,
215-
.robot_max_acceleration_m_per_s_2 = 3.0f,
216-
.robot_max_deceleration_m_per_s_2 = 3.0f,
217-
.robot_trajectory_max_acceleration_m_per_s_2 = 3.0f,
218-
.robot_trajectory_max_deceleration_m_per_s_2 = 3.0f,
219-
220-
// Robot's angular movement constants
221-
.robot_max_ang_speed_rad_per_s = 10.0f,
222-
.robot_trajectory_max_ang_speed_rad_per_s = 7.0f,
223-
.robot_max_ang_acceleration_rad_per_s_2 = 30.0f,
224-
225-
.wheel_radius_meters = 0.03f,
226-
227-
// Kalman filter variances for robot localizer
228-
.kalman_process_noise_variance_rad_per_s_4 = 0.5f,
229-
.kalman_vision_noise_variance_rad_2 = 0.01f * 0.01f,
230-
.kalman_motor_sensor_noise_variance_rad_per_s_2 = 0.5f * 0.5f};
231-
}
232-
#endif
141+
RobotConstants createRobotConstants();
233142

234143
} // namespace robot_constants

0 commit comments

Comments
 (0)