Skip to content

Commit

Permalink
Model command structure update
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Wagner <[email protected]>
  • Loading branch information
WagnerMarcos committed Jul 20, 2021
1 parent 9796606 commit 66bb5cf
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 115 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ set(IGNITION_GAZEBO_GUI_PLUGIN_INSTALL_DIR
#============================================================================
# Configure the build
#============================================================================
ign_configure_build(QUIT_IF_BUILD_ERRORS
COMPONENTS model
)
ign_configure_build(QUIT_IF_BUILD_ERRORS)

add_subdirectory(examples)

Expand Down
40 changes: 0 additions & 40 deletions model/src/CMakeLists.txt

This file was deleted.

58 changes: 0 additions & 58 deletions model/src/cmd/CMakeLists.txt

This file was deleted.

10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(gui_sources
PARENT_SCOPE
)

ign_add_component(model SOURCES cmd/ModelCommandAPI.cc GET_TARGET_NAME model_lib_target)
ign_add_component(ign SOURCES ign.cc GET_TARGET_NAME ign_lib_target)
target_link_libraries(${ign_lib_target}
PRIVATE
Expand Down Expand Up @@ -59,6 +60,7 @@ set (sources
Util.cc
View.cc
World.cc
cmd/ModelCommandAPI.cc
${PROTO_PRIVATE_SRC}
${network_sources}
)
Expand All @@ -74,6 +76,7 @@ set (gtest_sources
ign_TEST.cc
Link_TEST.cc
Model_TEST.cc
ModelCommandAPI_TEST.cc
SdfEntityCreator_TEST.cc
SdfGenerator_TEST.cc
Server_TEST.cc
Expand Down Expand Up @@ -164,6 +167,13 @@ if(TARGET UNIT_ign_TEST)
ENVIRONMENT "${_env_vars}")
endif()

if(TARGET UNIT_ModelCommandAPI_TEST)

target_compile_definitions(UNIT_ModelCommandAPI_TEST PRIVATE
"IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"")

endif()

if(NOT WIN32)
add_subdirectory(cmd)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gtest/gtest.h>

#include "ignition/gazebo/Server.hh"
#include "ignition/gazebo/test_config.hh" // NOLINT(build/include)

static const std::string kIgnModelCommand(std::string(IGN_PATH) +
"/ign model ");
Expand All @@ -40,8 +41,8 @@ void ReplaceNegativeZeroValues(std::string &_text)
size_t pos = 0;
while ((pos = _text.find(neg_zero, pos)) != std::string::npos)
{
_text.replace(pos, neg_zero.length(), zero);
pos += zero.length();
_text.replace(pos, neg_zero.length(), zero);
pos += zero.length();
}
}

Expand Down Expand Up @@ -114,7 +115,8 @@ TEST(ModelCommandAPI, Commands)
ReplaceNegativeZeroValues(output);
const std::string expectedOutput =
"\nRequesting state for world [diff_drive]...\n\n"
"Name: vehicle_blue\n"
"Model: [8]\n"
" - Name: vehicle_blue\n"
" - Pose: \n"
" [0.000000 | 2.000000 | 0.325000]\n"
" [0.000000 | 0.000000 | 0.000000]\n"
Expand Down Expand Up @@ -191,7 +193,8 @@ TEST(ModelCommandAPI, Commands)
ReplaceNegativeZeroValues(output);
const std::string expectedOutput =
"\nRequesting state for world [diff_drive]...\n\n"
"Name: vehicle_blue\n"
"Model: [8]\n"
" - Name: vehicle_blue\n"
" - Pose: \n"
" [0.000000 | 2.000000 | 0.325000]\n"
" [0.000000 | 0.000000 | 0.000000]\n\n";
Expand Down
59 changes: 59 additions & 0 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ install( FILES
DESTINATION
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/)

#===============================================================================
# Used for the installed model command version.
# Generate the ruby script that gets installed.
# Note that the major version of the library is included in the name.
set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured "${cmd_model_script_generated}.configured")

# Set the model_library_location variable to the relative path to the library file
# within the install directory structure.
set(model_library_location "../../../${CMAKE_INSTALL_LIBDIR}/$<TARGET_FILE_NAME:${model_lib_target}>")

configure_file(
"cmdmodel.rb.in"
"${cmd_model_script_configured}"
@ONLY)
file(GENERATE
OUTPUT "${cmd_model_script_generated}"
INPUT "${cmd_model_script_configured}")

install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition)

# Used for the installed version.
set(ign_model_ruby_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmdmodel${PROJECT_VERSION_MAJOR}")

set(ignmodel_configured "${CMAKE_CURRENT_BINARY_DIR}/ignmodel${PROJECT_VERSION_MAJOR}.yaml")
configure_file(
"ignmodel.yaml.in"
${ignmodel_configured})

install(FILES ${ignmodel_configured} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/)


#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
Expand Down Expand Up @@ -66,3 +98,30 @@ set(ign_library_path
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY)

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/model/test/lib/ruby/ignition")
set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured")

# Set the model_library_location variable to the full path of the library file
# within the build directory
set(model_library_location "$<TARGET_FILE:${model_lib_target}>")

configure_file(
"cmdmodel.rb.in"
"${cmd_model_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_model_script_generated_test}"
INPUT "${cmd_model_script_configured_test}")

# Used for internal testing.
set(ign_model_ruby_path "${cmd_model_script_generated_test}")

configure_file(
"ignmodel.yaml.in"
"${cmd_model_ruby_test_dir}/ignmodel${PROJECT_VERSION_MAJOR}.yaml")
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::string getWorldName()
// \brief Set the state of a ECM instance with a world snapshot.
// \param _ecm ECM instance to be populated.
// \return boolean indicating if it was able to populate the ECM.
bool PopulateECM(ignition::gazebo::EntityComponentManager &_ecm)
bool populateECM(ignition::gazebo::EntityComponentManager &_ecm)
{
const std::string world = getWorldName();
if (world.empty())
Expand Down Expand Up @@ -143,7 +143,8 @@ void printPose(const uint64_t _entity,
+ std::to_string(poseComp->Data().Pitch()) + " | "
+ std::to_string(poseComp->Data().Yaw()) + "]";

std::cout << "Name: " << nameComp->Data() << std::endl
std::cout << "Model: [" << _entity << "]" << std::endl
<< " - Name: " << nameComp->Data() << std::endl
<< " - Pose: " << poseInfo << std::endl << std::endl;
}
}
Expand Down Expand Up @@ -304,7 +305,7 @@ void printJoints(const uint64_t entity,
extern "C" IGNITION_GAZEBO_VISIBLE void cmdModelList()
{
ignition::gazebo::EntityComponentManager ecm{};
if(!PopulateECM(ecm))
if(!populateECM(ecm))
{
return;
}
Expand Down Expand Up @@ -347,7 +348,7 @@ extern "C" IGNITION_GAZEBO_VISIBLE void cmdModelInfo(
// Get arguments

ignition::gazebo::EntityComponentManager ecm{};
if(!PopulateECM(ecm))
if(!populateECM(ecm))
return;

// Get the desired model entity.
Expand Down
File renamed without changes.
17 changes: 11 additions & 6 deletions model/src/cmd/cmdmodel.rb.in → src/cmd/cmdmodel.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ COMMANDS = { 'model' =>
" If no arg is passed all links are printed \n"\
" Requires the -m option \n"\
" \n"\
" E.g. to get information about the \n"\
" caster link in the diff_drive world, run: \n"\
" ign model -m vehicle_blue -l caster \n"\
" \n"\
" -j [--joint] arg Select a joint to show its properties. \n"\
" If no arg is passed all joints are printed \n"\
" Requires the -m option \n"\
" \n"\
" E.g. to get information about the \n"\
" box_link in the shapes world, run: \n"\
" ign model -m box -l box_link \n\n"+
" caster_wheel joint in the diff_drive \n"\
" world, run: \n"\
" ign model -m vehicle_blue -j caster_wheel \n\n"+
COMMON_OPTIONS
}

Expand All @@ -77,7 +82,7 @@ class Cmd

opt_parser = OptionParser.new do |opts|
opts.banner = usage

opts.on('-h', '--help') do
puts usage
exit
Expand Down Expand Up @@ -124,8 +129,8 @@ class Cmd

options
end # parse()


def execute(args)
options = parse(args)

Expand Down Expand Up @@ -159,7 +164,7 @@ class Cmd

Importer.cmdModelInfo(options['model'], options['pose'], options['link'],
options['link_name'], options['joint'], options['joint_name'])
else
else
puts 'Command error: I do not have an implementation for '\
"command [ign #{options['command']}]."
end
Expand Down
File renamed without changes.

0 comments on commit 66bb5cf

Please sign in to comment.