Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
42172bf
init merge
Andrewyx May 29, 2026
fa58f79
linting
Andrewyx May 29, 2026
1cd0268
remove auto test
Andrewyx May 29, 2026
aff8056
remove auto test
Andrewyx May 29, 2026
41df92c
test fixture fixes
Andrewyx May 29, 2026
a677125
test fixture fixes linting
Andrewyx May 29, 2026
4e4a2c4
tuning constants pid
Andrewyx May 29, 2026
cc994be
tuning constants pid
Andrewyx May 29, 2026
8639b2c
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 29, 2026
573dc74
removed old pid
Andrewyx May 29, 2026
060b704
Merge branch 'Andrewyx/robot_localizer' of github.com:Andrewyx/Softwa…
Andrewyx May 29, 2026
39d7d7b
tuning fixes
Thunderbots May 29, 2026
24a50ac
tuning fixes
Thunderbots May 29, 2026
acedc5a
refactor and localizer fixes
Andrewyx May 31, 2026
244f17c
sim tests
Andrewyx Jun 2, 2026
96c20c1
linting
Andrewyx Jun 2, 2026
1bd2cd9
test fixes
Andrewyx Jun 2, 2026
4b62eae
more euclid change
Andrewyx Jun 2, 2026
9335cb7
more euclid change
Andrewyx Jun 2, 2026
d1f3efb
temporary fix for ai vs ai
nycrat Jun 3, 2026
6e0bc08
reseting
Andrewyx Jun 4, 2026
9c35caf
Merge branch 'Andrewyx/robot_localizer' of github.com:Andrewyx/Softwa…
Andrewyx Jun 4, 2026
f09c6f2
Merge branch 'master' of github.com:UBC-Thunderbots/Software into And…
Andrewyx Jun 5, 2026
810eae0
Merge branch 'master' of github.com:UBC-Thunderbots/Software into And…
Andrewyx Jun 7, 2026
5b3c06c
merged
Andrewyx Jun 10, 2026
f1321f6
Merge master into Andrewyx/robot_localizer
Andrewyx Jun 12, 2026
c13928f
pid
Andrewyx Jun 12, 2026
57f787c
localizer
Andrewyx Jun 12, 2026
9eb4d05
test fixes
Andrewyx Jun 13, 2026
9c8e12f
bugs fixed
Andrewyx Jun 14, 2026
bc13c3c
linting
Andrewyx Jun 14, 2026
3f0e37f
Merge branch 'master' of github.com:UBC-Thunderbots/Software into And…
Andrewyx Jun 14, 2026
66b994a
flags added
Andrewyx Jun 14, 2026
88afd0b
linting
Andrewyx Jun 14, 2026
3821ee2
renamed motors
Andrewyx Jun 14, 2026
ea757d1
prim
Andrewyx Jun 15, 2026
9fc91ad
Merge branch 'master' of github.com:UBC-Thunderbots/Software into And…
Andrewyx Jun 15, 2026
83e8911
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 15, 2026
e7cea8a
localizer tests
Andrewyx Jun 16, 2026
9fd5abb
merged
Andrewyx Jun 16, 2026
7f2ceae
merge fixes
Andrewyx Jun 16, 2026
39a2c16
pi values
Thunderbots Jun 16, 2026
e870f9a
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 16, 2026
6957006
breakout
Andrewyx Jun 17, 2026
80148f1
linting
Andrewyx Jun 17, 2026
bddca1e
Merge branch 'master' of github.com:UBC-Thunderbots/Software into And…
Andrewyx Jun 17, 2026
11d2689
removed unrelated changes
Andrewyx Jun 17, 2026
325aa27
removed unrelated changes
Andrewyx Jun 17, 2026
907725a
removed unrelated changes
Andrewyx Jun 17, 2026
bc73a47
Merge branch 'master' of github.com:UBC-Thunderbots/Software into And…
Andrewyx Jun 17, 2026
18c3d92
reverts
Andrewyx Jun 17, 2026
b2d8adb
limits added
Andrewyx Jun 18, 2026
214ae7e
cleanup
Andrewyx Jun 18, 2026
fac4b71
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 18, 2026
c0f17b7
enable i2c
Andrewyx Jun 19, 2026
fac14bb
Merge branch 'Andrewyx/robot_localizer' of github.com:Andrewyx/Softwa…
Andrewyx Jun 19, 2026
44c311d
Implement new SPI protocol with message delimiting and acknowledgements
williamckha Jun 20, 2026
4378009
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software …
Thunderbots Jun 20, 2026
3216e59
Merge branch 'william/new_spi_protocol' of https://github.com/UBC-Thu…
Thunderbots Jun 20, 2026
d15fcad
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jun 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ git_repository(
name = "mdv6_firmware",
build_file = "@//extlibs:mdv6_firmware.bzl",
# Pinning to the exact commit guarantees Bazel will rebuild when this commit SHA is updated
commit = "97e06b9ce8db1940a033b536cd55b4059943d601", # latest commit on master branch
commit = "0f14b9482985159dd132c6fa012970783b0263c3", # latest commit on master branch
remote = "https://github.com/UBC-Thunderbots/MDv6_Firmware.git",
)

Expand Down
14 changes: 14 additions & 0 deletions src/cli/cli_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ class DebugBinary(str, Enum):
),
]

# Deploy robot software "Options:" checkbox. Each option compiles Thunderloop
# with a preprocessor flag that disables the corresponding service, letting
# Thunderloop run on a robot whose powerboard or motorboard is unavailable.
DEPLOY_ROBOT_SOFTWARE_OPTION_CHOICES = [
questionary.Choice(
title="DISABLE_POWER_SERVICE",
description="Compile Thunderloop without the Power Service (no powerboard)",
),
questionary.Choice(
title="DISABLE_MOTOR_SERVICE",
description="Compile Thunderloop without the Motor Service (no motorboard)",
),
]

# Marker value returned by the DEBUG_POWERLOOP playbook choice. It maps to the
# deploy_powerboard.yml playbook but additionally compiles powerloop_main with
# the DEBUG_POWERLOOP flag, swapping in bare setup()/loop() stubs so arbitrary
Expand Down
3 changes: 3 additions & 0 deletions src/shared/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ static const unsigned THUNDERLOOP_HZ = 300u;

static const unsigned NUM_GENEVA_ANGLES = 5;


static constexpr double RTT_S = 0.03;

// Robot diagnostics constants
constexpr double AUTO_CHIP_DISTANCE_DEFAULT_M = 1.5;
constexpr double AUTO_KICK_SPEED_DEFAULT_M_PER_S = 1.5;
Expand Down
21 changes: 19 additions & 2 deletions src/shared/robot_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ struct RobotConstants
// Found by sqrt(x^2 + y^2) of a wheel.
// Front wheel arm = Rear wheel arm. See ASCII image above.
float expected_lever_arm;

// Various variances for the robot localizer Kalman filter
float kalman_process_noise_variance_rad_per_s_4;

float kalman_vision_noise_variance_rad_2;

float kalman_motor_sensor_noise_variance_rad_per_s_2;
};

/**
Expand Down Expand Up @@ -163,7 +170,12 @@ constexpr RobotConstants createRobotConstants()

.wheel_radius_meters = 0.03f,

.expected_lever_arm = 0.0749f};
.expected_lever_arm = 0.0749f,

// Kalman filter variances for robot localizer
.kalman_process_noise_variance_rad_per_s_4 = 1.0f,
.kalman_vision_noise_variance_rad_2 = 0.01f * 0.01f,
.kalman_motor_sensor_noise_variance_rad_per_s_2 = 0.5f};
}
#elif CHECK_VERSION(2021)
constexpr RobotConstants createRobotConstants()
Expand Down Expand Up @@ -194,7 +206,12 @@ constexpr RobotConstants createRobotConstants()
.robot_trajectory_max_ang_speed_rad_per_s = 7.0f,
.robot_max_ang_acceleration_rad_per_s_2 = 30.0f,

.wheel_radius_meters = 0.03f};
.wheel_radius_meters = 0.03f,

// Kalman filter variances for robot localizer
.kalman_process_noise_variance_rad_per_s_4 = 0.5f,
.kalman_vision_noise_variance_rad_2 = 0.01f * 0.01f,
.kalman_motor_sensor_noise_variance_rad_per_s_2 = 0.5f * 0.5f};
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/evaluation/intercept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Point findOvershootInterceptPosition(const Robot& robot, const Point intercept_p
Point best_position = intercept_position;
double final_speed = step_speed;
bool finished = false;
double max_speed = robot.robotConstants().robot_max_speed_m_per_s;
double max_speed = robot.robotConstants().robot_trajectory_max_speed_m_per_s;
double max_acc = robot.robotConstants().robot_max_acceleration_m_per_s_2;

while (!finished)
Expand Down
2 changes: 2 additions & 0 deletions src/software/ai/hl/stp/play/ball_placement/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ py_test(
srcs = [
"ball_placement_play_test.py",
],
# Flaky: multi-robot simulated play sensitive to sim timing; passes on retry.
flaky = True,
deps = [
"//software:conftest",
"//software/gameplay_tests/validation:validations",
Expand Down
2 changes: 2 additions & 0 deletions src/software/ai/hl/stp/play/kickoff_enemy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ cc_library(
py_test(
name = "kickoff_enemy_play_test",
srcs = ["kickoff_enemy_play_test.py"],
# Flaky: multi-robot simulated play sensitive to sim timing; passes on retry.
flaky = True,
deps = [
"//software:conftest",
"//software/gameplay_tests/validation:validations",
Expand Down
70 changes: 69 additions & 1 deletion src/software/embedded/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")

package(default_visibility = ["//visibility:public"])

# When enabled, compiles Thunderloop with the DISABLE_POWER_SERVICE flag, which
# skips initializing and polling the PowerService so Thunderloop can be run on a
# robot without a functioning powerboard.
bool_flag(
name = "disable_power_service",
build_setting_default = False,
)

config_setting(
name = "disable_power_service_enabled",
flag_values = {
":disable_power_service": "True",
},
)

# When enabled, compiles Thunderloop with the DISABLE_MOTOR_SERVICE flag, which
# skips initializing and polling the MotorService so Thunderloop can be run on a
# robot without a functioning motorboard.
bool_flag(
name = "disable_motor_service",
build_setting_default = False,
)

config_setting(
name = "disable_motor_service_enabled",
flag_values = {
":disable_motor_service": "True",
},
)

config_setting(
name = "build_trinamic",
flag_values = {
Expand Down Expand Up @@ -57,15 +87,24 @@ cc_library(
name = "thunderloop",
srcs = ["thunderloop.cpp"],
hdrs = ["thunderloop.h"],
local_defines = select({
":disable_power_service_enabled": ["DISABLE_POWER_SERVICE"],
"//conditions:default": [],
}) + select({
":disable_motor_service_enabled": ["DISABLE_MOTOR_SERVICE"],
"//conditions:default": [],
}),
deps = [
":primitive_executor",
"//proto:tbots_cc_proto",
"//software/embedded:robot_localizer",
"//software/embedded/services:imu",
"//software/embedded/services:motor",
"//software/embedded/services:power",
"//software/embedded/services/network",
"//software/embedded/toml_config",
"//software/logger:network_logger",
"//software/physics:velocity_conversion_util",
"//software/tracy:tracy_constants",
"//software/util/scoped_timespec_timer",
"@tracy",
Expand Down Expand Up @@ -108,3 +147,32 @@ cc_test(
"//shared/test_util:tbots_gtest_main",
],
)

cc_library(
name = "robot_localizer",
srcs = ["robot_localizer.cpp"],
hdrs = ["robot_localizer.h"],
deps = [
"//proto:tbots_cc_proto",
"//software:constants",
"//software/embedded/services:imu",
"//software/geom:angle",
"//software/geom:angular_velocity",
"//software/geom:point",
"//software/geom:vector",
"//software/sensor_fusion/filter:kalman_filter",
"//software/util/scoped_timespec_timer",
"@eigen",
],
)

cc_test(
name = "robot_localizer_test",
srcs = ["robot_localizer_test.cpp"],
deps = [
":robot_localizer",
"//shared:constants",
"//shared/test_util:tbots_gtest_main",
"//software/physics:velocity_conversion_util",
],
)
4 changes: 2 additions & 2 deletions src/software/embedded/linux_configs/pi/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Some settings may impact device functionality. See link above for details

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on

# Enable audio (loads snd_bcm2835)
Expand Down
3 changes: 0 additions & 3 deletions src/software/embedded/motion_control/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ cc_library(

cc_library(
name = "pid_controller",
srcs = [
"pid_controller.cpp",
],
hdrs = [
"pid_controller.h",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OrientationController

private:
// TODO(#3737): tune constants
PidController w_pid_{0.4, 0.0, 0.0, 0.0};
PidController<double> w_pid_{0.4, 0.0, 0.0, 0.0};

static constexpr double ANGULAR_DESTINATION_THRESHOLD_DEGREES = 5;
};
27 changes: 0 additions & 27 deletions src/software/embedded/motion_control/pid_controller.cpp

This file was deleted.

62 changes: 45 additions & 17 deletions src/software/embedded/motion_control/pid_controller.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#pragma once

#include <algorithm>
#include <cassert>
#include <optional>

/**
* A PID controller is used to calculate corrections based on error values over
* time as the difference between a desired value and the actual measured value.
* This PID controller also limits integral windup using a max_integral value.
*
* Resources:
* - https://raw.org/book/control-theory/introduction-to-pid-controllers/
* - http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-reset-windup/
*/
template <typename T>
Comment thread
Andrewyx marked this conversation as resolved.
class PidController
{
public:
/**
* Constructs a new PID controller.
*
* A PID controller is used to calculate corrections based on error values over
* time as the difference between a desired value and the actual measured value.
* This PID controller also limits integral windup using a max_integral value.
*
* Resources:
* - https://raw.org/book/control-theory/introduction-to-pid-controllers/
* - http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-reset-windup/
*
* @pre max_integral must be >= 0.0
*
* @param k_p The proportional gain.
Expand All @@ -24,7 +28,11 @@ class PidController
* @param max_integral The maximum absolute value that the integrator term can
* accumulate to.
**/
PidController(double k_p, double k_i, double k_d, double max_integral);
PidController(T k_p, T k_i, T k_d, T max_integral)
: k_p_(k_p), k_i_(k_i), k_d_(k_d), max_integral_(max_integral)
{
assert(max_integral >= T(0.0));
}

/**
* Given an error, returns the control effort to minimize it.
Expand All @@ -33,19 +41,39 @@ class PidController
* @param delta_time The time passed since last step, for calculating the integrator
* and derivative.
**/
double step(double error, double delta_time);
T step(T error, T delta_time = T(1.0))
{
// If sign of error swaps, reset integrator
if (last_error_.has_value() && (last_error_.value() * error < T(0.0)))
{
integral_ = T(0.0);
}

integral_ =
std::clamp(integral_ + error * delta_time, -max_integral_, max_integral_);

const T derivative = (error - last_error_.value_or(error)) / delta_time;

last_error_ = error;

return error * k_p_ + integral_ * k_i_ + derivative * k_d_;
}

/**
* Resets the integrator and clears the last error used for derivative calculation.
**/
void reset();
void reset()
{
integral_ = T(0.0);
last_error_ = std::nullopt;
}

private:
double k_p_;
double k_i_;
double k_d_;
double max_integral_;
T k_p_;
T k_i_;
T k_d_;
T max_integral_;

double integral_ = 0.0;
std::optional<double> last_error_ = std::nullopt;
T integral_ = T(0.0);
std::optional<T> last_error_ = std::nullopt;
};
Loading
Loading