Skip to content

Commit 088e8f3

Browse files
Andeshogkluge7
andauthored
fix: actually publish zero thrust (#536)
* fix(script): improve error handling and early termination on failure * fix: actually publish zero thrust --------- Co-authored-by: Andreas Kluge Svendsrud <89779148+kluge7@users.noreply.github.com>
1 parent db05964 commit 088e8f3

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

motion/thrust_allocator_auv/src/thrust_allocator_ros.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,13 @@ void ThrustAllocator::set_subscriber_and_publisher() {
9191
void ThrustAllocator::wrench_cb(const geometry_msgs::msg::Wrench& msg) {
9292
last_msg_time_ = this->now();
9393
Eigen::Vector6d wrench_vector = wrench_to_vector(msg);
94+
Eigen::VectorXd zero_forces = Eigen::VectorXd::Zero(8);
9495

9596
if (!healthy_wrench(wrench_vector)) {
9697
RCLCPP_ERROR(get_logger(), "Wrench vector invalid, publishing zeros.");
97-
thruster_forces_publisher_->publish(vortex_msgs::msg::ThrusterForces());
98+
vortex_msgs::msg::ThrusterForces msg_out =
99+
array_eigen_to_msg(zero_forces);
100+
thruster_forces_publisher_->publish(msg_out);
98101
return;
99102
}
100103

@@ -104,7 +107,9 @@ void ThrustAllocator::wrench_cb(const geometry_msgs::msg::Wrench& msg) {
104107
if (is_invalid_matrix(thruster_forces)) {
105108
RCLCPP_ERROR(get_logger(),
106109
"ThrusterForces vector invalid, publishing zeros.");
107-
thruster_forces_publisher_->publish(vortex_msgs::msg::ThrusterForces());
110+
vortex_msgs::msg::ThrusterForces msg_out =
111+
array_eigen_to_msg(zero_forces);
112+
thruster_forces_publisher_->publish(msg_out);
108113
return;
109114
}
110115

@@ -119,10 +124,13 @@ void ThrustAllocator::wrench_cb(const geometry_msgs::msg::Wrench& msg) {
119124

120125
void ThrustAllocator::watchdog_callback() {
121126
auto now = this->now();
127+
Eigen::VectorXd zero_forces = Eigen::VectorXd::Zero(8);
122128
if ((now - last_msg_time_) >= timeout_treshold_ && !watchdog_triggered_) {
123129
watchdog_triggered_ = true;
124130
RCLCPP_WARN(get_logger(), "Watchdog triggered, publishing zeros.");
125-
thruster_forces_publisher_->publish(vortex_msgs::msg::ThrusterForces());
131+
vortex_msgs::msg::ThrusterForces msg_out =
132+
array_eigen_to_msg(zero_forces);
133+
thruster_forces_publisher_->publish(msg_out);
126134
}
127135
}
128136

tests/waypoint_navigation/simulator_test.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e
3+
set -o pipefail
34

45
# Load ROS 2 environment
56
echo "Setting up ROS 2 environment..."
@@ -10,6 +11,14 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
1011
# Get the directory of this script dynamically
1112
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1213

14+
# Function to terminate processes safely on error
15+
cleanup() {
16+
echo "Error detected. Cleaning up..."
17+
kill -TERM -"$SIM_PID" -"$ORCA_PID" -"$CONTROLLER_PID" -"$FILTER_PID" || true
18+
exit 1
19+
}
20+
trap cleanup ERR
21+
1322
# Launch Stonefish Simulator
1423
setsid ros2 launch stonefish_sim simulation_nogpu.launch.py &
1524
SIM_PID=$!
@@ -22,6 +31,12 @@ timeout 30s bash -c '
2231
done || true'
2332
echo "Simulator started"
2433

34+
# Check for ROS errors in logs
35+
if journalctl -u ros2 | grep -i "error"; then
36+
echo "Error detected in ROS logs. Exiting..."
37+
exit 1
38+
fi
39+
2540
# Wait for odometry data
2641
echo "Waiting for odom data..."
2742
timeout 10s ros2 topic echo /orca/odom --once
@@ -36,6 +51,12 @@ echo "Waiting for sim interface to start..."
3651
timeout 30s bash -c 'until ros2 topic list | grep -q "/orca/pose"; do sleep 1; done'
3752
echo "Simulator started"
3853

54+
# Check for ROS errors again
55+
if journalctl -u ros2 | grep -i "error"; then
56+
echo "Error detected in ROS logs. Exiting..."
57+
exit 1
58+
fi
59+
3960
# Wait for pose data
4061
echo "Waiting for pose data..."
4162
timeout 10s ros2 topic echo /orca/pose --once
@@ -50,6 +71,12 @@ setsid ros2 launch reference_filter_dp reference_filter.launch.py &
5071
FILTER_PID=$!
5172
echo "Launched filter with PID: $FILTER_PID"
5273

74+
# Check for ROS errors before continuing
75+
if journalctl -u ros2 | grep -i "error"; then
76+
echo "Error detected in ROS logs. Exiting..."
77+
exit 1
78+
fi
79+
5380
# Set operation mode
5481
echo "Turning off killswitch and setting operation mode to autonomous mode"
5582
ros2 topic pub /orca/killswitch std_msgs/msg/Bool "{data: false}" -1
@@ -72,3 +99,5 @@ fi
7299

73100
# Terminate processes
74101
kill -TERM -"$SIM_PID" -"$ORCA_PID" -"$CONTROLLER_PID" -"$FILTER_PID"
102+
103+
echo "Test completed successfully."

0 commit comments

Comments
 (0)