Skip to content

Commit

Permalink
fix(raw_vehicle_cmd_converter): fix null check
Browse files Browse the repository at this point in the history
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
  • Loading branch information
kosuke55 committed Aug 29, 2024
1 parent fb6fd8d commit ee13d91
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(

// NOTE: some vehicles do not publish actuation status. To handle this, subscribe only when the
// option is specified.
const bool use_vgr = convert_steer_cmd_method_.has_value() &&

Check warning on line 102 in vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp#L102

Added line #L102 was not covered by tests
convert_steer_cmd_method_.value() == "vgr";
need_to_subscribe_actuation_status_ =
convert_actuation_to_steering_status_ || convert_steer_cmd_method_.value() == "vgr";
convert_actuation_to_steering_status_ || use_vgr;

Check warning on line 105 in vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

RawVehicleCommandConverterNode::RawVehicleCommandConverterNode increases in cyclomatic complexity from 16 to 17, 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.

Check warning on line 105 in vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp#L105

Added line #L105 was not covered by tests
if (need_to_subscribe_actuation_status_) {
sub_actuation_status_ = create_subscription<ActuationStatusStamped>(
"~/input/actuation_status", 1,
Expand All @@ -119,7 +121,7 @@ RawVehicleCommandConverterNode::RawVehicleCommandConverterNode(

void RawVehicleCommandConverterNode::publishActuationCmd()
{
if (!current_twist_ptr_ || !control_cmd_ptr_ || !current_steer_ptr_ || !actuation_status_ptr_) {
if (!current_twist_ptr_ || !control_cmd_ptr_ || !current_steer_ptr_) {

Check notice on line 124 in vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Complex Method

RawVehicleCommandConverterNode::publishActuationCmd decreases in cyclomatic complexity from 18 to 17, 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.

Check notice on line 124 in vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Complex Conditional

RawVehicleCommandConverterNode::publishActuationCmd decreases from 1 complex conditionals with 3 branches to 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.
RCLCPP_WARN_EXPRESSION(
get_logger(), is_debugging_, "some pointers are null: %s, %s, %s",
!current_twist_ptr_ ? "twist" : "", !control_cmd_ptr_ ? "cmd" : "",
Expand Down Expand Up @@ -270,7 +272,7 @@ void RawVehicleCommandConverterNode::onActuationStatus(
{
actuation_status_ptr_ = msg;

if (!convert_actuation_to_steering_status_) {
if (!convert_actuation_to_steering_status_ || convert_steer_cmd_method_.has_value()){
return;
}

Expand Down

0 comments on commit ee13d91

Please sign in to comment.