generated from wessel/boilerplate
fix(rename): Rename left over axis variables to object variables
This commit is contained in:
@@ -42,12 +42,12 @@ void DataSimulator::publish_imu_data() {
|
||||
double elapsed_time = (this->now() - start_time_).seconds();
|
||||
|
||||
// Get values for each axis
|
||||
imu_msg->linear_acceleration.x = simulator_->get_axis_value("linear_x", elapsed_time);
|
||||
imu_msg->linear_acceleration.y = simulator_->get_axis_value("linear_y", elapsed_time);
|
||||
imu_msg->linear_acceleration.z = simulator_->get_axis_value("linear_z", elapsed_time);
|
||||
imu_msg->angular_velocity.x = simulator_->get_axis_value("angular_x", elapsed_time);
|
||||
imu_msg->angular_velocity.y = simulator_->get_axis_value("angular_y", elapsed_time);
|
||||
imu_msg->angular_velocity.z = simulator_->get_axis_value("angular_z", elapsed_time);
|
||||
imu_msg->linear_acceleration.x = simulator_->get_object_value("linear_x", elapsed_time);
|
||||
imu_msg->linear_acceleration.y = simulator_->get_object_value("linear_y", elapsed_time);
|
||||
imu_msg->linear_acceleration.z = simulator_->get_object_value("linear_z", elapsed_time);
|
||||
imu_msg->angular_velocity.x = simulator_->get_object_value("angular_x", elapsed_time);
|
||||
imu_msg->angular_velocity.y = simulator_->get_object_value("angular_y", elapsed_time);
|
||||
imu_msg->angular_velocity.z = simulator_->get_object_value("angular_z", elapsed_time);
|
||||
|
||||
RCLCPP_INFO(this->get_logger(),
|
||||
"t=%.2fs - Accel: [%.3f, %.3f, %.3f], Gyro: [%.3f, %.3f, %.3f]",
|
||||
|
||||
@@ -35,18 +35,15 @@ DataSimulator::~DataSimulator() {
|
||||
void DataSimulator::publish_wheel_data() {
|
||||
auto wheel_msg = std::make_shared<std_msgs::msg::Float64MultiArray>();
|
||||
|
||||
// wheel_msg->header.stamp = this->now();
|
||||
// wheel_msg->header.frame_id = "wheel_link";
|
||||
|
||||
// Calculate elapsed time since node start
|
||||
double elapsed_time = (this->now() - start_time_).seconds();
|
||||
|
||||
// For now, just log wheel values (adjust based on your actual message type)
|
||||
wheel_msg->data = {
|
||||
simulator_->get_axis_value("wheel_fl", elapsed_time),
|
||||
simulator_->get_axis_value("wheel_fr", elapsed_time),
|
||||
simulator_->get_axis_value("wheel_rl", elapsed_time),
|
||||
simulator_->get_axis_value("wheel_rr", elapsed_time)
|
||||
simulator_->get_object_value("wheel_fl", elapsed_time),
|
||||
simulator_->get_object_value("wheel_fr", elapsed_time),
|
||||
simulator_->get_object_value("wheel_rl", elapsed_time),
|
||||
simulator_->get_object_value("wheel_rr", elapsed_time)
|
||||
};
|
||||
|
||||
RCLCPP_INFO(this->get_logger(),
|
||||
|
||||
@@ -4,27 +4,26 @@
|
||||
namespace assignments::three
|
||||
{
|
||||
|
||||
Simulator::Simulator(rclcpp::Node* node, const std::vector<std::string>& axes) {
|
||||
load_intervals(node, axes);
|
||||
Simulator::Simulator(rclcpp::Node* node, const std::vector<std::string>& objects) {
|
||||
load_intervals(node, objects);
|
||||
}
|
||||
|
||||
Simulator::~Simulator() {
|
||||
}
|
||||
|
||||
void Simulator::load_intervals(rclcpp::Node* node, const std::vector<std::string>& axes) {
|
||||
void Simulator::load_intervals(rclcpp::Node* node, const std::vector<std::string>& objects) {
|
||||
node->declare_parameter("max_intervals", 4);
|
||||
max_intervals_ = node->get_parameter("max_intervals").as_int();
|
||||
|
||||
for (const auto& axis : axes) {
|
||||
node->declare_parameter(axis + ".num_intervals", 0);
|
||||
int num_intervals = node->get_parameter(axis + ".num_intervals").as_int();
|
||||
|
||||
RCLCPP_INFO(node->get_logger(), "Loading %d intervals for axis '%s'", num_intervals, axis.c_str());
|
||||
for (const auto& object : objects) {
|
||||
node->declare_parameter(object + ".num_intervals", 0);
|
||||
int num_intervals = node->get_parameter(object + ".num_intervals").as_int();
|
||||
|
||||
RCLCPP_INFO(node->get_logger(), "Loading %d intervals for object '%s'", num_intervals, object.c_str());
|
||||
std::vector<IntervalConfig> intervals;
|
||||
|
||||
for (int i = 0; i < std::min(num_intervals, max_intervals_); i++) {
|
||||
std::string prefix = axis + ".interval_" + std::to_string(i);
|
||||
std::string prefix = object + ".interval_" + std::to_string(i);
|
||||
|
||||
node->declare_parameter(prefix + ".type", "constant");
|
||||
node->declare_parameter(prefix + ".t_start", 0.0);
|
||||
@@ -61,13 +60,13 @@ void Simulator::load_intervals(rclcpp::Node* node, const std::vector<std::string
|
||||
const char* type_str = (cfg.type == SimType::CONSTANT) ? "constant" :
|
||||
(cfg.type == SimType::LINEAR) ? "linear" : "quadratic";
|
||||
RCLCPP_DEBUG(node->get_logger(),
|
||||
"Axis '%s' Interval %zu: type='%s', t_start=%.6f, t_end=%.6f, y_start=%.6f, y_end=%.6f, t_mid=%.6f, y_mid=%.6f",
|
||||
axis.c_str(), j, type_str,
|
||||
"Object '%s' Interval %zu: type='%s', t_start=%.6f, t_end=%.6f, y_start=%.6f, y_end=%.6f, t_mid=%.6f, y_mid=%.6f",
|
||||
object.c_str(), j, type_str,
|
||||
cfg.t_start, cfg.t_end, cfg.y_start, cfg.y_end, cfg.t_mid, cfg.y_mid
|
||||
);
|
||||
}
|
||||
|
||||
axis_intervals_[axis] = intervals;
|
||||
object_intervals_[object] = intervals;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,14 +114,14 @@ double Simulator::compute_value(double t, const IntervalConfig& interval) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double Simulator::get_axis_value(const std::string& axis, double t) {
|
||||
// Check if axis exists in configuration
|
||||
auto it = axis_intervals_.find(axis);
|
||||
if (it == axis_intervals_.end()) {
|
||||
return 0.0; // Default value if axis not configured
|
||||
double Simulator::get_object_value(const std::string& object, double t) {
|
||||
// Check if object exists in configuration
|
||||
auto it = object_intervals_.find(object);
|
||||
if (it == object_intervals_.end()) {
|
||||
return 0.0; // Default value if object not configured
|
||||
}
|
||||
|
||||
// Check each interval for this axis
|
||||
// Check each interval for this object
|
||||
double last_value = 0.0;
|
||||
for (const auto& interval : it->second) {
|
||||
if (t >= interval.t_start && t <= interval.t_end) {
|
||||
|
||||
@@ -25,18 +25,18 @@ struct IntervalConfig {
|
||||
|
||||
class Simulator {
|
||||
public:
|
||||
Simulator(rclcpp::Node* node, const std::vector<std::string>& axes);
|
||||
Simulator(rclcpp::Node* node, const std::vector<std::string>& objects);
|
||||
~Simulator();
|
||||
|
||||
double get_axis_value(const std::string& axis, double t);
|
||||
double get_object_value(const std::string& object, double t);
|
||||
|
||||
private:
|
||||
int max_intervals_;
|
||||
|
||||
void load_intervals(rclcpp::Node* node, const std::vector<std::string>& axes);
|
||||
void load_intervals(rclcpp::Node* node, const std::vector<std::string>& objects);
|
||||
double compute_value(double t, const IntervalConfig& interval);
|
||||
|
||||
std::map<std::string, std::vector<IntervalConfig>> axis_intervals_;
|
||||
std::map<std::string, std::vector<IntervalConfig>> object_intervals_;
|
||||
};
|
||||
|
||||
} // namespace assignments::three
|
||||
|
||||
Reference in New Issue
Block a user