Skip to content

Commit

Permalink
improved robustness and tractability for better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
klaxalk committed Apr 28, 2024
1 parent f1d3260 commit 9283b3f
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/automatic_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ class AutomaticStart : public nodelet::Nodelet {
void timerMain(const ros::TimerEvent& event);
double _main_timer_rate_;

// | ------------------- hw api diagnostics ------------------- |
// | ------------------------- hw api ------------------------- |

void callbackHwApiStatus(const mrs_msgs::HwApiStatus::ConstPtr msg);
std::atomic<bool> hw_api_connected_ = false;
std::mutex mutex_hw_api_status_;

void callbackHwApiCapabilities(const mrs_msgs::HwApiCapabilities::ConstPtr msg);

// | --------------- Gazebo spawner diagnostics --------------- |

void callbackGazeboSpawnerDiagnostics(const mrs_msgs::GazeboSpawnerDiagnostics::ConstPtr msg);
Expand Down Expand Up @@ -273,9 +275,10 @@ void AutomaticStart::onInit() {
shopts.queue_size = 10;
shopts.transport_hints = ros::TransportHints().tcpNoDelay();

sh_estimation_diag_ = mrs_lib::SubscribeHandler<mrs_msgs::EstimationDiagnostics>(shopts, "estimation_diag_in");
sh_hw_api_status_ = mrs_lib::SubscribeHandler<mrs_msgs::HwApiStatus>(shopts, "hw_api_status_in", &AutomaticStart::callbackHwApiStatus, this);
sh_hw_api_capabilities_ = mrs_lib::SubscribeHandler<mrs_msgs::HwApiCapabilities>(shopts, "hw_api_capabilities_in");
sh_estimation_diag_ = mrs_lib::SubscribeHandler<mrs_msgs::EstimationDiagnostics>(shopts, "estimation_diag_in");
sh_hw_api_status_ = mrs_lib::SubscribeHandler<mrs_msgs::HwApiStatus>(shopts, "hw_api_status_in", &AutomaticStart::callbackHwApiStatus, this);
sh_hw_api_capabilities_ =
mrs_lib::SubscribeHandler<mrs_msgs::HwApiCapabilities>(shopts, "hw_api_capabilities_in", &AutomaticStart::callbackHwApiCapabilities, this);
sh_distance_sensor_ = mrs_lib::SubscribeHandler<sensor_msgs::Range>(shopts, "distance_sensor_in");
sh_imu_ = mrs_lib::SubscribeHandler<sensor_msgs::Imu>(shopts, "imu_in");
sh_control_manager_diag_ = mrs_lib::SubscribeHandler<mrs_msgs::ControlManagerDiagnostics>(shopts, "control_manager_diagnostics_in");
Expand Down Expand Up @@ -347,15 +350,15 @@ void AutomaticStart::genericCallback([[maybe_unused]] const topic_tools::ShapeSh

//}

/* callbackHwApiDiag() //{ */
/* callbackHwApiStatus() //{ */

void AutomaticStart::callbackHwApiStatus(const mrs_msgs::HwApiStatus::ConstPtr msg) {

if (!is_initialized_) {
return;
}

ROS_INFO_ONCE("[AutomaticStart]: getting HW API diagnostics");
ROS_INFO_ONCE("[AutomaticStart]: getting HW API status");

std::scoped_lock lock(mutex_hw_api_status_);

Expand Down Expand Up @@ -406,6 +409,19 @@ void AutomaticStart::callbackHwApiStatus(const mrs_msgs::HwApiStatus::ConstPtr m

//}

/* callbackHwApiCapabilities() //{ */

void AutomaticStart::callbackHwApiCapabilities([[maybe_unused]] const mrs_msgs::HwApiCapabilities::ConstPtr msg) {

if (!is_initialized_) {
return;
}

ROS_INFO_ONCE("[AutomaticStart]: getting HW API capabilities");
}

//}

/* callbackGazeboSpawnerDiagnostics() //{ */

void AutomaticStart::callbackGazeboSpawnerDiagnostics(const mrs_msgs::GazeboSpawnerDiagnostics::ConstPtr msg) {
Expand Down Expand Up @@ -860,6 +876,10 @@ bool AutomaticStart::preflightCheckSpeed(void) {
return true;
}

if (!sh_estimation_diag_.hasMsg()) {
return false;
}

auto estimation_diag = sh_estimation_diag_.getMsg();

double speed = std::hypot(estimation_diag->velocity.linear.x, estimation_diag->velocity.linear.y, estimation_diag->velocity.linear.z);
Expand Down Expand Up @@ -889,6 +909,10 @@ bool AutomaticStart::preflighCheckHeight(void) {

// | ----------------- is the check possible? ----------------- |

if (!sh_hw_api_capabilities_.hasMsg()) {
return false;
}

auto capabilities = sh_hw_api_capabilities_.getMsg();

if (!capabilities->produces_distance_sensor) {
Expand Down Expand Up @@ -928,6 +952,10 @@ bool AutomaticStart::preflighCheckGyro(void) {

// | ----------------- is the check possible? ----------------- |

if (!sh_hw_api_capabilities_.hasMsg()) {
return false;
}

auto capabilities = sh_hw_api_capabilities_.getMsg();

if (!capabilities->produces_imu) {
Expand Down

0 comments on commit 9283b3f

Please sign in to comment.