Skip to content

Commit

Permalink
feat: add condition for filtering marker
Browse files Browse the repository at this point in the history
Signed-off-by: 1222-takeshi <[email protected]>
  • Loading branch information
1222-takeshi committed Oct 30, 2023
1 parent 0d1b49b commit c4fab1f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion control/vehicle_cmd_gate/config/vehicle_cmd_gate.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
check_external_emergency_heartbeat: false
use_start_request: false
enable_cmd_limit_filter: true
filter_activated_count_threshold: 10
filter_activated_count_threshold: 5
filter_activated_velocity_threshold: 1.0
external_emergency_stop_heartbeat_timeout: 0.0
stop_hold_acceleration: -1.5
emergency_acceleration: -2.4
Expand Down
6 changes: 6 additions & 0 deletions control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ VehicleCmdGate::VehicleCmdGate(const rclcpp::NodeOptions & node_options)
stop_check_duration_ = declare_parameter<double>("stop_check_duration");
enable_cmd_limit_filter_ = declare_parameter<bool>("enable_cmd_limit_filter");
filter_activated_count_threshold_ = declare_parameter<int>("filter_activated_count_threshold");
filter_activated_velocity_threshold_ =
declare_parameter<double>("filter_activated_velocity_threshold");

Check warning on line 169 in control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

VehicleCmdGate::VehicleCmdGate increases from 152 to 159 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.

// Vehicle Parameter
const auto vehicle_info = vehicle_info_util::VehicleInfoUtil(*this).getVehicleInfo();
Expand Down Expand Up @@ -587,10 +589,14 @@ AckermannControlCommand VehicleCmdGate::filterControlCommand(const AckermannCont
}
if (
filter_activated_count_ >= filter_activated_count_threshold_ &&
std::fabs(current_status_cmd.longitudinal.speed) >= filter_activated_velocity_threshold_ &&

Check warning on line 592 in control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

VehicleCmdGate::filterControlCommand has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
mode.mode == OperationModeState::AUTONOMOUS) {
filter_activated_marker_pub_->publish(createMarkerArray(is_filter_activated));
is_filter_activated_flag.data = true;
} else {
is_filter_activated_flag.data = false;
}

is_filter_activated_flag.stamp = now();
filter_activated_flag_pub_->publish(is_filter_activated_flag);

Check notice on line 601 in control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ New issue: Complex Method

VehicleCmdGate::filterControlCommand has a cyclomatic complexity of 11, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Expand Down
1 change: 1 addition & 0 deletions control/vehicle_cmd_gate/src/vehicle_cmd_gate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class VehicleCmdGate : public rclcpp::Node
double moderate_stop_service_acceleration_;
bool enable_cmd_limit_filter_;
int filter_activated_count_threshold_;
double filter_activated_velocity_threshold_;

// Service
rclcpp::Service<EngageSrv>::SharedPtr srv_engage_;
Expand Down

0 comments on commit c4fab1f

Please sign in to comment.