-
Notifications
You must be signed in to change notification settings - Fork 1
Implement reset functionality for control module #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rate_hz: 20 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| control_node: | ||
| ros__parameters: | ||
| rate_hz: 20 | ||
| turn_kp: 0.5 | ||
| turn_ki: 0.1 | ||
| turn_kd: 0.05 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,61 +8,72 @@ | |
|
|
||
| #include <iostream> | ||
| #include <string> | ||
| #include <memory> | ||
| #include <filesystem> | ||
| #include <chrono> | ||
|
|
||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "yaml-cpp/yaml.h" | ||
|
|
||
| #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 "std_srvs/srv/trigger.hpp" | ||
|
|
||
| #include "ap1/control/ackermann_controller.hpp" | ||
| #include "ap1/control/icontroller.hpp" | ||
|
|
||
| namespace ap1::control | ||
| { | ||
|
|
||
| class ControlNode : public rclcpp::Node | ||
| { | ||
| private: | ||
| // Fields | ||
| public: | ||
| // Constructor with config path + default rate | ||
| ControlNode(const std::string &cfg_path, float rate_hz = 60); | ||
|
|
||
| // Control Loop | ||
| const double rate_hz_; | ||
| rclcpp::TimerBase::SharedPtr timer_; | ||
| private: | ||
| void load_config(); | ||
|
|
||
| std::string config_path_; | ||
| int rate_hz_{60}; | ||
|
|
||
| // Controller | ||
| std::unique_ptr<IController> controller_; | ||
| AckermannController ackermann_controller_; | ||
|
|
||
| // Memory | ||
| // half these types are very unnecessary, we should just have stampedfloat or | ||
| // 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::TurnAngleStamped vehicle_turn_angle_; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
| // Subs | ||
| rclcpp::Subscription<ap1_msgs::msg::TargetPathStamped>::SharedPtr target_path_sub_; | ||
| rclcpp::Subscription<ap1_msgs::msg::SpeedProfileStamped>::SharedPtr speed_profile_sub_; | ||
| rclcpp::Subscription<ap1_msgs::msg::VehicleSpeedStamped>::SharedPtr vehicle_speed_sub_; | ||
| rclcpp::Subscription<ap1_msgs::msg::TurnAngleStamped>::SharedPtr vehicle_turn_angle_sub_; | ||
|
|
||
| // Pubs | ||
| void on_speed_profile(const ap1_msgs::msg::SpeedProfileStamped msg); | ||
| void on_path(const ap1_msgs::msg::TargetPathStamped msg); | ||
| void on_speed(const ap1_msgs::msg::VehicleSpeedStamped msg); | ||
| void on_turn_angle(const ap1_msgs::msg::TurnAngleStamped msg); | ||
|
|
||
|
|
||
| rclcpp::Publisher<ap1_msgs::msg::TurnAngleStamped>::SharedPtr turning_angle_pub_; | ||
| rclcpp::Publisher<ap1_msgs::msg::MotorPowerStamped>::SharedPtr motor_power_pub_; // between -1 and 1? probably | ||
| rclcpp::Publisher<ap1_msgs::msg::MotorPowerStamped>::SharedPtr motor_power_pub_; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you move the class methods to be between the subscriptions and publishers? |
||
| // 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); | ||
| rclcpp::TimerBase::SharedPtr timer_; | ||
| void control_loop_callback(); | ||
|
|
||
| public: | ||
| ControlNode(const std::string& cfg_path, float rate_hz = 60); | ||
|
|
||
| rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr reset_service_; | ||
|
|
||
| void handle_reset( | ||
| const std::shared_ptr<std_srvs::srv::Trigger::Request>, | ||
| std::shared_ptr<std_srvs::srv::Trigger::Response> response); | ||
| }; | ||
|
|
||
| } // namespace ap1::control | ||
|
|
||
| #endif // AP1_CONTROL_NODE_HPP | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| <?xml version="1.0"?> | ||
| <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
| <package format="3"> | ||
| <name>ap1_control</name> | ||
| <version>0.1.0</version> | ||
| <description>AP1 Control Node</description> | ||
|
|
||
| <maintainer email="alyashour1@gmail.com">Aly Ashour</maintainer> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change Ashour lmao |
||
| <license>MIT</license> | ||
|
|
||
|
|
@@ -13,9 +13,8 @@ | |
| <depend>std_msgs</depend> | ||
| <depend>geometry_msgs</depend> | ||
| <depend>ap1_msgs</depend> | ||
|
|
||
| <test_depend>ament_lint_auto</test_depend> | ||
| <test_depend>ament_lint_common</test_depend> | ||
| <depend>std_srvs</depend> | ||
| <depend>yaml-cpp</depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!