4#include "message_filters/message_traits.h"
5#include "message_filters/sync_policies/approximate_time.h"
6#include "message_filters/time_synchronizer.h"
14 declare_parameter<double>(
"ebs_test_ideal_velocity");
15 declare_parameter<double>(
"ebs_test_gain");
16 declare_parameter<double>(
"inspection_ideal_velocity");
17 declare_parameter<double>(
"inspection_gain");
21 this->create_publisher<custom_interfaces::msg::ControlCommand>(
"/control/command", 10);
24 _finish_client_ = this->create_client<std_srvs::srv::Trigger>(
"/as_srv/mission_finished");
31 this->create_subscription<custom_interfaces::msg::OperationalStatus>(
32 "/vehicle/operational_status", 10,
35 _timer_ = this->create_wall_timer(
36 std::chrono::milliseconds(10),
40 "/vehicle/motor_rpm", 10,
43 RCLCPP_INFO(this->get_logger(),
"Inspection node has been started.");
49 custom_interfaces::msg::OperationalStatus::SharedPtr mission_signal) {
50 std::string mission_string =
55 if (mission_signal->as_mission == common_lib::competition_logic::Mission::INSPECTION) {
58 this->
_mission_ = common_lib::competition_logic::Mission::INSPECTION;
66 RCLCPP_WARN(this->get_logger(),
"Invalid mission for inspection: %s", mission_string.c_str());
69 }
catch (
const rclcpp::exceptions::ParameterNotDeclaredException& exception) {
70 RCLCPP_ERROR(this->get_logger(),
"Parameter not declared: %s", exception.what());
74 if (mission_signal->go_signal !=
_go_ && mission_signal->go_signal) {
75 RCLCPP_INFO(this->get_logger(),
"Starting timer");
82 _go_ = mission_signal->go_signal;
86 RCLCPP_DEBUG(this->get_logger(),
"Motor RPM: %f", motor_rpm.rr_rpm);
91 if (!
_go_ ||
_mission_ == common_lib::competition_logic::Mission::NONE) {
94 RCLCPP_DEBUG(this->get_logger(),
"Executing Inspection Script.");
98 RCLCPP_DEBUG(this->get_logger(),
"Mission is over. Stopping the car.");
108 auto current_time = this->
_clock_.now();
111 RCLCPP_DEBUG(this->get_logger(),
"average_rpm %f", average_rpm);
113 RCLCPP_DEBUG(this->get_logger(),
"current_velocity %f", current_velocity);
116 double calculated_steering =
_mission_ == common_lib::competition_logic::Mission::INSPECTION
121 bool steering_straight = calculated_steering < 0.1 && calculated_steering > -0.1;
124 if (steering_straight) {
134 calculated_throttle = 0.0;
142 calculated_steering = 0.0;
154 RCLCPP_DEBUG(this->get_logger(),
155 "Publishing control command. Steering: %lf; Torque after conversion - before: %lf - "
156 "%lf; Elapsed Time: %lf",
157 calculated_steering, scaled_throttle, calculated_throttle, elapsed_time);
164 custom_interfaces::msg::ControlCommand control_command;
165 control_command.throttle_rl = control_command.throttle_rr = throttle;
166 control_command.steering = steering;
173 RCLCPP_INFO(this->get_logger(),
"Sending ending signal...");
174 if (this->
_mission_ == common_lib::competition_logic::Mission::INSPECTION) {
176 std::make_shared<std_srvs::srv::Trigger::Request>(),
185 this->get_logger(),
"Invalid mission at mission end: %s",
191 rclcpp::Client<std_srvs::srv::Trigger>::SharedFuture future)
const {
192 auto result = future.get();
193 if (result->success) {
195 RCLCPP_INFO(this->get_logger(),
"Mission has been finished!");
197 RCLCPP_ERROR(this->get_logger(),
"Mission could not be finished!");
void redefine_goal_velocity(double current_velocity)
used when in oscilation mode to redefine the ideal velocity
double calculate_throttle(double current_velocity) const
calculate torque output according to velocity
bool stop_oscilating_
Used to stop the oscilation near zero and avoid violent wheel movements.
double throttle_to_adequate_range(double throttle) const
convert the throttle to a range between -1 and 1
double current_goal_velocity_
double rpm_to_velocity(double rpm) const
convert rpm [rotations/minute] to velocity [m/s]
double calculate_steering(double time) const
calculate the steering angle according to time
rclcpp::Subscription< custom_interfaces::msg::OperationalStatus >::SharedPtr _mission_signal_subscription_
rclcpp::Clock _clock_
Timer for main callback.
void publish_controls(double throttle, double steering) const
Publishes the control command.
void inspection_script()
Function to publish control command while time is less than the defined time limit.
rclcpp::Publisher< custom_interfaces::msg::ControlCommand >::SharedPtr _control_command_publisher_
void mission_decider(custom_interfaces::msg::OperationalStatus::SharedPtr mission_signal)
recieves GoSignal and stores the mission that should be ran
rclcpp::Subscription< custom_interfaces::msg::WheelRPM >::SharedPtr _motor_rpm_subscription_
rclcpp::TimerBase::SharedPtr _mission_end_timer_
InspectionMission()
Contruct a new Inspection Mission with constants defined in file.
InspectionFunctions _inspection_object_
Ellapsed time in seconds.
void update_rpms_callback(const custom_interfaces::msg::WheelRPM &motor_rpm)
Function to update the current rpms of the wheels.
void end_of_mission()
Rotations per minute of the motor.
rclcpp::Client< std_srvs::srv::Trigger >::SharedPtr _emergency_client_
rclcpp::Client< std_srvs::srv::Trigger >::SharedPtr _finish_client_
double _motor_rpm_
Mission to be executed;.
rclcpp::TimerBase::SharedPtr _timer_
void handle_end_of_mission_response(rclcpp::Client< std_srvs::srv::Trigger >::SharedFuture future) const
Function to end communication of end of mission.
common_lib::competition_logic::Mission _mission_
Flag to start the mission.
bool _mission_end_timer_started_
Timer for repetition of end of mission signal.
rclcpp::Time _initial_time_
constexpr double WHEELS_STOPPED_THRESHOLD
std::string get_mission_string(int mission)
const std::map< Mission, std::string > MISSION_STRING_MAP