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(vehicle_cmd_gate): fix the problems while transition from/to stopped state #5183

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 17 additions & 2 deletions control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,17 @@

// Check engage
if (!is_engaged_) {
filtered_commands.control = createStopControlCmd();
filtered_commands.control.longitudinal = createLongitudinalStopControlCmd();

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L433

Added line #L433 was not covered by tests
}

// Check pause. Place this check after all other checks as it needs the final output.
adapi_pause_->update(filtered_commands.control);
if (adapi_pause_->is_paused()) {
filtered_commands.control = createStopControlCmd();
if (is_engaged_) {
filtered_commands.control.longitudinal = createLongitudinalStopControlCmd();

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L440

Added line #L440 was not covered by tests
} else {
filtered_commands.control = createStopControlCmd();

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L442

Added line #L442 was not covered by tests
}

Check warning on line 443 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: Complex Method

VehicleCmdGate::publishControlCommands increases in cyclomatic complexity from 12 to 13, 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 if command filtering option is enable
Expand Down Expand Up @@ -599,6 +603,17 @@
return cmd;
}

LongitudinalCommand VehicleCmdGate::createLongitudinalStopControlCmd() const

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L606

Added line #L606 was not covered by tests
{
LongitudinalCommand cmd;
const auto t = this->now();

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L609

Added line #L609 was not covered by tests
cmd.stamp = t;
cmd.speed = 0.0;
cmd.acceleration = stop_hold_acceleration_;

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L612

Added line #L612 was not covered by tests

return cmd;
}

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

View check run for this annotation

Codecov / codecov/patch

control/vehicle_cmd_gate/src/vehicle_cmd_gate.cpp#L614-L615

Added lines #L614 - L615 were not covered by tests

AckermannControlCommand VehicleCmdGate::createEmergencyStopControlCmd() const
{
AckermannControlCommand cmd;
Expand Down
2 changes: 2 additions & 0 deletions control/vehicle_cmd_gate/src/vehicle_cmd_gate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace vehicle_cmd_gate
using autoware_adapi_v1_msgs::msg::MrmState;
using autoware_adapi_v1_msgs::msg::OperationModeState;
using autoware_auto_control_msgs::msg::AckermannControlCommand;
using autoware_auto_control_msgs::msg::LongitudinalCommand;
using autoware_auto_vehicle_msgs::msg::GearCommand;
using autoware_auto_vehicle_msgs::msg::HazardLightsCommand;
using autoware_auto_vehicle_msgs::msg::SteeringReport;
Expand Down Expand Up @@ -220,6 +221,7 @@ class VehicleCmdGate : public rclcpp::Node
// Algorithm
AckermannControlCommand prev_control_cmd_;
AckermannControlCommand createStopControlCmd() const;
LongitudinalCommand createLongitudinalStopControlCmd() const;
AckermannControlCommand createEmergencyStopControlCmd() const;

std::shared_ptr<rclcpp::Time> prev_time_;
Expand Down
Loading