Skip to content
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

PID Error Graphs #2328

Merged
merged 15 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions soccer/src/soccer/control/motion_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ MotionControl::MotionControl(int shell_id, rclcpp::Node* node)
[this](PlayState::Msg::SharedPtr play_state_msg) { // NOLINT
play_state_ = rj_convert::convert_from_ros(*play_state_msg).state();
});

error_x_pub_ =
node->create_publisher<std_msgs::msg::Float64>("debug/motion_control/pose_error_x", 10);
error_y_pub_ =
node->create_publisher<std_msgs::msg::Float64>("debug/motion_control/pose_error_y", 10);
error_heading_pub_ = node->create_publisher<std_msgs::msg::Float64>(
"debug/motion_control/pose_error_heading", 10);
}

void MotionControl::run(const RobotState& state, const planning::Trajectory& trajectory,
Expand Down Expand Up @@ -121,9 +128,29 @@ void MotionControl::run(const RobotState& state, const planning::Trajectory& tra
// TODO(Kyle): Clamp acceleration

Twist correction = Twist::zero();

if (maybe_pose_target) {
Pose error = maybe_pose_target.value() - state.pose;
error.heading() = fix_angle_radians(error.heading());

if (error_x_pub_->get_subscription_count() > 0) {
std_msgs::msg::Float64 error_x_msg;
error_x_msg.data = error.position().x();
error_x_pub_->publish(error_x_msg);
}

if (error_y_pub_->get_subscription_count() > 0) {
std_msgs::msg::Float64 error_y_msg;
error_y_msg.data = error.position().y();
error_y_pub_->publish(error_y_msg);
}

if (error_heading_pub_->get_subscription_count() > 0) {
std_msgs::msg::Float64 error_heading_msg;
error_heading_msg.data = error.heading();
error_heading_pub_->publish(error_heading_msg);
}

correction = Twist(position_x_controller_.run(static_cast<float>(error.position().x())),
position_y_controller_.run(static_cast<float>(error.position().y())),
angle_controller_.run(static_cast<float>(error.heading())));
Expand Down
6 changes: 6 additions & 0 deletions soccer/src/soccer/control/motion_control.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include <rclcpp/rclcpp.hpp>

#include <context.hpp>
#include <rj_common/time.hpp>
#include <rj_constants/topic_names.hpp>
#include <rj_geometry/point.hpp>
#include <rj_param_utils/param.hpp>
#include <std_msgs/msg/float64.hpp>

#include "control/motion_setpoint.hpp"
#include "game_state.hpp"
Expand Down Expand Up @@ -95,6 +98,9 @@ class MotionControl {
rclcpp::Subscription<PlayState::Msg>::SharedPtr play_state_sub_;
rclcpp::Publisher<MotionSetpoint::Msg>::SharedPtr motion_setpoint_pub_;
rclcpp::Publisher<RobotState::Msg>::SharedPtr target_state_pub_;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr error_x_pub_;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr error_y_pub_;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr error_heading_pub_;
};

} // namespace control
Loading