Skip to content
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

fix(raw_vehicle_cmd_converter): fix null check #8677

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions vehicle/autoware_raw_vehicle_cmd_converter/src/node.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Tier IV, Inc. All rights reserved.

Check notice on line 1 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: Overall Code Complexity

The mean cyclomatic complexity increases from 6.38 to 6.50, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -99,8 +99,9 @@

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

Check warning on line 104 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.
if (need_to_subscribe_actuation_status_) {
sub_actuation_status_ = create_subscription<ActuationStatusStamped>(
"~/input/actuation_status", 1,
Expand All @@ -119,7 +120,7 @@

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 123 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 123 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 +271,7 @@
{
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
Loading