Skip to content

Commit

Permalink
Flexiv RDK 0.5.1 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
pzhu-flexiv authored Apr 29, 2022
1 parent 10a57dc commit 0b9d3fe
Show file tree
Hide file tree
Showing 45 changed files with 1,019 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.vs
config.h
build/
html/
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ foreach(example ${EXAMPLE_LIST})
# Link arm64 or x64 version of libFlexivRdk
if (${BUILD_FOR_ARM64})
target_link_libraries(${example}
${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp/arm64/libFlexivRdk.a)
${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/cpp/arm64/libFlexivRdk.a)
else()
target_link_libraries(${example}
${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp/x64/libFlexivRdk.a)
${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/cpp/x64/libFlexivRdk.a)
endif()

endforeach()
Expand Down Expand Up @@ -108,10 +108,10 @@ foreach(test ${TEST_LIST})
# Link arm64 or x64 version of libFlexivRdk
if (${BUILD_FOR_ARM64})
target_link_libraries(${test}
${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp/arm64/libFlexivRdk.a)
${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/cpp/arm64/libFlexivRdk.a)
else()
target_link_libraries(${test}
${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp/x64/libFlexivRdk.a)
${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/cpp/x64/libFlexivRdk.a)
endif()

endforeach()
51 changes: 39 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
![CMake Badge](https://github.com/flexivrobotics/flexiv_rdk/actions/workflows/cmake.yml/badge.svg)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Flexiv RDK (Robot Development Kit) is a powerful toolkit as an add-on to the Flexiv software platform. It enables the users to create complex applications with APIs that provide low-level real-time access to the robot.

**C++** (access to all APIs) and **Python** (access to non-real-time APIs only) are supported.
Flexiv RDK (Robotic Development Kit), a key component of the Flexiv Robotic Software Platform, is a powerful development toolkit that enables the users to create complex and customized robotic applications using APIs that provide both low-level real-time (RT) and high-level non-real-time (NRT) access to Flexiv robots.

## License

Expand All @@ -15,45 +13,74 @@ Flexiv RDK is licensed under the [Apache 2.0 license](https://www.apache.org/lic

[Flexiv RDK main webpage](https://rdk.flexiv.com/) contains important information like the user manual and API documentation, please read them carefully before proceeding.

## OS and language support

Supported OS:

* Linux: Ubuntu 18.04 / 20.04
* Windows: 10 with MSVC 14.0+

Supported programming languages:

* C++ (Linux and Windows)
* Python (Linux only)

## Run example programs

**NOTE:** the instruction below is only a quick reference, assuming you've already gone through the Flexiv RDK Manual.
**NOTE:** the instruction below is only a quick reference, assuming you've already gone through [Flexiv RDK Manual](https://rdk.flexiv.com/manual/).

### C++ interface
### Linux C++ interface

1. Configure and compile example programs for x64 processors:
1. Configure CMake and compile all C++ example programs for the x64 processor platform:

cd flexiv_rdk
mkdir build && cd build
cmake ..
make -j4

For arm64 processors, set the additional CMake option when configuring:
If compiling for the arm64 processor platform, set the additional CMake option when configuring:

cmake .. -DBUILD_FOR_ARM64=ON

2. The compiled program binaries will be output to ``flexiv_rdk/build/example``
3. Assume the robot is booted and connected, to run an example program:
3. Assume the robot is booted and connected, to run an example program from a Linux Terminal:

cd flexiv_rdk/build/example
./<program_name> <robot_ip> <local_ip> <...>

If ``flexiv::Scheduler`` is used in this program, then ``sudo`` is required to grant root privileges to the integrated scheduler:

sudo ./<program_name> <robot_ip> <local_ip> <...>

### Python interface
### Linux Python interface

**NOTE:** Python 3.8 is required to use this interface, see Flexiv RDK Manual for more details.

1. Make sure your Python version is 3.8.x:

python3 --version

2. Assume the robot is booted and connected, to run an example program:
2. Assume the robot is booted and connected, to run an example program from a Linux Terminal:

cd flexiv_rdk/example_py
sudo python3 <program_name>.py <robot_ip> <local_ip> <...>
python3 <program_name>.py <robot_ip> <local_ip> <...>

Note that ``sudo`` is not required for Python interface.

### Windows C++ interface

1. Install any edition of Microsoft Visual Studio with version 2010 or above.
2. Use Visual Studio to open the example solution file at ``flexiv_rdk\example\windows\windows.sln``. Several example projects are pre-configured for x64 and x86 processor platforms, with each of them corresponding to an example under ``flexiv_rdk\example\``.
3. Check that the global solution configuration is set to **Release**. This setting can usually be found near the top menu bar.
4. Use *Build* -> *Build Solution* to compile all example projects. The compiled ``.exe`` executable binary files are output to ``flexiv_rdk\build\windows\``.
5. Assume the robot is booted and connected, to run an example program from a Windows Command Prompt:

cd flexiv_rdk_dev\build\windows\<platform>\Release\
<program_name>.exe <robot_ip> <local_ip> <...>

## Integrated visualization

Flexiv RDK has integrated visualization (only available for C++ interface) based on Meshcat. To use this feature:
Flexiv RDK has integrated visualization (only available for **Linux C++ interface**) based on Meshcat. To use this feature:

1. Install Meshcat server using ``pip``:

Expand Down
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 RDK APIs"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "0.5.0"
PROJECT_NUMBER = "0.5"

# 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: 8 additions & 1 deletion example/auto_recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ int main(int argc, char* argv[])

// Enable the robot, make sure the E-stop is released before enabling
log.info("Enabling robot ...");
robot.enable();
// TODO: remove this extra try catch block after the destructor bug in
// Windows library is fixed
try {
robot.enable();
} catch (const flexiv::Exception& e) {
log.error(e.what());
return 0;
}

// Application-specific Code
//=============================================================================
Expand Down
112 changes: 59 additions & 53 deletions example/display_robot_states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,39 @@
#include <flexiv/Robot.hpp>
#include <flexiv/Exception.hpp>
#include <flexiv/Log.hpp>
#include <flexiv/Scheduler.hpp>

#include <iostream>
#include <iomanip>
#include <thread>
#include <mutex>

namespace {
/** Mutex on shared data */
std::mutex g_mutex;
}

/** User-defined high-priority periodic task @ 1kHz */
void highPriorityTask(flexiv::Robot* robot, flexiv::RobotStates* robotStates,
flexiv::Scheduler* scheduler, flexiv::Log* log)
/** User-defined periodic task @ 1Hz */
void periodicTask(flexiv::Robot* robot, flexiv::Log* log)
{
unsigned int printCounter = 0;

// Data struct for storing robot states
flexiv::RobotStates robotStates;

try {
// Safely write shared data
std::lock_guard<std::mutex> lock(g_mutex);
// Get robot states
robot->getRobotStates(robotStates);
while (true) {
// Wake up every second to do something
std::this_thread::sleep_for(std::chrono::seconds(1));

} catch (const flexiv::Exception& e) {
log->error(e.what());
scheduler->stop();
}
}
// Get robot states
robot->getRobotStates(&robotStates);

/** User-defined low-priority periodic task @ 1Hz */
void lowPriorityTask(flexiv::RobotStates* robotStates)
{
static unsigned int printCounter = 0;
constexpr size_t k_nominalDof = 7;

// Safely read shared data
flexiv::RobotStates robotStatesCopy;
{
std::lock_guard<std::mutex> lock(g_mutex);
robotStatesCopy = *robotStates;
}
// Print all robot states in JSON format using the built-in ostream
// operator overloading
std::cout << "\n\n[" << ++printCounter << "]";
std::cout
<< "========================================================="
<< std::endl;

// Print only when the data is valid
if (robotStatesCopy.m_q.size() == k_nominalDof) {
// Print divider
std::cout << "\n\n[" << ++printCounter << "]";
std::cout << "========================================================="
<< std::endl;
std::cout << robotStates << std::endl;
}

// Print all robot states in JSON format using the built-in ostream
// operator overloading
std::cout << robotStatesCopy << std::endl;
} catch (const flexiv::Exception& e) {
log->error(e.what());
return;
}
}

Expand Down Expand Up @@ -86,21 +68,45 @@ int main(int argc, char* argv[])
// Instantiate robot interface
flexiv::Robot robot(robotIP, localIP);

// Create data struct for storing robot states
flexiv::RobotStates robotStates;
// Clear fault on robot server if any
if (robot.isFault()) {
log.warn("Fault occurred on robot server, trying to clear ...");
// Try to clear the fault
robot.clearFault();
std::this_thread::sleep_for(std::chrono::seconds(2));
// Check again
if (robot.isFault()) {
log.error("Fault cannot be cleared, exiting ...");
return 0;
}
log.info("Fault on robot server is cleared");
}

// Enable the robot, make sure the E-stop is released before enabling
log.info("Enabling robot ...");
// TODO: remove this extra try catch block after the destructor bug in
// Windows library is fixed
try {
robot.enable();
} catch (const flexiv::Exception& e) {
log.error(e.what());
return 0;
}

// Wait for the robot to become operational
while (!robot.isOperational()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
log.info("Robot is now operational");

// Periodic Tasks
//=============================================================================
flexiv::Scheduler scheduler;
// Add periodic task with 1ms interval and highest applicable priority
scheduler.addTask(
std::bind(highPriorityTask, &robot, &robotStates, &scheduler, &log),
"HP periodic", 1, 45);
// Add periodic task with 1s interval and lowest applicable priority
scheduler.addTask(
std::bind(lowPriorityTask, &robotStates), "LP periodic", 1000, 0);
// Start all added tasks, this is by default a blocking method
scheduler.start();
// Use std::thread to do scheduling since this example is used for both
// Linux and Windows, and the latter does not support flexiv::Scheduler
std::thread lowPriorityThread(std::bind(periodicTask, &robot, &log));

// Properly exit thread
lowPriorityThread.join();

} catch (const flexiv::Exception& e) {
log.error(e.what());
Expand Down
11 changes: 9 additions & 2 deletions example/gripper_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ int main(int argc, char* argv[])

// Enable the robot, make sure the E-stop is released before enabling
log.info("Enabling robot ...");
robot.enable();
// TODO: remove this extra try catch block after the destructor bug in
// Windows library is fixed
try {
robot.enable();
} catch (const flexiv::Exception& e) {
log.error(e.what());
return 0;
}

// Wait for the robot to become operational
while (!robot.isOperational()) {
Expand Down Expand Up @@ -99,7 +106,7 @@ int main(int argc, char* argv[])
log.info("Opening fingers");
gripper.move(0.08, 0.1);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
log.info("Stopping grippergripper");
log.info("Stopping gripper");
gripper.stop();

} catch (const flexiv::Exception& e) {
Expand Down
9 changes: 8 additions & 1 deletion example/plan_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ int main(int argc, char* argv[])

// Enable the robot, make sure the E-stop is released before enabling
log.info("Enabling robot ...");
robot.enable();
// TODO: remove this extra try catch block after the destructor bug in
// Windows library is fixed
try {
robot.enable();
} catch (const flexiv::Exception& e) {
log.error(e.what());
return 0;
}

// Wait for the robot to become operational
while (!robot.isOperational()) {
Expand Down
9 changes: 8 additions & 1 deletion example/primitive_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ int main(int argc, char* argv[])

// Enable the robot, make sure the E-stop is released before enabling
log.info("Enabling robot ...");
robot.enable();
// TODO: remove this extra try catch block after the destructor bug in
// Windows library is fixed
try {
robot.enable();
} catch (const flexiv::Exception& e) {
log.error(e.what());
return 0;
}

// Wait for the robot to become operational
while (!robot.isOperational()) {
Expand Down
Loading

0 comments on commit 0b9d3fe

Please sign in to comment.