Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 include/franka/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ class Model {
*/
explicit Model(franka::Network& network);

/**
* Creates a new Model instance.
*
* This constructor is for internal use only.
*
* @see Robot::loadModel
*
* @param[in] pathToLib file path to load model library from (instead of downloading from the robot)
*
* @throw ModelException if the model library cannot be loaded.
*/
explicit Model(const std::string& pathToLib);


/**
* Move-constructs a new Model instance.
*
Expand Down
6 changes: 6 additions & 0 deletions include/franka/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ class Robot {

class Impl;

/**
* Save the dynamics model library from the robot for offline use to the given path
*
*/
void downloadModelLibrary(const std::string& toFile);

private:
std::unique_ptr<Impl> impl_;
std::mutex control_mutex_;
Expand Down
1 change: 1 addition & 0 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Frame operator++(Frame& frame, int /* dummy */) noexcept {
}

Model::Model(Network& network) : library_{new ModelLibrary(network)} {}
Model::Model(const std::string& pathToLib) : library_{new ModelLibrary(pathToLib)} {}

// Has to be declared here, as the ModelLibrary type is incomplete in the header
Model::~Model() noexcept = default;
Expand Down
5 changes: 4 additions & 1 deletion src/model_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
namespace franka {

ModelLibrary::ModelLibrary(franka::Network& network)
: loader_(LibraryDownloader(network).path()),
: ModelLibrary(LibraryDownloader(network).path()) {}

ModelLibrary::ModelLibrary(const std::string& cachepath)
: loader_(cachepath),
body_jacobian_joint1{reinterpret_cast<decltype(&Ji_J_J1)>(loader_.getSymbol("Ji_J_J1"))},
body_jacobian_joint2{reinterpret_cast<decltype(&Ji_J_J2)>(loader_.getSymbol("Ji_J_J2"))},
body_jacobian_joint3{reinterpret_cast<decltype(&Ji_J_J3)>(loader_.getSymbol("Ji_J_J3"))},
Expand Down
1 change: 1 addition & 0 deletions src/model_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace franka {
class ModelLibrary {
public:
ModelLibrary(Network& network);
ModelLibrary(const std::string& cachepath);

private:
LibraryLoader loader_;
Expand Down
9 changes: 9 additions & 0 deletions src/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <franka/robot.h>

#include <utility>
#include <fstream>

#include "control_loop.h"
#include "network.h"
#include "robot_impl.h"
#include "library_downloader.h"

namespace franka {

Expand Down Expand Up @@ -306,4 +308,11 @@ Model Robot::loadModel() {
return impl_->loadModel();
}

void Robot::downloadModelLibrary(const std::string& toFile) {
std::ofstream dst(toFile, std::ios::binary);
LibraryDownloader downloaderObj(*(impl_->network_));
std::ifstream src(downloaderObj.path(), std::ios::binary);
dst << src.rdbuf();
}

} // namespace franka
3 changes: 2 additions & 1 deletion src/robot_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Robot::Impl : public RobotControl {

Model loadModel() const;

std::unique_ptr<Network> network_;

protected:
bool motionGeneratorRunning() const noexcept;
bool controllerRunning() const noexcept;
Expand All @@ -73,7 +75,6 @@ class Robot::Impl : public RobotControl {
research_interface::robot::RobotState receiveRobotState();
void updateState(const research_interface::robot::RobotState& robot_state);

std::unique_ptr<Network> network_;

Logger logger_;

Expand Down