diff --git a/include/ap1/control/control_node.hpp b/include/ap1/control/control_node.hpp index a130b04..0a5a840 100644 --- a/include/ap1/control/control_node.hpp +++ b/include/ap1/control/control_node.hpp @@ -11,11 +11,9 @@ #include "rclcpp/rclcpp.hpp" -#include "ap1_msgs/msg/motor_power_stamped.hpp" #include "ap1_msgs/msg/speed_profile_stamped.hpp" #include "ap1_msgs/msg/target_path_stamped.hpp" -#include "ap1_msgs/msg/turn_angle_stamped.hpp" -#include "ap1_msgs/msg/vehicle_speed_stamped.hpp" +#include "ap1_msgs/msg/float_stamped.hpp" #include "ap1/control/ackermann_controller.hpp" #include "ap1/control/icontroller.hpp" @@ -40,24 +38,24 @@ class ControlNode : public rclcpp::Node // stamped double or something ap1_msgs::msg::SpeedProfileStamped speed_profile_; ap1_msgs::msg::TargetPathStamped target_path_; - ap1_msgs::msg::VehicleSpeedStamped vehicle_speed_; - ap1_msgs::msg::TurnAngleStamped vehicle_turn_angle; + ap1_msgs::msg::FloatStamped vehicle_speed_; + ap1_msgs::msg::FloatStamped vehicle_turn_angle; // Subs rclcpp::Subscription::SharedPtr target_path_sub_; rclcpp::Subscription::SharedPtr speed_profile_sub_; - rclcpp::Subscription::SharedPtr vehicle_speed_sub_; - rclcpp::Subscription::SharedPtr vehicle_turn_angle_sub_; + rclcpp::Subscription::SharedPtr vehicle_speed_sub_; + rclcpp::Subscription::SharedPtr vehicle_turn_angle_sub_; // Pubs - rclcpp::Publisher::SharedPtr turning_angle_pub_; - rclcpp::Publisher::SharedPtr motor_power_pub_; // between -1 and 1? probably + rclcpp::Publisher::SharedPtr turning_angle_pub_; + rclcpp::Publisher::SharedPtr motor_power_pub_; // between -1 and 1? probably // Methods void on_speed_profile(const ap1_msgs::msg::SpeedProfileStamped speed_profile); void on_path(const ap1_msgs::msg::TargetPathStamped target_path); - void on_speed(const ap1_msgs::msg::VehicleSpeedStamped speed); - void on_turn_angle(const ap1_msgs::msg::TurnAngleStamped turn_angle); + void on_speed(const ap1_msgs::msg::FloatStamped speed); + void on_turn_angle(const ap1_msgs::msg::FloatStamped turn_angle); void control_loop_callback(); public: diff --git a/src/control_node.cpp b/src/control_node.cpp index 29d9812..9e1d6ec 100644 --- a/src/control_node.cpp +++ b/src/control_node.cpp @@ -9,11 +9,9 @@ #include "rclcpp/rclcpp.hpp" -#include "ap1_msgs/msg/motor_power_stamped.hpp" #include "ap1_msgs/msg/speed_profile_stamped.hpp" #include "ap1_msgs/msg/target_path_stamped.hpp" -#include "ap1_msgs/msg/turn_angle_stamped.hpp" -#include "ap1_msgs/msg/vehicle_speed_stamped.hpp" +#include "ap1_msgs/msg/float_stamped.hpp" #include "ap1/control/control_node.hpp" #include "ap1/control/icontroller.hpp" @@ -33,20 +31,20 @@ void ControlNode::on_path(const TargetPathStamped target_path) target_path_ = target_path; } -void ControlNode::on_speed(const VehicleSpeedStamped speed) +void ControlNode::on_speed(const FloatStamped & msg) { - vehicle_speed_ = speed; + vehicle_speed_ = msg.value; } -void ControlNode::on_turn_angle(const TurnAngleStamped turn_angle) +void ControlNode::on_turn_angle(const FloatStamped & msg) { - vehicle_turn_angle = turn_angle; + vehicle_turn_angle = msg.value; } void ControlNode::control_loop_callback() { // the car's current velocity. we only support moving forward atp - const vec3f velocity(this->vehicle_speed_.speed, 0, 0); // +x is always forward on the car + const vec3f velocity(this->vehicle_speed_, 0, 0); // +x is always forward on the car const bool PATH_IS_STALE = false, SPEED_PROFILE_IS_STALE = false; // TEMP @@ -77,16 +75,16 @@ void ControlNode::control_loop_callback() RCLCPP_INFO(this->get_logger(), "CMD: {throttle: %.2f, steering: %.2f}", cmd.throttle, cmd.steering); // pack the turn angle into a message - TurnAngleStamped turn_msg; + FloatStamped turn_msg; turn_msg.header.stamp = this->now(); turn_msg.header.frame_id = "base_link"; - turn_msg.angle = cmd.steering; // rads + turn_msg.value = cmd.steering; // rads // pack the power into a message - MotorPowerStamped pwr_msg; + FloatStamped pwr_msg; pwr_msg.header.stamp = this->now(); pwr_msg.header.frame_id = "base_link"; - pwr_msg.power = cmd.throttle; // [-1, 1] + pwr_msg.value = cmd.throttle; // [-1, 1] // pwr_msg.power = 1.0f; // send both messages out @@ -105,16 +103,16 @@ ControlNode::ControlNode(const std::string& cfg_path, float rate_hz) target_path_sub_ = this->create_subscription( "ap1/planning/target_path", 10, std::bind(&ControlNode::on_path, this, std::placeholders::_1)); - vehicle_speed_sub_ = this->create_subscription( + vehicle_speed_sub_ = this->create_subscription( "ap1/actuation/speed_actual", 10, std::bind(&ControlNode::on_speed, this, std::placeholders::_1)); - vehicle_turn_angle_sub_ = this->create_subscription( + vehicle_turn_angle_sub_ = this->create_subscription( "ap1/actuation/turn_angle_actual", 10, std::bind(&ControlNode::on_turn_angle, this, std::placeholders::_1)); // Pubs - turning_angle_pub_ = this->create_publisher("ap1/control/turn_angle", 10); - motor_power_pub_ = this->create_publisher("ap1/control/motor_power", 10); + turning_angle_pub_ = this->create_publisher("ap1/control/turn_angle", 10); + motor_power_pub_ = this->create_publisher("ap1/control/motor_power", 10); // Create Control Loop timer_ = this->create_wall_timer(std::chrono::duration(1.0 / rate_hz),