-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test: SubjuGator can spawn in Gazebo (#1201)
* add test: SubjuGator can spawn in Gazebo * Testing new checkout action * pre-commit changes
- Loading branch information
Showing
8 changed files
with
95 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
SubjuGator/simulation/subjugator_gazebo/test/spawn_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Author: Cameron Brown | ||
* Date: June 1, 2024 | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include <ros/ros.h> | ||
|
||
#include <mil_tools/test.hpp> | ||
|
||
using namespace mil_tools; | ||
|
||
// Ensure that at least sub8 or sub9 shows up when launching gazebo | ||
TEST(SpawnTest, spawnTest) | ||
{ | ||
ros::NodeHandle nh; | ||
EXPECT_TRUE(mil_tools::gazeboModelExists(nh, "sub8") || mil_tools::gazeboModelExists(nh, "sub8_no_cams") || | ||
mil_tools::gazeboModelExists(nh, "sub9")); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
ros::init(argc, argv, "subjugator_gazebo_spawn_test"); | ||
return RUN_ALL_TESTS(); | ||
} |
7 changes: 7 additions & 0 deletions
7
SubjuGator/simulation/subjugator_gazebo/test/subjugator_gazebo.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<launch> | ||
<include file="$(find subjugator_gazebo)/launch/duck.launch"> | ||
<arg name="gui" value="false" /> | ||
</include> | ||
<include file="$(find subjugator_launch)/launch/tf.launch"></include> | ||
<test test-name="subjugator_gazebo_spawn_test" pkg="subjugator_gazebo" type="subjugator_gazebo_spawn_test" /> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <gazebo_msgs/ModelStates.h> | ||
#include <ros/ros.h> | ||
|
||
namespace mil_tools | ||
{ | ||
bool gazeboModelExists(ros::NodeHandle &nh, const std::string &_name, | ||
const ros::WallDuration _timeout = ros::WallDuration(5, 0)) | ||
{ | ||
ros::WallTime timeout = ros::WallTime::now() + _timeout; | ||
while (ros::WallTime::now() < timeout) | ||
{ | ||
gazebo_msgs::ModelStatesConstPtr modelStates = ros::topic::waitForMessage<gazebo_msgs::ModelStates>( | ||
std::string("/gazebo/model_states"), nh, ros::Duration(0.3)); | ||
|
||
if (!modelStates) | ||
continue; | ||
for (auto model : modelStates->name) | ||
{ | ||
if (model == _name) | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} // namespace mil_tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters