Skip to content

Commit

Permalink
cleaned up the example.
Browse files Browse the repository at this point in the history
Added FK
  • Loading branch information
kpwelsh committed Jun 23, 2024
1 parent eec6971 commit 612e3fa
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 183 deletions.
53 changes: 13 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ cmake_minimum_required(VERSION 3.0)
# Enable ExternalProject CMake module
include(ExternalProject)

#target_include_directories(ik_geo PUBLIC include)

# # Set default ExternalProject root directory
# set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/Rust)
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/Rust)

# Add rust_example as a CMake target
ExternalProject_Add(
Expand All @@ -21,47 +19,22 @@ ExternalProject_Add(
INSTALL_COMMAND ""
LOG_BUILD ON)


# Specify link libraries

# if (WIN32)
# target_link_libraries(ik_geo
# debug "${CMAKE_SOURCE_DIR}/rust-wrapper/target/debug/libik_geo.lib"
# optimized "${CMAKE_SOURCE_DIR}/rust-wrapper/target/release/libik_geo.lib"
# ws2_32 userenv advapi32)
# else ()
# target_link_libraries(ik_geo
# debug "${CMAKE_SOURCE_DIR}/rust-wrapper/target/de bug/libik_geo.so"
# optimized "${CMAKE_SOURCE_DIR}/rust-wrapper/target/release/libik_geo.so")
# endif()



#set_target_properties(ik_geo PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)

# Build to the dist folder
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# Custom command to copy libik_cpp.a to the dist folder
add_library(ik_geo INTERFACE include/ik_geo.h)
add_dependencies(ik_geo ik_geo_lib)
target_include_directories(ik_geo INTERFACE include)

if (WIN32)
add_custom_command(TARGET ik_geo_lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_LIST_DIR}/rust-wrapper/target/debug/libik_geo.lib"
"${CMAKE_BINARY_DIR}/libik_geo.lib"
)
else()
add_custom_command(TARGET ik_geo_lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_LIST_DIR}/rust-wrapper/target/release/libik_geo.so"
"${CMAKE_BINARY_DIR}/libik_geo.so"
)
target_link_libraries(ik_geo INTERFACE
debug "${CMAKE_CURRENT_LIST_DIR}/rust-wrapper/target/debug/libik_geo.lib"
optimized "${CMAKE_CURRENT_LIST_DIR}/rust-wrapper/target/release/libik_geo.lib"
ws2_32 userenv advapi32)
else ()
target_link_libraries(ik_geo INTERFACE
debug "${CMAKE_CURRENT_LIST_DIR}/rust-wrapper/target/debug/libik_geo.so"
optimized "${CMAKE_CURRENT_LIST_DIR}/rust-wrapper/target/release/libik_geo.so")
endif()


# Copy ik_geo.h to the dist folder
add_custom_command(TARGET ik_geo_lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_LIST_DIR}/include/ik_geo.h"
"${CMAKE_BINARY_DIR}/ik_geo.h")

58 changes: 47 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
# IK Geo C++

This is a wrapper for the Rust implementation for C++
This is a wrapper for the Rust implementation for C++. The outpiut of this build is 2 files:

1. ik_geo.h
2. libik_geo.so/libik_geo.lib

## To build

In this directory, run `cmake . && make`. This will create a dist folder with three files:
- `ik_geo.h`, a header file to include in a c++ project
- `libik_cpp.a` (or `libik_cpp.lib` in Windows), a static library that must be included to use ik_geo in c++.
- `libik_geo.a` (or `libik_geo.lib` in Windows), another static library that must be included as well.
```bash
mkdir build
cd build
cmake .. && make
```

## Including as a dependency

You can get a CMake object to link against by including this source as a sub_directory.

```cmake
# Include the ik_geo cmake as a subdirectory
add_subdirectory(.. IK_GEO)
add_executable(test src/main.cpp)
# Link against the ik_geo object produced by the ik_geo cmake
target_link_libraries(test PRIVATE ik_geo)
```

## To use

Include the three files from the build step in the project, and look at `ik_geo.h` for function signatures.
Include the header

```c++
#include "ik_geo.h"
```

Then you can create robots based off of kinematic specifications or select from hard coded ones

```c++
int main() {
Robot robot = Robot::ur5();
double rotation_matrix[9] = {
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0
};

double position_vector[3] = {0.0, 0.0, 0.0};

There is an example usage of this in `../examples/cpp`
std::vector<ik_geo::Solution> solutions;
robot.ik(rotation_matrix, position_vector, solutions);
}
```

## To do

- Test Windows implementation
- Create a GitHub workflow for generating the dist files
- Create a moveit package
- Add a wrapper for forward kinematics and allow for calculating error.
- Test Windows implementation
- Create a moveit package
10 changes: 4 additions & 6 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ project(test)

set(CMAKE_CXX_STANDARD 17)

include(../CMakeLists.txt)
# Include the ik_geo cmake as a subdirectory
add_subdirectory(.. IK_GEO)

add_executable(test src/main.cpp)
target_include_directories(test PRIVATE ../include)

target_link_libraries(test PRIVATE ik_geo)
target_link_directories(test PRIVATE ${CMAKE_BINARY_DIR})

add_dependencies(test ik_geo_lib)
# Link against the ik_geo object produced by the ik_geo cmake
target_link_libraries(test PRIVATE ik_geo)
52 changes: 31 additions & 21 deletions example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
#include <iostream>
#include "ik_geo.h"
#include <array>
#include <iostream>
#include <vector>


using namespace ik_geo;

int main(int argc, char const *argv[])
{
Robot robot = Robot::ur5();
// Create identity matrix
double rotation_matrix[9] = {
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0
};
int main(int argc, char const *argv[]) {
Robot robot = Robot::ur5();
double rotation_matrix[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};

double position_vector[3] = {0.5, 0.5, 0.0};

double position_vector[3] = {0.0, 0.0, 0.0};
std::vector<ik_geo::Solution> solutions;
robot.ik(rotation_matrix, position_vector, solutions);

std::vector<ik_geo::Solution> solutions;
robot.ik(rotation_matrix, position_vector, solutions);
for (auto &solution : solutions) {

for (auto &solution : solutions) {
std::cout << "Solution: ";
for (size_t i = 0; i < 6; i++) {
std::cout << solution.q[i] << " ";
}
std::cout << "Is LS: " << solution.is_ls << std::endl;
std::cout << "Solution: ";
for (std::size_t i = 0; i < 6; i++) {
std::cout << solution.q[i] << " ";
}

std::array<double, 9> rotation_matrix;
std::array<double, 3> position_vector;
robot.fk(solution.q, rotation_matrix, position_vector);
std::cout << "Is LS: " << (solution.is_ls ? "True" : "False") << std::endl;
std::cout << "Rotation Matrix: " << std::endl;
for (std::size_t i = 0; i < 3; i++) {
for (std::size_t j = 0; j < 3; j++)
std::cout << rotation_matrix[i * 3 + j] << " ";
std::cout << std::endl;
}
std::cout << "Position Vector: " << std::endl;
for (std::size_t i = 0; i < 3; i++) {
std::cout << position_vector[i] << " ";
}
return 0;
std::cout << std::endl;
}
return 0;
}
Loading

0 comments on commit 612e3fa

Please sign in to comment.