2828extern int clock_nanosleep (clockid_t __clock_id, int __flags,
2929 __const struct timespec * __req, struct timespec * __rem);
3030
31+ namespace
32+ {
33+ /* *
34+ * Returns a copy of robot_constants with its movement limits overridden by any
35+ * matching keys present in robot_config.toml. Fields whose key is absent from the
36+ * TOML file keep their compiled-in value from createRobotConstants().
37+ *
38+ * @param robot_constants The compiled-in robot constants to override
39+ * @param toml_config_client The TOML config client to read overrides from
40+ *
41+ * @return robot_constants with movement limits overridden by robot_config.toml
42+ */
43+ robot_constants::RobotConstants applyTomlRobotConstantsOverrides (
44+ robot_constants::RobotConstants robot_constants, TomlConfigClient& toml_config_client)
45+ {
46+ robot_constants.robot_max_speed_m_per_s =
47+ std::stof (toml_config_client.get (ROBOT_MAX_SPEED_M_PER_S_CONFIG_KEY ,
48+ std::to_string (robot_constants.robot_max_speed_m_per_s )));
49+ robot_constants.ball_placement_wall_max_speed_m_per_s = std::stof (
50+ toml_config_client.get (BALL_PLACEMENT_WALL_MAX_SPEED_M_PER_S_CONFIG_KEY ,
51+ std::to_string (
52+ robot_constants.ball_placement_wall_max_speed_m_per_s )));
53+ robot_constants.ball_placement_retreat_max_speed_m_per_s = std::stof (
54+ toml_config_client.get (
55+ BALL_PLACEMENT_RETREAT_MAX_SPEED_M_PER_S_CONFIG_KEY ,
56+ std::to_string (robot_constants.ball_placement_retreat_max_speed_m_per_s )));
57+ robot_constants.dribble_speed_m_per_s =
58+ std::stof (toml_config_client.get (DRIBBLE_SPEED_M_PER_S_CONFIG_KEY ,
59+ std::to_string (robot_constants.dribble_speed_m_per_s )));
60+ robot_constants.robot_trajectory_max_speed_m_per_s = std::stof (
61+ toml_config_client.get (
62+ ROBOT_TRAJECTORY_MAX_SPEED_M_PER_S_CONFIG_KEY ,
63+ std::to_string (robot_constants.robot_trajectory_max_speed_m_per_s )));
64+ robot_constants.robot_max_acceleration_m_per_s_2 = std::stof (
65+ toml_config_client.get (
66+ ROBOT_MAX_ACCELERATION_M_PER_S_2_CONFIG_KEY ,
67+ std::to_string (robot_constants.robot_max_acceleration_m_per_s_2 )));
68+ robot_constants.robot_max_deceleration_m_per_s_2 = std::stof (
69+ toml_config_client.get (
70+ ROBOT_MAX_DECELERATION_M_PER_S_2_CONFIG_KEY ,
71+ std::to_string (robot_constants.robot_max_deceleration_m_per_s_2 )));
72+ robot_constants.robot_trajectory_max_acceleration_m_per_s_2 = std::stof (
73+ toml_config_client.get (
74+ ROBOT_TRAJECTORY_MAX_ACCELERATION_M_PER_S_2_CONFIG_KEY ,
75+ std::to_string (robot_constants.robot_trajectory_max_acceleration_m_per_s_2 )));
76+ robot_constants.robot_trajectory_max_deceleration_m_per_s_2 = std::stof (
77+ toml_config_client.get (
78+ ROBOT_TRAJECTORY_MAX_DECELERATION_M_PER_S_2_CONFIG_KEY ,
79+ std::to_string (robot_constants.robot_trajectory_max_deceleration_m_per_s_2 )));
80+ robot_constants.robot_max_jerk_m_per_s_3 =
81+ std::stof (toml_config_client.get (ROBOT_MAX_JERK_M_PER_S_3_CONFIG_KEY ,
82+ std::to_string (robot_constants.robot_max_jerk_m_per_s_3 )));
83+ robot_constants.robot_min_jerk_m_per_s_3 =
84+ std::stof (toml_config_client.get (ROBOT_MIN_JERK_M_PER_S_3_CONFIG_KEY ,
85+ std::to_string (robot_constants.robot_min_jerk_m_per_s_3 )));
86+ robot_constants.robot_max_ang_speed_rad_per_s = std::stof (
87+ toml_config_client.get (
88+ ROBOT_MAX_ANG_SPEED_RAD_PER_S_CONFIG_KEY ,
89+ std::to_string (robot_constants.robot_max_ang_speed_rad_per_s )));
90+ robot_constants.robot_trajectory_max_ang_speed_rad_per_s = std::stof (
91+ toml_config_client.get (
92+ ROBOT_TRAJECTORY_MAX_ANG_SPEED_RAD_PER_S_CONFIG_KEY ,
93+ std::to_string (robot_constants.robot_trajectory_max_ang_speed_rad_per_s )));
94+ robot_constants.robot_max_ang_acceleration_rad_per_s_2 = std::stof (
95+ toml_config_client.get (
96+ ROBOT_MAX_ANG_ACCELERATION_RAD_PER_S_2_CONFIG_KEY ,
97+ std::to_string (robot_constants.robot_max_ang_acceleration_rad_per_s_2 )));
98+
99+ return robot_constants;
100+ }
101+ } // namespace
102+
31103// signal handling is done by csignal which requires a function pointer with C linkage
32104extern " C"
33105{
@@ -75,14 +147,15 @@ extern "C"
75147Thunderloop::Thunderloop (const robot_constants::RobotConstants& robot_constants,
76148 bool enable_log_merging, const int loop_hz)
77149 : toml_config_client_(std::make_unique<TomlConfigClient>(TOML_CONFIG_FILE_PATH )),
78- robot_constants_(robot_constants),
150+ robot_constants_(
151+ applyTomlRobotConstantsOverrides (robot_constants, *toml_config_client_)),
79152 robot_id_(std::stoi(toml_config_client_->get (ROBOT_ID_CONFIG_KEY ))),
80153 channel_id_(
81154 std::stoi (toml_config_client_->get (ROBOT_MULTICAST_CHANNEL_CONFIG_KEY ))),
82155 network_interface_(toml_config_client_->get (ROBOT_NETWORK_INTERFACE_CONFIG_KEY )),
83156 loop_hz_(loop_hz),
84157 primitive_executor_(
85- robot_constants ,
158+ robot_constants_ ,
86159 PositionControllerConfig{
87160 std::stod (toml_config_client_->get (
88161 ROBOT_POSITION_CONTROLLER_KP_CONFIG_KEY )),
@@ -102,9 +175,9 @@ Thunderloop::Thunderloop(const robot_constants::RobotConstants& robot_constants,
102175 std::stod (toml_config_client_->get (
103176 ROBOT_ORIENTATION_CONTROLLER_MAX_INTEGRAL_CONFIG_KEY ))}),
104177 robot_localizer_(RobotLocalizer::RobotLocalizerConfig{
105- robot_constants .kalman_process_noise_variance_rad_per_s_4 ,
106- robot_constants .kalman_vision_noise_variance_rad_2 ,
107- robot_constants .kalman_motor_sensor_noise_variance_rad_per_s_2 })
178+ robot_constants_ .kalman_process_noise_variance_rad_per_s_4 ,
179+ robot_constants_ .kalman_vision_noise_variance_rad_2 ,
180+ robot_constants_ .kalman_motor_sensor_noise_variance_rad_per_s_2 })
108181{
109182 waitForNetworkUp ();
110183
@@ -148,7 +221,7 @@ Thunderloop::Thunderloop(const robot_constants::RobotConstants& robot_constants,
148221#endif
149222
150223#ifndef DISABLE_MOTOR_SERVICE
151- motor_service_ = std::make_unique<MotorService>(robot_constants );
224+ motor_service_ = std::make_unique<MotorService>(robot_constants_ );
152225 g_motor_service = motor_service_.get ();
153226 motor_service_->setup ();
154227
0 commit comments