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

Add a ROS node that runs Gazebo #500

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions ros_gz_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
)

add_executable(gzserver src/gzserver.cpp)
ament_target_dependencies(gzserver
rclcpp
std_msgs
)
target_link_libraries(gzserver
${GZ_TARGET_PREFIX}-sim${GZ_SIM_VER}::core
)
ament_target_dependencies(gzserver std_msgs)

configure_file(
launch/gz_sim.launch.py.in
launch/gz_sim.launch.py.configured
Expand All @@ -105,6 +115,10 @@ install(TARGETS
create
DESTINATION lib/${PROJECT_NAME}
)
install(TARGETS
gzserver
DESTINATION lib/${PROJECT_NAME}
)

install(
TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
Expand Down
68 changes: 68 additions & 0 deletions ros_gz_sim/src/gzserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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>

int main(int _argc, char ** _argv)
{
using namespace gz;
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", "");

common::Console::SetVerbosity(4);
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;
}

// (azeey) Testing if a plugin can be loaded along side the defaults. Not working yet.
azeey marked this conversation as resolved.
Show resolved Hide resolved

// <plugin
// filename="gz-sim-imu-system"
// name="gz::sim::systems::Imu">
// </plugin>
sdf::Plugin imu_sdf_plugin;
imu_sdf_plugin.SetName("gz::sim::systems::Imu");
imu_sdf_plugin.SetFilename("gz-sim-imu-system");
sim::SystemLoader loader;
auto imu_plugin = loader.LoadPlugin(imu_sdf_plugin);
std::cout << imu_plugin.value() << std::endl;

gz::sim::Server server(server_config);
server.RunOnce();
if (!server.AddSystem(*imu_plugin))
{
RCLCPP_ERROR(
node->get_logger(), "IMU system not added");

}
server.Run(true /*blocking*/, 0, false /*paused*/);
}
Loading