Browse Source

Add direct knee offset for standing height control

Planner height input doesn't produce visible knee bend in IDLE mode.
Instead, add a direct offset to both knee motor targets (+5 deg default).
Runtime-adjustable via keys 3/4 (±1 deg). This shifts the standing
equilibrium lower without changing the NN's learned dynamics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
main
Joe DiPrima 4 weeks ago
parent
commit
e4b42f85e6
  1. 18
      gear_sonic_deploy/src/g1/g1_deploy_onnx_ref/include/input_interface/gamepad_manager.hpp
  2. 6
      gear_sonic_deploy/src/g1/g1_deploy_onnx_ref/src/g1_deploy_onnx_ref.cpp

18
gear_sonic_deploy/src/g1/g1_deploy_onnx_ref/include/input_interface/gamepad_manager.hpp

@ -58,6 +58,10 @@ inline std::atomic<double> g_waist_pitch_offset_deg{0.0};
/// Lowered from planner default 0.789m to add knee bend. /// Lowered from planner default 0.789m to add knee bend.
inline std::atomic<double> g_standing_height_m{0.72}; inline std::atomic<double> g_standing_height_m{0.72};
/// Runtime-adjustable knee offset (degrees). Keys 3/4 to adjust via tmux.
/// Positive = more bent knees = lower stance. Applied to both knees equally.
inline std::atomic<double> g_knee_offset_deg{5.0};
#if HAS_ROS2 #if HAS_ROS2
#include "ros2_input_handler.hpp" #include "ros2_input_handler.hpp"
#endif #endif
@ -175,6 +179,20 @@ class GamepadManager : public InputInterface {
is_manager_key = true; is_manager_key = true;
break; break;
} }
case '3': {
double val = g_knee_offset_deg.load() - 1.0;
g_knee_offset_deg.store(val);
std::cout << "[KNEE] Offset: " << val << " deg" << std::endl;
is_manager_key = true;
break;
}
case '4': {
double val = g_knee_offset_deg.load() + 1.0;
g_knee_offset_deg.store(val);
std::cout << "[KNEE] Offset: " << val << " deg" << std::endl;
is_manager_key = true;
break;
}
} }
if (!is_manager_key && current_) { if (!is_manager_key && current_) {

6
gear_sonic_deploy/src/g1/g1_deploy_onnx_ref/src/g1_deploy_onnx_ref.cpp

@ -2841,6 +2841,12 @@ class G1Deploy {
if (waist_offset_rad != 0.0) { if (waist_offset_rad != 0.0) {
motor_command_tmp.q_target.at(14) += static_cast<float>(waist_offset_rad); motor_command_tmp.q_target.at(14) += static_cast<float>(waist_offset_rad);
} }
// Optional knee offset (keys 3/4). Default +5°. Positive = more bent.
double knee_offset_rad = g_knee_offset_deg.load() * M_PI / 180.0;
if (knee_offset_rad != 0.0) {
motor_command_tmp.q_target.at(3) += static_cast<float>(knee_offset_rad); // LeftKnee
motor_command_tmp.q_target.at(9) += static_cast<float>(knee_offset_rad); // RightKnee
}
// Debug: log raw NN actions + measured positions for waist joints every 1s // Debug: log raw NN actions + measured positions for waist joints every 1s
static int waist_dbg_ctr = 0; static int waist_dbg_ctr = 0;

Loading…
Cancel
Save