Skip to content

Add balance control to foot controller #1636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 66 commits into
base: main
Choose a base branch
from

Conversation

Crafty15
Copy link
Collaborator

@Crafty15 Crafty15 commented Jun 30, 2025

  • Balance code stolen from Tom's old branch here, with the only major change being the use of gyro for roll/pitch rates.
  • This PR allows torso correction to be applied to FootControl tasks.
  • So far has been tested on spline kick and the walk. Limited success with spline kick unless gains are turned right up, leading to oscillations. Walk seemed decent with low gains.
    • More testing might be required on what happens when the robot falls. The delay in fall detection could cause some wild behaviour. I wonder if that could have contributed to Kevin's knees giving out recently.

P.S. It's probably not critical that we have this in and use it for robocup. I was thinking it might help with the tilting during get ups and starting to walk again when the batteries get low.

@Crafty15 Crafty15 marked this pull request as ready for review July 1, 2025 09:13
@Crafty15 Crafty15 requested review from ysims and Tom0Brien July 1, 2025 09:13
Comment on lines 60 to 61
void FusedFromQuat(const Eigen::Quaterniond& q, double& fusedPitch, double& fusedRoll);
Eigen::Quaterniond QuatFromFused(double fusedPitch, double fusedRoll);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation directives. These also look like they should be inside the class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh these should be replaced with standard roll/pitch/yaw euler utilities (rpy_intrinsic_to_mat)

FusedFromQuat(Hwt_quat, fused_pitch, fused_roll);

if (log_level <= DEBUG) {
// graph the correction being applied
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// graph the correction being applied
// Graph the correction being applied

/// derivative calculations.
NUClear::clock::time_point last_update_time{};

public:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these functions seem like they're just used within the class, so they should be in the private section?

Comment on lines 259 to 271
// Conversion: Quaternion --> Fused angles (2D)
void FusedFromQuat(const Eigen::Quaterniond& q, double& fusedPitch, double& fusedRoll) {
// Calculate the fused pitch and roll
double stheta = 2.0 * (q.y() * q.w() - q.x() * q.z());
double sphi = 2.0 * (q.y() * q.z() + q.x() * q.w());
stheta = (stheta >= 1.0 ? 1.0 : (stheta <= -1.0 ? -1.0 : stheta)); // Coerce stheta to [-1,1]
sphi = (sphi >= 1.0 ? 1.0 : (sphi <= -1.0 ? -1.0 : sphi)); // Coerce sphi to [-1,1]
fusedPitch = asin(stheta);
fusedRoll = asin(sphi);
}

Eigen::Quaterniond QuatFromFused(double fusedPitch, double fusedRoll) // Assume: fusedYaw = 0, hemi = true
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move implementation to cpp?

@@ -17,3 +19,17 @@ servo_gains:
R_KNEE: 30
R_ANKLE_PITCH: 30
R_ANKLE_ROLL: 30

balance:
enabled: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there much of a reason to have this? It seems like all the modules (kick and walk) that use the balance control have their own configs that get passed into this module.

@@ -90,6 +90,9 @@ namespace utility::skill {

/// @brief Option to only switch between planted foot if the next foot is planted
bool only_switch_when_planted = false;

/// @brief Option to use balance control when walking
bool use_balance_control = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never used for walk generator stuff, so I think it should be moved to a variable on the walk/kick class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a check for the amount of error to prevent issues if the robot falls over, so if the robot is X degrees from desired setpoint, pause applying control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants