Skip to content

Commit

Permalink
feat: Added a new command to receive the URDF model of the robot
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasKuhner committed Sep 6, 2024
1 parent 93f72cb commit 5090f36
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 281 deletions.
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ endif()

target_include_directories(franka PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)

Expand Down Expand Up @@ -173,13 +172,6 @@ install(EXPORT FrankaTargets
DESTINATION ${INSTALL_CMAKE_CONFIG_DIR}
)

set(ROBOT_MODELS_PATH ${CMAKE_INSTALL_PREFIX}/share/robot_models)
configure_file(cmake/config.h.in config.h)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/robot_models
DESTINATION share
)

## Subprojects

# Ignore find_package(Franka) in subprojects.
Expand Down
1 change: 0 additions & 1 deletion cmake/config.h.in

This file was deleted.

11 changes: 11 additions & 0 deletions include/franka/commands/get_robot_model_command.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <string>

namespace franka {

struct GetRobotModelResult {
std::string robot_model_urdf;
};

} // namespace franka
4 changes: 1 addition & 3 deletions include/franka/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <array>
#include <memory>

#include <config.h>
#include <franka/robot.h>
#include <franka/robot_model_base.h>
#include <franka/robot_state.h>
Expand Down Expand Up @@ -63,7 +62,7 @@ class Model {
*
* @throw ModelException if the model library cannot be loaded.
*/
explicit Model(franka::Network& network);
explicit Model(franka::Network& network, const std::string& urdf_model);

/**
* Creates a new Model instance only for the tests.
Expand Down Expand Up @@ -299,7 +298,6 @@ class Model {
private:
std::unique_ptr<ModelLibrary> library_;
std::unique_ptr<RobotModelBase> robot_model_;
std::string k_urdf_path_ = std::string(ROBOT_MODELS_PATH) + "/fr3.urdf";
};

} // namespace franka
9 changes: 9 additions & 0 deletions include/franka/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <franka/robot_model_base.h>
#include <franka/robot_state.h>
#include <research_interface/robot/service_types.h>
#include <franka/commands/get_robot_model_command.hpp>

/**
* @file robot.h
Expand Down Expand Up @@ -455,6 +456,14 @@ class Robot {
* @{
*/

/**
* @throw CommandException if the Control reports an error.
* @throw NetworkException if the connection is lost, e.g. after a timeout.
*
* @return std::string Provides the URDF model of the attached robot arm as json string
*/
auto getRobotModel() -> std::string;

/**
* Changes the collision behavior.
*
Expand Down
6 changes: 5 additions & 1 deletion include/franka/robot_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "franka/robot_model_base.h"

namespace franka {

/**
* Implements RobotModelBase using Pinocchio.
*/
Expand Down Expand Up @@ -57,4 +59,6 @@ class RobotModel : public RobotModelBase {
pinocchio::Inertia initial_last_link_inertia_;
pinocchio::FrameIndex last_link_frame_index_;
pinocchio::JointIndex last_joint_index_;
};
};

} // namespace franka
230 changes: 0 additions & 230 deletions robot_models/fr3.urdf

This file was deleted.

21 changes: 3 additions & 18 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@
#include "model_library.h"
#include "network.h"

std::string readURDFFromFile(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
std::cerr << "Error opening file: " << filename << std::endl;
return "";
}

std::ostringstream oss;
oss << file.rdbuf();
file.close();

return oss.str();
}

using namespace std::string_literals; // NOLINT(google-build-using-namespace)

namespace franka {
Expand All @@ -38,10 +24,9 @@ Frame operator++(Frame& frame, int /* dummy */) noexcept {
return original;
}

Model::Model(Network& network) : library_{new ModelLibrary(network)} {
// TODO(baris) workaround for now, get the robot specific urdf from the robot in the future
auto urdf_string = readURDFFromFile(k_urdf_path_);
robot_model_ = std::make_unique<RobotModel>(urdf_string);
Model::Model(Network& network, const std::string& urdf_model)
: library_{new ModelLibrary(network)} {
robot_model_ = std::make_unique<RobotModel>(urdf_model);
}

// for the tests
Expand Down
Loading

0 comments on commit 5090f36

Please sign in to comment.