Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ assignees: pzhu-flexiv

## Version info

- Sim Plugin: [e.g. v1.1]
- OS: [e.g. Ubuntu 20.04, x86_64]
- Sim Plugin: [e.g. v1.2]
- OS: [e.g. Ubuntu 22.04, x86_64]

## How urgent is this bug? Have you found any workarounds?

Expand Down
45 changes: 22 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ cmake_minimum_required(VERSION 3.16.3)
# ===================================================================
# PROJECT SETUP
# ===================================================================
project(flexiv_sim_plugin VERSION 1.1.0)
project(flexiv_sim_plugin VERSION 1.2.0)

# Configure build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "CMake build type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithDebInfo")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithDebInfo" "MinSizeRel")

# Set static library according to platform
message(STATUS "OS: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Processor: ${CMAKE_SYSTEM_PROCESSOR}")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
set(SIM_PLUGIN_STATIC_LIB "libflexiv_sim_plugin.x86_64-linux-gnu.a")
set(SIM_PLUGIN_LIB "libflexiv_sim_plugin.x86_64-linux-gnu.a")
else()
message(FATAL_ERROR "Linux with ${CMAKE_SYSTEM_PROCESSOR} processor is currently not supported.")
endif()
Expand All @@ -32,51 +32,50 @@ endif()
# Threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(Threads_FOUND)
message(STATUS "Found Threads: HAVE_PTHREAD = ${THREADS_HAVE_PTHREAD_ARG}")
endif()
message(STATUS "Found Threads")

# spdlog
find_package(spdlog REQUIRED)
if(spdlog_FOUND)
message(STATUS "Found spdlog: ${spdlog_DIR}")
endif()
message(STATUS "Found spdlog v${spdlog_VERSION}: ${spdlog_DIR}")

# Fast-DDS (Fast-RTPS)
find_package(fastrtps 2.6.7 REQUIRED)
if(fastrtps_FOUND)
message(STATUS "Found fastrtps: ${fastrtps_DIR}")
endif()
find_package(fastrtps REQUIRED)
message(STATUS "Found fastrtps v${fastrtps_VERSION}: ${fastrtps_DIR}")

# Fast-CDR
find_package(fastcdr REQUIRED)
message(STATUS "Found fastcdr v${fastcdr_VERSION}: ${fastcdr_DIR}")

# ===================================================================
# CREATE LIBRARY
# ===================================================================
# Create an INTERFACE library with no source file to compile
add_library(${PROJECT_NAME} INTERFACE)
# Create static library target with dummy source
add_library(${PROJECT_NAME} STATIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/dummy.cpp)

# Create an alias of the library using flexiv namespace,
# to imitate the install target which uses flexiv namespace.
# Create an alias of the target with flexiv namespace
add_library(flexiv::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} INTERFACE
# Set include directories
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(${PROJECT_NAME} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/lib/${SIM_PLUGIN_STATIC_LIB}
# Link to dependencies
target_link_libraries(${PROJECT_NAME} PUBLIC
Threads::Threads
spdlog::spdlog
fastrtps
fastcdr
)

# Use moderate compiler warning option
if(CMAKE_HOST_UNIX)
target_compile_options(${PROJECT_NAME} INTERFACE -Wall -Wextra)
target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Wextra)
else()
target_compile_options(${PROJECT_NAME} INTERFACE /W1)
target_compile_options(${PROJECT_NAME} PUBLIC /W1)
endif()

# Install the INTERFACE library
# Install the library
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FlexivInstallLibrary.cmake)
FlexivInstallLibrary()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ An example program that mocks an external simulator is provided and can be used
NOTE: the robot serial number provided to the program is the same one you noted down when creating the simulated robot in Flexiv Elements Studio.

2. Go back to Elements Studio, then restart the exited simulator by toggling ON the *Connect* button.
3. Wait for the connection to establish. If the connection is successful, you should see the visualized robot in Elements Studio moving every joint back and forth. A software error should occur in Elements Studio which is expected because the mock external simulator did not close the loop by applying the calculated joint torques command to the simulated robot in it. This won't happen to real external simulators.
3. Wait for the connection to establish. If the connection is successful, you should see the visualized robot in Elements Studio moving every joint back and forth. NOTE: a software error should occur in Elements Studio which is expected because the mock external simulator did not close the loop by applying the calculated joint torques command to the simulated robot in it. This won't happen to real external simulators.

## Quick Start - Python

Expand Down
12 changes: 10 additions & 2 deletions cmake/FlexivInstallLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,28 @@ macro(FlexivInstallLibrary)
COMPATIBILITY AnyNewerVersion
)

# copy the *-targets.cmake file to the CMAKE_INSTALL_PREFIX directory
# Copy the *-targets.cmake file to the CMAKE_INSTALL_PREFIX directory
install(EXPORT "${PROJECT_NAME}-targets"
FILE "${PROJECT_NAME}-targets.cmake"
NAMESPACE "flexiv::"
DESTINATION "lib/cmake/${PROJECT_NAME}"
)

