Skip to content

Commit

Permalink
1.0.17版本 (#33)
Browse files Browse the repository at this point in the history
* fix: 完善文档,添加dotnet的文档。

* fix: 修正linux_python_build.yml重复编译的问题,以及没有指定PYTHONPATH的问题。

* feat: 添加python2的构建选项 修正旋转部分数据表示x和z反了的问题 完善文档
  • Loading branch information
liufang-robot authored Feb 13, 2023
1 parent eaa388d commit 36b2170
Show file tree
Hide file tree
Showing 16 changed files with 367 additions and 61 deletions.
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile command" TRUE)

project(lebai VERSION 1.0.16 LANGUAGES CXX)
project(lebai VERSION 1.0.17 LANGUAGES CXX)
set(PROJECT_NAMESPACE lebai)
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}")
# message(STATUS "major: ${PROJECT_VERSION_MAJOR}")
Expand Down Expand Up @@ -82,12 +82,19 @@ message(STATUS "Build C++ library: ${BUILD_CXX}")
option(BUILD_PYTHON "Build Python Library" OFF)
message(STATUS "Build Python: ${BUILD_PYTHON}")

option(BUILD_PYTHON2 "Build Python2 Library" OFF)
message(STATUS "Build Python2: ${BUILD_PYTHON2}")

option(BUILD_DOTNET "Build .NET Library" OFF)
message(STATUS "Build .Net: ${BUILD_DOTNET}")

option(BUILD_JAVA "Build Java Library" OFF)
message(STATUS "Build Java: ${BUILD_JAVA}")

if(BUILD_PYTHON AND BUILD_PYTHON2)
message(FATAL_ERROR "Can only build one of python2 and python3.")
endif()

if(BUILD_PYTHON)
option(FETCH_PYTHON_DEPS "Install python required modules if not available" ON)
message(STATUS "Python fetch dependencies: ${FETCH_PYTHON_DEPS}")
Expand All @@ -97,6 +104,13 @@ if(BUILD_PYTHON)
endif()
endif()

if(BUILD_PYTHON2)
if(DEFINED PYTHONPATH)
message(STATUS "Python path: ${PYTHON2PATH}")
set(Python2_ROOT_DIR ${PYTHONPATH})
endif()
endif()

# Disable CTest targets
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CTest)
Expand All @@ -115,6 +129,8 @@ if(BUILD_PYTHON)
endif()
include(python)

include(python2)


if(BUILD_DOTNET)
# .Net Core 3.1 LTS is not available for osx arm64
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "lebai sdk"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.0.16
PROJECT_NUMBER = 1.0.17

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ lebai-sdk的源代码仓库,可以用于控制乐白机械臂.

**上图中显示TODO的地方表示该平台该语言的实现还存在问题,没有完全测试通过,后续会陆续完成。**

**上图中显示TODO的地方表示该平台该语言的实现还存在问题,没有完全测试通过,后续会陆续完成。**

[cpp_linux_svg]: https://github.com/lebai-robotics/lebai-sdk/actions/workflows/linux_cpp_release.yml/badge.svg
[cpp_linux_link]: https://github.com/lebai-robotics/lebai-sdk/actions/workflows/linux_cpp_release.yml
[python_linux_svg]: https://github.com/lebai-robotics/lebai-sdk/actions/workflows/linux_python_release.yml/badge.svg
Expand Down Expand Up @@ -66,8 +68,10 @@ sudo apt install build-essential python3-pip dpkg-dev
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# 如果需要生成文档,还需要安装doxygen
sudo apt install doxygen graphviz
# 如果需要生成python的wrapper包
sudo apt install python3-dev
# 如果需要生成python3的wrapper包
sudo apt install python3-dev python3-setuptools
# 如果需要生成python2的wrapper包
sudo apt install python-dev python-setuptools
```


Expand Down Expand Up @@ -100,7 +104,8 @@ cpack

## 编译选项

- BUILD_PYTHON: 是否编译python接口 默认为OFF
- BUILD_PYTHON: 是否编译python3接口 默认为OFF
- BUILD_PYTHON2: 是否编译python2接口 默认为OFF
- PYTHONPATH: PYTHON的安装目录
- BUILD_DOTNET: 是否编译.NET接口 默认为OFF(请先安装好.NET的开发环境)
- BUILD_JAVA: 是否编译JAVA接口 默认为OFF(请先安装好JDK和Maven)
Expand Down
2 changes: 1 addition & 1 deletion cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif()
# Find Python 3

find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
list(APPEND CMAKE_SWIG_FLAGS "-threads" "-py3" "-DPY3")
list(APPEND CMAKE_SWIG_FLAGS "-threads" "-DPY3")

# Find if the python module is available,
# otherwise install it (PACKAGE_NAME) to the Python3 user install directory.
Expand Down
246 changes: 246 additions & 0 deletions cmake/python2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
if(NOT BUILD_PYTHON2)
return()
endif()

cmake_minimum_required(VERSION 3.18)

# Will need swig
set(CMAKE_SWIG_FLAGS)
find_package(SWIG REQUIRED)
include(UseSWIG)

if(${SWIG_VERSION} VERSION_GREATER_EQUAL 4)
list(APPEND CMAKE_SWIG_FLAGS "-doxygen")
endif()

if(UNIX AND NOT APPLE)
list(APPEND CMAKE_SWIG_FLAGS "-DSWIGWORDSIZE64")
endif()

# Find Python 2
find_package(Python2 COMPONENTS Interpreter Development REQUIRED)
list(APPEND CMAKE_SWIG_FLAGS "-threads")

# Find if the python module is available,
# otherwise install it (PACKAGE_NAME) to the Python3 user install directory.
# If CMake option FETCH_PYTHON_DEPS is OFF then issue a fatal error instead.
# e.g
# search_python_module(
# NAME
# mypy_protobuf
# PACKAGE
# mypy-protobuf
# NO_VERSION
# )
function(search_python_module)
set(options NO_VERSION)
set(oneValueArgs NAME PACKAGE)
set(multiValueArgs "")
cmake_parse_arguments(MODULE
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
message(STATUS "Searching python module: \"${MODULE_NAME}\"")
if(${MODULE_NO_VERSION})
execute_process(
COMMAND ${Python2_EXECUTABLE} -c "import ${MODULE_NAME}"
RESULT_VARIABLE _RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(MODULE_VERSION "unknown")
else()
execute_process(
COMMAND ${Python2_EXECUTABLE} -c "import ${MODULE_NAME}; print(${MODULE_NAME}.__version__)"
RESULT_VARIABLE _RESULT
OUTPUT_VARIABLE MODULE_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(${_RESULT} STREQUAL "0")
message(STATUS "Found python module: \"${MODULE_NAME}\" (found version \"${MODULE_VERSION}\")")
else()
if(FETCH_PYTHON_DEPS)
message(WARNING "Can't find python module: \"${MODULE_NAME}\", install it using pip...")
execute_process(
COMMAND ${Python2_EXECUTABLE} -m pip install --user ${MODULE_PACKAGE}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
message(FATAL_ERROR "Can't find python module: \"${MODULE_NAME}\", please install it using your system package manager.")
endif()
endif()
endfunction()

function(search_python_internal_module)
set(options "")
set(oneValueArgs NAME)
set(multiValueArgs "")
cmake_parse_arguments(MODULE
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
message(STATUS "Searching python module: \"${MODULE_NAME}\"")
execute_process(
COMMAND ${Python2_EXECUTABLE} -c "import ${MODULE_NAME}"
RESULT_VARIABLE _RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${_RESULT} STREQUAL "0")
message(STATUS "Found python internal module: \"${MODULE_NAME}\"")
else()
message(FATAL_ERROR "Can't find python internal module \"${MODULE_NAME}\", please install it using your system package manager.")
endif()
endfunction()

set(PYTHON_PROJECT lebai)
set(PYTHON_PROJECT_DIR ${PROJECT_BINARY_DIR}/python/${PYTHON_PROJECT})
message(STATUS "Python project build path: ${PYTHON_PROJECT_DIR}")

# Swig wrap sdk
foreach(SUBPROJECT IN ITEMS sdk)
add_subdirectory(${SUBPROJECT}/python)
endforeach()

#######################
## Python Packaging ##
#######################
#file(MAKE_DIRECTORY python/${PYTHON_PROJECT})
file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/__init__.py CONTENT "__version__ = \"${PROJECT_VERSION}\"\n")
# file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/__init__.py CONTENT "")

configure_file(
${PROJECT_SOURCE_DIR}/python/setup.py.in
${PROJECT_BINARY_DIR}/python/setup.py.in
@ONLY)
file(GENERATE
OUTPUT ${PROJECT_BINARY_DIR}/python/setup.py
INPUT ${PROJECT_BINARY_DIR}/python/setup.py.in)

#add_custom_command(
# OUTPUT python/setup.py
# DEPENDS ${PROJECT_BINARY_DIR}/python/setup.py
# COMMAND ${CMAKE_COMMAND} -E copy setup.py setup.py
# WORKING_DIRECTORY python)

# Look for python module wheel
search_python_module(
NAME setuptools
PACKAGE setuptools)
search_python_module(
NAME wheel
PACKAGE wheel)

add_custom_command(
OUTPUT python/dist/timestamp
COMMAND ${CMAKE_COMMAND} -E remove_directory dist
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_PROJECT}/.libs
# Don't need to copy static lib on Windows.
COMMAND ${CMAKE_COMMAND} -E $<IF:$<STREQUAL:$<TARGET_PROPERTY:lebai-cpp,TYPE>,SHARED_LIBRARY>,copy,true>
$<$<STREQUAL:$<TARGET_PROPERTY:lebai-cpp,TYPE>,SHARED_LIBRARY>:$<TARGET_SONAME_FILE:lebai-cpp>>
${PYTHON_PROJECT}/.libs
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:lebai-cpp> ${PYTHON_PROJECT}/
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:posture> ${PYTHON_PROJECT}/
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:motion> ${PYTHON_PROJECT}/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:l_master> ${PYTHON_PROJECT}/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:zeroconf> ${PYTHON_PROJECT}/
# COMMAND ${Python3_EXECUTABLE} setup.py bdist_egg bdist_wheel
COMMAND ${Python2_EXECUTABLE} setup.py bdist_wheel
COMMAND ${CMAKE_COMMAND} -E touch ${PROJECT_BINARY_DIR}/python/dist/timestamp
MAIN_DEPENDENCY
python/setup.py.in
DEPENDS
python/setup.py
${PROJECT_NAMESPACE}::lebai-cpp
# ${PROJECT_NAMESPACE}::posture
# ${PROJECT_NAMESPACE}::motion
${PROJECT_NAMESPACE}::l_master
${PROJECT_NAMESPACE}::zeroconf
BYPRODUCTS
python/${PYTHON_PROJECT}
python/${PYTHON_PROJECT}.egg-info
python/build
python/dist
WORKING_DIRECTORY python
COMMAND_EXPAND_LISTS)

# Main Target
add_custom_target(python_package ALL
DEPENDS
python/dist/timestamp
WORKING_DIRECTORY python)

###################
## Python Test ##
###################
# if(BUILD_TESTING)
# search_python_module(NAME virtualenv PACKAGE virtualenv)
# # venv not working on github windows runners
# # search_python_internal_module(NAME venv)
# # Testing using a vitual environment
# set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m virtualenv)
# #set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m venv)
# set(VENV_DIR ${CMAKE_CURRENT_BINARY_DIR}/python/venv)
# if(WIN32)
# set(VENV_Python3_EXECUTABLE ${VENV_DIR}/Scripts/python.exe)
# else()
# set(VENV_Python3_EXECUTABLE ${VENV_DIR}/bin/python)
# endif()
# # make a virtualenv to install our python package in it
# add_custom_command(TARGET python_package POST_BUILD
# # Clean previous install otherwise pip install may do nothing
# COMMAND ${CMAKE_COMMAND} -E remove_directory ${VENV_DIR}
# COMMAND ${VENV_EXECUTABLE} -p ${Python3_EXECUTABLE} ${VENV_DIR}
# #COMMAND ${VENV_EXECUTABLE} ${VENV_DIR}
# # Must NOT call it in a folder containing the setup.py otherwise pip call it
# # (i.e. "python setup.py bdist") while we want to consume the wheel package
# COMMAND ${VENV_Python3_EXECUTABLE} -m pip install --find-links=${CMAKE_CURRENT_BINARY_DIR}/python/dist ${PYTHON_PROJECT}
# BYPRODUCTS ${VENV_DIR}
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Create venv and install ${PYTHON_PROJECT}"
# VERBATIM)
# endif()

# add_python_test()
# CMake function to generate and build python test.
# Parameters:
# the python filename
# e.g.:
# add_python_test(foo.py)
# function(add_python_test FILE_NAME)
# message(STATUS "Configuring test ${FILE_NAME} ...")
# get_filename_component(EXAMPLE_NAME ${FILE_NAME} NAME_WE)

# if(BUILD_TESTING)
# add_test(
# NAME python_test_${EXAMPLE_NAME}
# COMMAND ${VENV_Python3_EXECUTABLE} ${FILE_NAME}
# WORKING_DIRECTORY ${VENV_DIR})
# endif()
# message(STATUS "Configuring test ${FILE_NAME} done")
# endfunction()

# add_python_example()
# CMake function to generate and build python example.
# Parameters:
# the python filename
# e.g.:
# add_python_example(foo.py)
# function(add_python_example FILE_NAME)
# message(STATUS "Configuring example ${FILE_NAME} ...")
# get_filename_component(EXAMPLE_NAME ${FILE_NAME} NAME_WE)

# if(BUILD_TESTING)
# add_test(
# NAME python_example_${EXAMPLE_NAME}
# COMMAND ${VENV_Python3_EXECUTABLE} ${FILE_NAME}
# WORKING_DIRECTORY ${VENV_DIR})
# endif()
# message(STATUS "Configuring example ${FILE_NAME} done")
# endfunction()
6 changes: 6 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## 1.0.17

添加python2的构建选项
修正旋转部分数据表示x和z反了的问题
完善文档

## 1.0.14

文档更新,持续集成更新,修正程序的错误
Expand Down
4 changes: 4 additions & 0 deletions doc/dotnet.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# .net平台应用文档

<<<<<<< HEAD
**目前.net仅支持linux平台,windows平台还存在问题.**
=======
>>>>>>> eaa388d5ed4303d406026c6b7d2b632bd30a6374
[Nuget包地址](https://www.nuget.org/packages/lebai/)

Expand Down
3 changes: 1 addition & 2 deletions examples/example.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using lebai.l_master;

namespace lebai.app
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"Enter example");
Robot robot = new Robot("192.168.1.100", true);
Robot robot = new Robot("127.0.0.1", true);
robot.stop_sys();
Console.WriteLine($"stop...");
robot.start_sys();
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InstallPlatlib(install):
install.finalize_options(self)
self.install_lib=self.install_platlib

with open(r"../../README.md", "r", encoding='UTF-8') as fh:
with open(r"../../README.md", "r") as fh:
long_description = fh.read()

setup(
Expand Down
Loading

0 comments on commit 36b2170

Please sign in to comment.