Skip to content

Commit

Permalink
started trying to fix installation of the jni by changing the cmake t…
Browse files Browse the repository at this point in the history
…o a less complex structure
  • Loading branch information
rjgriffin42 committed Dec 17, 2024
1 parent 5ad8e14 commit 05cc32e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 21 deletions.
18 changes: 7 additions & 11 deletions external-control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ set(CMAKE_CXX_STANDARD 17)

project(external-control CXX)

set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
#set(INSTALL_LIB_DIR "lib" CACHE PATH "Installation directory for libraries")
#set(INSTALL_INC_DIR "include" CACHE PATH "Installation directory for headers")

find_package(Catch2 2 REQUIRED)
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

Expand All @@ -26,11 +25,8 @@ target_link_libraries(external-wrapper PUBLIC
Eigen3::Eigen)

install(TARGETS external-wrapper
EXPORT targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install(DIRECTORY
src/main/cpp/
DESTINATION "${INSTALL_INC_DIR}"
FILES_MATCHING PATTERN "*.hpp")
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include FILES_MATCHING PATTERN "*.hpp")
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace ihmc
ConstantPositionController::ConstantPositionController(const double default_stiffness, const double default_damping, const int number_of_joints)
{
number_of_joints_ = number_of_joints;
desired_joint_velocities_ = Eigen::VectorXd(number_of_joints_);
desired_joint_torques_ = Eigen::VectorXd(number_of_joints_);
desired_joint_stiffnesses_ = Eigen::VectorXd(number_of_joints_);
desired_joint_damping_ = Eigen::VectorXd(number_of_joints_);
desired_joint_velocities_.resize(number_of_joints_);
desired_joint_torques_.resize(number_of_joints_);
desired_joint_stiffnesses_.resize(number_of_joints_);
desired_joint_damping_.resize(number_of_joints_);

desired_joint_velocities_.setZero();
desired_joint_torques_.setZero();
Expand Down
8 changes: 4 additions & 4 deletions external-control/src/main/cpp/external-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace ihmc
ExternalControlImpl::ExternalControlImpl(const double default_stiffness, const double default_damping, const int number_of_joints)
{
constant_position_controller_ = ConstantPositionController(default_stiffness, default_damping, number_of_joints);
desired_state_data_ = Eigen::VectorXd(13 + 2 * number_of_joints);
desired_control_data_ = Eigen::VectorXd(number_of_joints);
p_gains_ = Eigen::VectorXd(number_of_joints);
d_gains_ = Eigen::VectorXd(number_of_joints);
desired_state_data_.resize(13 + 2 * number_of_joints);
desired_control_data_.resize(number_of_joints);
p_gains_.resize(number_of_joints);
d_gains_.resize(number_of_joints);
number_of_joints_ = number_of_joints;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public ExternalControllerState(String namePrefix,

blendRatioCurrentValue = new YoDouble(namePrefix + "BlendRatioCurrentValue", registry);

ExternalWrapperNativeLibrary.load();

externalControl = new ExternalControl(controllerToolbox.getFullRobotModel().getRootBody(), controlledJoints, 100.0, 25.0);

lowLevelOneDoFJointDesiredDataHolder.registerJointsWithEmptyData(controlledJoints);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package us.ihmc.externalControl;

import us.ihmc.log.LogTools;
import us.ihmc.tools.nativelibraries.NativeLibraryDescription;
import us.ihmc.tools.nativelibraries.NativeLibraryLoader;
import us.ihmc.tools.nativelibraries.NativeLibraryWithDependencies;

public class ExternalWrapperNativeLibrary implements NativeLibraryDescription
{
@Override
public String getPackage(OperatingSystem operatingSystem, Architecture architecture)
{
String architecturePackage = "";
if (architecture == Architecture.x64)
{
architecturePackage = switch (operatingSystem)
{
case LINUX64 -> "linux-x86_64";
default -> "unknown";
};
}

return "externalWrapper." + architecturePackage;
}

@Override
public NativeLibraryWithDependencies getLibraryWithDependencies(OperatingSystem operatingSystem, Architecture architecture)
{
switch (operatingSystem)
{
case LINUX64:
return NativeLibraryWithDependencies.fromFilename("jniExternalWrapper.so",
"libexternal-wrapper.so");
default:
break;
}

LogTools.warn("Unsupported platform: " + operatingSystem.name() + "-" + architecture.name());
return null;
}

private static boolean loaded = false;

public static boolean load()
{
if (!loaded)
{
ExternalWrapperNativeLibrary nativeLibrary = new ExternalWrapperNativeLibrary();
loaded = NativeLibraryLoader.loadLibrary(nativeLibrary);
}
return loaded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
include = {"external-control.hpp"},
linkpath = "../lib",
link = "external-wrapper",
preload = {"external-wrapper", "jniExternalWrapper"}
preload = {"external-wrapper", "jniExternalControlWrapper"}
),
target = "us.ihmc.externalControl.ExternalControlWrapper"
)
Expand Down
Git LFS file not shown

0 comments on commit 05cc32e

Please sign in to comment.