# copy the *.-config file to the CMAKE_INSTALL_PREFIX directory. This will specify the dependencies.
# Copy the *.-config file to the CMAKE_INSTALL_PREFIX directory. This will specify the dependencies.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" "${PROJECT_NAME}-config.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "lib/cmake/${PROJECT_NAME}"
)

# Replace the dummy static lib with the actual static lib
install(CODE
"file(REMOVE ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lib/${SIM_PLUGIN_LIB}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RENAME ${CMAKE_STATIC_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
)

# Use the CPack Package Generator
set(CPACK_PACKAGE_VENDOR "Flexiv")
set(CPACK_PACKAGE_CONTACT "support@flexiv.com")
Expand Down
3 changes: 2 additions & 1 deletion cmake/flexiv_sim_plugin-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ include(CMakeFindDependencyMacro)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_dependency(Threads REQUIRED)
find_dependency(spdlog REQUIRED)
find_dependency(fastrtps 2.6.7 REQUIRED)
find_dependency(fastrtps REQUIRED)
find_dependency(fastcdr REQUIRED)

# Add targets file
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
2 changes: 1 addition & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Flexiv Sim Plugin APIs"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.1.0
PROJECT_NUMBER = 1.2.0

# 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
9 changes: 4 additions & 5 deletions example/mock_external_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ constexpr double kSineAmp = 0.035;
constexpr double kSineFreq = 0.3;

// Initial joint positions when the robot is at home posture [rad]
constexpr std::array<float, sim_plugin::kJointDoF> kInitQ
= {0.0, -0.698132, 0.0, 1.5708, 0.0, 0.698132, 0.0};
const std::vector<float> kInitQ = {0.0, -0.698132, 0.0, 1.5708, 0.0, 0.698132, 0.0};

// Servo cycle of the physics loop
unsigned int g_servo_cycle = 0;
Expand Down Expand Up @@ -60,13 +59,13 @@ void StepPhysics(sim_plugin::UserNode& user_node)
robot_states.servo_cycle = g_servo_cycle++;

// Set joint positions to sine waves
for (size_t i = 0; i < sim_plugin::kJointDoF; i++) {
for (size_t i = 0; i < kInitQ.size(); i++) {
robot_states.q[i]
= kInitQ[i] + kSineAmp * sin(2 * M_PI * kSineFreq * g_servo_cycle * kPhysicsPeriod);
}

// Set joint velocities to corresponding cosine waves
for (size_t i = 0; i < sim_plugin::kJointDoF; i++) {
for (size_t i = 0; i < kInitQ.size(); i++) {
robot_states.dq[i] = kSineAmp * 2 * M_PI * kSineFreq
* cos(2 * M_PI * kSineFreq * g_servo_cycle * kPhysicsPeriod);
}
Expand All @@ -87,7 +86,7 @@ void StepPhysics(sim_plugin::UserNode& user_node)

// Step 4: apply joint torques command to the simulated robot in the external simulator
// =============================================================================================
auto target_joint_torques = user_node.robot_commands().tau_d;
auto target_joint_torques = user_node.robot_commands().target_drives;
// Call the external simulator's API to apply the target joint torques

// End the current physics step with kPhysicsPeriod as the total loop period
Expand Down
2 changes: 1 addition & 1 deletion example_py/mock_external_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def step_physics(user_node, logger):

# Step 4: apply joint torques command to the simulated robot in the external simulator
# =============================================================================================
target_joint_torques = user_node.robot_commands().tau_d
target_joint_torques = user_node.robot_commands().target_drives
# Call the external simulator's API to apply the target joint torques

# End the current physics step with kPhysicsPeriod as roughly the total loop period
Expand Down
31 changes: 18 additions & 13 deletions include/flexiv/sim_plugin/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,61 @@
#define FLEXIV_SIM_PLUGIN_DATA_HPP_

#include <array>
#include <vector>
#include <string>

namespace flexiv {
namespace sim_plugin {

/** Joint-space degrees of freedom of the simulated robot */
constexpr size_t kJointDoF = 7;

/** Number of simulated digital IO ports */
constexpr size_t kIOPorts = 16;

/** States data of a simulated robot in the external simulator */
struct SimRobotStates
{
/** @brief Customized constructor */
SimRobotStates(uint64_t _servo_cycle, const std::array<float, kJointDoF>& _q,
const std::array<float, kJointDoF>& _dq)
SimRobotStates(
uint64_t _servo_cycle, const std::vector<float>& _q, const std::vector<float>& _dq)
: servo_cycle(_servo_cycle)
, q(_q)
, dq(_dq)
{
}

/** @brief Default constructor */
SimRobotStates() = default;

/** Servo cycle incremented once per physics step of the external simulator */
uint64_t servo_cycle = 0;

/** Current joint positions of the simulated robot [rad] */
std::array<float, kJointDoF> q = {};
/** Current joint positions of the simulated robot: \f$ q \in \mathbb{R}^{n \times 1} \f$. Unit:
* \f$ [rad] or [m] \f$.
* @note This contains values for both the external axes (if any) and the robot manipulator. */
std::vector<float> q = {};

/** Current joint velocities of the simulated robot [rad/s] */
std::array<float, kJointDoF> dq = {};
/** Current joint velocities of the simulated robot: \f$ \dot{q} \in \mathbb{R}^{n \times 1}
* \f$. Unit: \f$ [rad/s] or [m/s] \f$.
* @note This contains values for both the external axes (if any) and the robot manipulator. */
std::vector<float> dq = {};
};

/** Commands data for a simulated robot in the external simulator */
struct SimRobotCommands
{
/** @brief Customized constructor */
SimRobotCommands(const std::array<float, kJointDoF>& _tau_d,
SimRobotCommands(const std::vector<float>& _target_drives,
const std::array<bool, kIOPorts>& _digital_outputs)
: tau_d(_tau_d)
: target_drives(_target_drives)
, digital_outputs(_digital_outputs)
{
}
/** @brief Default constructor */
SimRobotCommands() = default;

/** Target joint torques for the simulated robot [Nm]. */
std::array<float, kJointDoF> tau_d = {};
/** Target joint drives for the simulated robot, can be torques or velocities depending on the
* drive type of the joint. Unit: \f$ [Nm] or [rad/s] or [m/s] \f$.
* @note This contains values for both the external axes (if any) and the robot manipulator. */
std::vector<float> target_drives = {};

/** Desired digital outputs for the simulated robot. The index of this boolean array corresponds
* to that of the digital output ports. True: port high, false: port low. */
Expand Down
5 changes: 5 additions & 0 deletions lib/dummy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @file dummy.cpp
* @brief A dummy source file to add portability to the installed flexiv_rdk library
*/
void dummy() { }
Binary file modified lib/libflexiv_sim_plugin.x86_64-linux-gnu.a
Binary file not shown.
24 changes: 16 additions & 8 deletions thirdparty/build_and_install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,31 @@ fi
INSTALL_DIR=$1
echo "Dependencies will be installed to: $INSTALL_DIR"

# Use specified number for parallel build jobs, otherwise use number of cores
# Use specified number for parallel build jobs, otherwise use 4
if [ -n "$2" ] ;then
NUM_JOBS=$2
export NUM_JOBS=$2
else
NUM_JOBS=4
export NUM_JOBS=4
fi
echo "Number of parallel build jobs: $NUM_JOBS"

# Set shared cmake arguments
SHARED_CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_PREFIX_PATH=$INSTALL_DIR \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DBUILD_TESTING=OFF"

# Clone all dependencies in a subfolder
mkdir -p cloned && cd cloned
export SHARED_CMAKE_ARGS

# Build and install all dependencies to INSTALL_DIR
bash $SCRIPTPATH/scripts/install_spdlog.sh $INSTALL_DIR $NUM_JOBS
bash $SCRIPTPATH/scripts/install_tinyxml2.sh $INSTALL_DIR $NUM_JOBS
bash $SCRIPTPATH/scripts/install_foonathan_memory.sh $INSTALL_DIR $NUM_JOBS
bash $SCRIPTPATH/scripts/install_Fast-CDR.sh $INSTALL_DIR $NUM_JOBS
bash $SCRIPTPATH/scripts/install_Fast-DDS.sh $INSTALL_DIR $NUM_JOBS
bash $SCRIPTPATH/scripts/install_spdlog.sh
bash $SCRIPTPATH/scripts/install_tinyxml2.sh
bash $SCRIPTPATH/scripts/install_foonathan_memory.sh
bash $SCRIPTPATH/scripts/install_Fast-CDR.sh
bash $SCRIPTPATH/scripts/install_Fast-DDS.sh

echo ">>>>>>>>>> Finished <<<<<<<<<<"
20 changes: 5 additions & 15 deletions thirdparty/scripts/install_Fast-CDR.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@
set -e
echo "Installing Fast-CDR"

# Get install directory and number of parallel build jobs as script arguments
INSTALL_DIR=$1
NUM_JOBS=$2
# Use a specific version
VER_TAG=v1.0.28

# Clone source code
if [ ! -d Fast-CDR ] ; then
git clone https://github.com/eProsima/Fast-CDR.git
git clone https://github.com/eProsima/Fast-CDR.git --branch $VER_TAG
cd Fast-CDR
else
cd Fast-CDR
git checkout $VER_TAG
fi

# Use specific version
git fetch -p
git checkout v1.0.24
git submodule update --init --recursive

# Configure CMake
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DCMAKE_PREFIX_PATH=$INSTALL_DIR \
-DCOMPILE_EXAMPLES=OFF
cmake .. $SHARED_CMAKE_ARGS -DCOMPILE_EXAMPLES=OFF

# Build and install
cmake --build . --target install --config Release -j $NUM_JOBS
Expand Down
Loading