-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a ROS node that runs Gazebo (#500)
* Add gzserver with ability to load an SDF file or string --------- Signed-off-by: Addisu Z. Taddese <[email protected]> (cherry picked from commit 92a2891)
- Loading branch information
1 parent
98b9d13
commit e6d4c6b
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gz/common/Console.hh> | ||
#include <gz/sim/Server.hh> | ||
#include <gz/sim/SystemLoader.hh> | ||
#include <gz/sim/ServerConfig.hh> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
// ROS node that executes a gz-sim Server given a world SDF file or string. | ||
int main(int _argc, char ** _argv) | ||
{ | ||
auto filtered_arguments = rclcpp::init_and_remove_ros_arguments(_argc, _argv); | ||
auto node = rclcpp::Node::make_shared("gzserver"); | ||
auto world_sdf_file = node->declare_parameter("world_sdf_file", ""); | ||
auto world_sdf_string = node->declare_parameter("world_sdf_string", ""); | ||
|
||
gz::common::Console::SetVerbosity(4); | ||
gz::sim::ServerConfig server_config; | ||
|
||
if (!world_sdf_file.empty()) { | ||
server_config.SetSdfFile(world_sdf_file); | ||
} else if (!world_sdf_string.empty()) { | ||
server_config.SetSdfString(world_sdf_string); | ||
} else { | ||
RCLCPP_ERROR( | ||
node->get_logger(), "Must specify either 'world_sdf_file' or 'world_sdf_string'"); | ||
return -1; | ||
} | ||
|
||
gz::sim::Server server(server_config); | ||
server.Run(true /*blocking*/, 0, false /*paused*/); | ||
} |